我有客户端服务器代码client.cpp和server.cpp都带有main()。服务器需要首先执行并保持活动状态,直到不被中断。
server.cpp 包含我创建的两个 cpp 文件:
#include "serverFunction.cpp"
#include "serverFunction2.cpp"
这两者还包括serverFunction.h
.
如何为此编写makefile?我最后使用了 pthread 所以 -lpthread 。我以这种方式单独编译:
g++ -o a LinServer.cpp -lpthread
我试过这个:
all: LinServer LinClient
LinServer:
g++ -o a LinServer.cpp -pthread
LinClient:
g++ -o b LinClient.cpp -pthread
但它给出了这个错误:
LinServer.o: In function `main':
LinServer.cpp:(.text+0x6dd): undefined reference to `pthread_create'
LinServer.cpp:(.text+0x6e9): undefined reference to `pthread_detach'
LinServer.o: In function `__static_initialization_and_destruction_0(int, int)':
LinServer.cpp:(.text+0xb3e): undefined reference to `std::ios_base::Init::Init()'
LinServer.cpp:(.text+0xb55): undefined reference to `std::ios_base::Init::~Init()'
LinServer.o:(.eh_frame+0x7b): undefined reference to `__gxx_personality_v0'
collect2: error: ld returned 1 exit status
make: *** [LinServer] Error 1