我在项目目录的tests
文件夹中创建了三个C ++简单测试。当我创建第一个C ++简单测试并构建它没有问题但是当我创建第二个或第三个时,生成下面列出的无数错误
build/DebugDynamic/GNU-Linux-x86/ClientSocket.o: In function `Socket::is_valid() const':
/home/gowtham/workspace/base/ClientSocket.cpp:8: multiple definition of `ClientSocket::ClientSocket(std::string, int, Socket::SOCKET_TYPE, std::string, std::string, std::string)'
build/DebugDynamic/GNU-Linux-x86/ClientSocket_nomain.o:/home/gowtham/workspace/base/ClientSocket.cpp:8: first defined here
链接器命令是
g++ -g -O0 -o build/DebugDynamic/GNU-Linux-x86/tests/TestFiles/f3 build/DebugDynamic/GNU-Linux-x86/tests/tests/sizeInfo.o build/DebugDynamic/GNU-Linux-x86/ClientSocket_nomain.o build/DebugDynamic/GNU-Linux-x86/FFJSON_nomain.o build/DebugDynamic/GNU-Linux-x86/JPEGImage_nomain.o build/DebugDynamic/GNU-Linux-x86/ServerSocket_nomain.o build/DebugDynamic/GNU-Linux-x86/Socket_nomain.o build/DebugDynamic/GNU-Linux-x86/logger_nomain.o build/DebugDynamic/GNU-Linux-x86/myconverters_nomain.o build/DebugDynamic/GNU-Linux-x86/mycurl_nomain.o build/DebugDynamic/GNU-Linux-x86/mystdlib_nomain.o build/DebugDynamic/GNU-Linux-x86/myxml_nomain.o build/DebugDynamic/GNU-Linux-x86/ClientSocket.o build/DebugDynamic/GNU-Linux-x86/FFJSON.o build/DebugDynamic/GNU-Linux-x86/JPEGImage.o build/DebugDynamic/GNU-Linux-x86/ServerSocket.o build/DebugDynamic/GNU-Linux-x86/Socket.o build/DebugDynamic/GNU-Linux-x86/logger.o build/DebugDynamic/GNU-Linux-x86/myconverters.o build/DebugDynamic/GNU-Linux-x86/mycurl.o build/DebugDynamic/GNU-Linux-x86/mystdlib.o build/DebugDynamic/GNU-Linux-x86/myxml.o -lxml2 -lpthread -lssl -lcrypto -lz
netbeans为项目中的每个目标文件都包含一个重复的目标文件_nomain.o
。
ClientSocket.h
#ifndef CLIENTSOCKET_H
#define CLIENTSOCKET_H
#include "Socket.h"
class ClientSocket : public Socket {
public:
class AftermathObj {
public:
void* (*aftermath)(void* aftermathDS, bool isSuccess);
void* aftermathDS;
std::string payload;
std::string* payloadPTR;
std::string error;
int __flags;
pthread_t t;
ClientSocket* cs;
AftermathObj() {
};
~AftermathObj() {
};
};
ClientSocket();
ClientSocket(std::string host, int port, Socket::SOCKET_TYPE socketType = Socket::DEFAULT, std::string trustedCA = "", std::string privatecert = "", std::string privatekey = "");
std::string host;
int port;
void reconnect();
void disconnect();
bool send(const std::string s, int __flags) const;
bool send(const std::string* s, int __flags) const;
bool send(const std::string s) const;
virtual ~ClientSocket();
const ClientSocket& operator <<(const std::string&) const;
void asyncsend(std::string payload, AftermathObj* after_math_obj);
void asyncsend(std::string* payload, AftermathObj* aftermath_obj);
const ClientSocket& operator >>(std::string&) const;
private:
//Socket* soc;
static void* socsend(void*);
struct soc_send_t_args {
std::string s;
void* (&aftermath)(void* aftermathDS);
void* aftermathDS;
};
pthread_key_t socket_thread_key;
};
#endif