landonmkelsey
17th August 2008, 01:30
I moved some stuff around in my TCP/IP program and now I get a duplicate defined
message for static variables.
The strange thing is that the compiler is calling the use of a static variable a definition. :confused:
#ifndef TCPIP_SERVER_H_
#define TCPIP_SERVER_H_
#include "ui_tcpip.h"
#include "inet.h"
#include <iostream>
#include <sstream>
#include <exception>
using namespace std;
#include "thread.cpp"
#include "sock_io.cpp"
#include "tstash.h"
#include <QtDebug>
typedef void* (*p_VOID_FUNCT)(void*);
class tcpip_server {
socklen_t clilen;
struct sockaddr_in cli_addr, serv_addr;
ushort port;
// struct sock_addr_in accept_ip_struct;
int accept_ip_address;
int client_ip_address;
Ui::tcpipClass ui;
public:
tcpip_server(int accept_ip_addr,
ushort port_port,
p_VOID_FUNCT p_void_funct, Ui::tcpipClass uip);
//:
// accept_ip_address(accept_ip_addr),
// port(port_port),
// ui(uip);
// destructor
~tcpip_server()
{
close(socketfd); /* close original socket */
}
static int socketfd, newsocketfd;
static QList<QString> qlist;
static bool running;
static QStringList qstrList;
static void localClose()
{
qDebug()<<"close detected";
running = false;
close(socketfd); // obviously this is NOT a definition
close(newsocketfd);
exit(0);
}
static void* str_echo(void* p_void);
// struct sock_addr_in client_ip_struct;
};
bool tcpip_server::running = true;
int tcpip_server::socketfd = 0;
int tcpip_server::newsocketfd = 0;
QStringList tcpip_server::qstrList = QStringList();
QList<QString> tcpip_server::qlist = QList<QString>();
#endif /*TCPIP_SERVER_H_*/
link errors for each static variable!
make release
make -f Makefile.Release
make[1]: Entering directory `/home/landon4/workspace/tcpip'
g++ -c -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -Irelease -I. -o release/tcpip_client.o tcpip_client.cpp
g++ -c -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -Irelease -I. -o release/tcpip_server.o tcpip_server.cpp
tcpip_client.h: In constructor ‘tcpip_client::tcpip_client(int, ushort, bool, Ui::tcpipClass)’:
tcpip_client.h:14: warning: ‘tcpip_client::accept_ip_address’ will be initialized after
tcpip_client.h:12: warning: ‘ushort tcpip_client::port’
tcpip_client.cpp:17: warning: when initialized here
tcpip_client.cpp: At global scope:
tcpip_client.cpp:17: warning: unused parameter ‘ui’
tcpip_client.cpp: In member function ‘int tcpip_client::tcp_write(char*, int)’:
tcpip_client.cpp:64: warning: ignoring return value of ‘ssize_t write(int, const void*, size_t)’, declared with attribute warn_unused_result
g++ -c -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -Irelease -I. -o release/main.o main.cpp
In file included from tcpip_server.h:11,
from tcpip_server.cpp:2:
sock_io.cpp: In member function ‘int sock_io::tcp_write(char*, int)’:
sock_io.cpp:18: warning: ignoring return value of ‘ssize_t write(int, const void*, size_t)’, declared with attribute warn_unused_result
tcpip_server.h: In constructor ‘tcpip_server::tcpip_server(int, ushort, void* (*)(void*), Ui::tcpipClass)’:
tcpip_server.h:21: warning: ‘tcpip_server::accept_ip_address’ will be initialized after
tcpip_server.h:19: warning: ‘ushort tcpip_server::port’
tcpip_server.cpp:4: warning: when initialized here
tcpip_server.cpp:43: warning: suggest parentheses around assignment used as truth value
g++ -c -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -Irelease -I. -o release/tcpip.o tcpip.cpp
/usr/lib/qt4/bin/moc -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -Irelease -I. tcpip.h -o release/moc_tcpip.cpp
In file included from tcpip_server.h:11,
from tcpip.cpp:8:
sock_io.cpp: In member function ‘int sock_io::tcp_write(char*, int)’:
sock_io.cpp:18: warning: ignoring return value of ‘ssize_t write(int, const void*, size_t)’, declared with attribute warn_unused_result
g++ -c -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -Irelease -I. -o release/moc_tcpip.o release/moc_tcpip.cpp
g++ -o tcpip release/tcpip_client.o release/tcpip_server.o release/main.o release/tcpip.o release/moc_tcpip.o -lQtGui -lQtCore -lpthread
make[1]: Leaving directory `/home/landon4/workspace/tcpip'
release/tcpip.o:/usr/include/QtCore/qlist.h:527: multiple definition of `tcpip_server::qstrList'
release/tcpip_server.o:/usr/include/QtCore/qatomic_i386.h:90: first defined here
release/tcpip.o:/usr/include/QtCore/qlist.h:559: multiple definition of `tcpip_server::qlist'
release/tcpip_server.o:/usr/lib/gcc/i386-redhat-linux/4.3.0/../../../../include/c++/4.3.0/iostream:77: first defined here
release/tcpip.o:/home/landon4/workspace/tcpip/tcpip.cpp:175: multiple definition of `tcpip_server::socketfd'
release/tcpip_server.o:/home/landon4/workspace/tcpip/tcpip_server.cpp:90: first defined here
release/tcpip.o:(.data+0x0): multiple definition of `tcpip_server::running'
release/tcpip_server.o:(.data+0x0): first defined here
release/tcpip.o:/home/landon4/workspace/tcpip/tcpip.cpp:175: multiple definition of `tcpip_server::newsocketfd'
release/tcpip_server.o:/usr/include/QtCore/qatomic_i386.h:90: first defined here
collect2: ld returned 1 exit status
make[1]: *** [tcpip] Error 1
make: *** [release] Error 2
message for static variables.
The strange thing is that the compiler is calling the use of a static variable a definition. :confused:
#ifndef TCPIP_SERVER_H_
#define TCPIP_SERVER_H_
#include "ui_tcpip.h"
#include "inet.h"
#include <iostream>
#include <sstream>
#include <exception>
using namespace std;
#include "thread.cpp"
#include "sock_io.cpp"
#include "tstash.h"
#include <QtDebug>
typedef void* (*p_VOID_FUNCT)(void*);
class tcpip_server {
socklen_t clilen;
struct sockaddr_in cli_addr, serv_addr;
ushort port;
// struct sock_addr_in accept_ip_struct;
int accept_ip_address;
int client_ip_address;
Ui::tcpipClass ui;
public:
tcpip_server(int accept_ip_addr,
ushort port_port,
p_VOID_FUNCT p_void_funct, Ui::tcpipClass uip);
//:
// accept_ip_address(accept_ip_addr),
// port(port_port),
// ui(uip);
// destructor
~tcpip_server()
{
close(socketfd); /* close original socket */
}
static int socketfd, newsocketfd;
static QList<QString> qlist;
static bool running;
static QStringList qstrList;
static void localClose()
{
qDebug()<<"close detected";
running = false;
close(socketfd); // obviously this is NOT a definition
close(newsocketfd);
exit(0);
}
static void* str_echo(void* p_void);
// struct sock_addr_in client_ip_struct;
};
bool tcpip_server::running = true;
int tcpip_server::socketfd = 0;
int tcpip_server::newsocketfd = 0;
QStringList tcpip_server::qstrList = QStringList();
QList<QString> tcpip_server::qlist = QList<QString>();
#endif /*TCPIP_SERVER_H_*/
link errors for each static variable!
make release
make -f Makefile.Release
make[1]: Entering directory `/home/landon4/workspace/tcpip'
g++ -c -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -Irelease -I. -o release/tcpip_client.o tcpip_client.cpp
g++ -c -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -Irelease -I. -o release/tcpip_server.o tcpip_server.cpp
tcpip_client.h: In constructor ‘tcpip_client::tcpip_client(int, ushort, bool, Ui::tcpipClass)’:
tcpip_client.h:14: warning: ‘tcpip_client::accept_ip_address’ will be initialized after
tcpip_client.h:12: warning: ‘ushort tcpip_client::port’
tcpip_client.cpp:17: warning: when initialized here
tcpip_client.cpp: At global scope:
tcpip_client.cpp:17: warning: unused parameter ‘ui’
tcpip_client.cpp: In member function ‘int tcpip_client::tcp_write(char*, int)’:
tcpip_client.cpp:64: warning: ignoring return value of ‘ssize_t write(int, const void*, size_t)’, declared with attribute warn_unused_result
g++ -c -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -Irelease -I. -o release/main.o main.cpp
In file included from tcpip_server.h:11,
from tcpip_server.cpp:2:
sock_io.cpp: In member function ‘int sock_io::tcp_write(char*, int)’:
sock_io.cpp:18: warning: ignoring return value of ‘ssize_t write(int, const void*, size_t)’, declared with attribute warn_unused_result
tcpip_server.h: In constructor ‘tcpip_server::tcpip_server(int, ushort, void* (*)(void*), Ui::tcpipClass)’:
tcpip_server.h:21: warning: ‘tcpip_server::accept_ip_address’ will be initialized after
tcpip_server.h:19: warning: ‘ushort tcpip_server::port’
tcpip_server.cpp:4: warning: when initialized here
tcpip_server.cpp:43: warning: suggest parentheses around assignment used as truth value
g++ -c -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -Irelease -I. -o release/tcpip.o tcpip.cpp
/usr/lib/qt4/bin/moc -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -Irelease -I. tcpip.h -o release/moc_tcpip.cpp
In file included from tcpip_server.h:11,
from tcpip.cpp:8:
sock_io.cpp: In member function ‘int sock_io::tcp_write(char*, int)’:
sock_io.cpp:18: warning: ignoring return value of ‘ssize_t write(int, const void*, size_t)’, declared with attribute warn_unused_result
g++ -c -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -Irelease -I. -o release/moc_tcpip.o release/moc_tcpip.cpp
g++ -o tcpip release/tcpip_client.o release/tcpip_server.o release/main.o release/tcpip.o release/moc_tcpip.o -lQtGui -lQtCore -lpthread
make[1]: Leaving directory `/home/landon4/workspace/tcpip'
release/tcpip.o:/usr/include/QtCore/qlist.h:527: multiple definition of `tcpip_server::qstrList'
release/tcpip_server.o:/usr/include/QtCore/qatomic_i386.h:90: first defined here
release/tcpip.o:/usr/include/QtCore/qlist.h:559: multiple definition of `tcpip_server::qlist'
release/tcpip_server.o:/usr/lib/gcc/i386-redhat-linux/4.3.0/../../../../include/c++/4.3.0/iostream:77: first defined here
release/tcpip.o:/home/landon4/workspace/tcpip/tcpip.cpp:175: multiple definition of `tcpip_server::socketfd'
release/tcpip_server.o:/home/landon4/workspace/tcpip/tcpip_server.cpp:90: first defined here
release/tcpip.o:(.data+0x0): multiple definition of `tcpip_server::running'
release/tcpip_server.o:(.data+0x0): first defined here
release/tcpip.o:/home/landon4/workspace/tcpip/tcpip.cpp:175: multiple definition of `tcpip_server::newsocketfd'
release/tcpip_server.o:/usr/include/QtCore/qatomic_i386.h:90: first defined here
collect2: ld returned 1 exit status
make[1]: *** [tcpip] Error 1
make: *** [release] Error 2