-
Simple makefile problem
Hello,
As I'm writing some simple email server app, I decided it's probably good idea to create my very first makefile.. Guess it didn't go that well... :confused:
Code:
OBJ = main.o EmailServer.o BasicServer.o Tokenizer.o Socket.o
BIN = EmailServer
FLG = -Wall -pthread -c
$(BIN): $(OBJ)
g++ $(OBJ) -o $(BIN)
main.o: main.cpp
g++ $(FLG) main.cpp -o main.o
EmailServer.o: EmailServer.cpp EmailServer.h
g++ $(FLG) EmailServer.cpp -o EmailServer.o
BasicServer.o: BasicServer.cpp BasicServer.h
g++ $(FLG) BasicServer.cpp -o BasicServer.o
Tokenizer.o: Tokenizer.cpp Tokenizer.h
g++ $(FLG) Tokenizer.cpp -o Tokenizer.o
Socket.o: Socket.cpp Socket.h
g++ $(FLG) Socket.cpp -o Socket.o
clean:
rm -f *.obj core
And well, when I try to make it, I get the following output:
Code:
g++ -Wall -pthread -c main.cpp -o main.o
g++ -Wall -pthread -c EmailServer.cpp -o EmailServer.o
g++ -Wall -pthread -c BasicServer.cpp -o BasicServer.o
g++ -Wall -pthread -c Tokenizer.cpp -o Tokenizer.o
g++ -Wall -pthread -c Socket.cpp -o Socket.o
g++ main.o EmailServer.o BasicServer.o Tokenizer.o Socket.o -o EmailServer
BasicServer.o: In function `BasicServer::startNewThread(unsigned long&, void* (*)(void*), void*)':
BasicServer.cpp:(.text+0x89): undefined reference to `pthread_create'
collect2: ld returned 1 exit status
make: *** [EmailServer] Error 1
Even though problem might seem quite simple, I didn't manage to find solution for it...
I also tried -lpthread instead of -pthread, no results. If anybody knows how to fix/improve (or maybe I should completely rebuild my makefile, as if it could be wrong to the root :p), I'll gladly hear your suggestions.
I'm using gcc 4.1.2 and make 3.81 with SUSE Linux.
Oh, and some include info (in case it might help);
BasicServer.h includes <pthread.h>
BasicServer.h includes Socket,
EmailServer.h includes BasicServer
EmailServer.cpp includes Tokenizer
main.cpp includes EmailServer
Cheers,
~
-
Add this:
And change this:
Code:
$(BIN): $(OBJ)
g++ $(OBJ) -o $(BIN)
To this:
Code:
$(BIN): $(OBJ)
g++ $(OBJ) -o $(BIN) $(LDFLAGS)
-
Oh, thanks a lot brewbuck, works now :-)