Thread: Simple makefile problem

  1. #1
    Registered User
    Join Date
    Nov 2006

    Simple makefile problem

    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...

    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
            rm -f *.obj core
    And well, when I try to make it, I get the following output:

    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 ), 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


  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Portland, OR
    Add this:

    And change this:

    $(BIN): $(OBJ)
            g++ $(OBJ) -o $(BIN)
    To this:

    $(BIN): $(OBJ)
            g++ $(OBJ) -o $(BIN) $(LDFLAGS)

  3. #3
    Registered User
    Join Date
    Nov 2006
    Oh, thanks a lot brewbuck, works now :-)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A simple file I/O problem
    By eecoder in forum C Programming
    Replies: 10
    Last Post: 10-16-2010, 11:00 PM
  2. Makefile Problem: None rule to make target
    By chris24300 in forum Linux Programming
    Replies: 25
    Last Post: 06-17-2009, 09:45 AM
  3. A simple problem with "include" definition and makefile
    By junketeer in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2009, 03:01 AM
  4. Problem in very simple code
    By richdb in forum C Programming
    Replies: 22
    Last Post: 01-14-2006, 09:10 PM
  5. Simple Initialization Problem
    By PsyK in forum C++ Programming
    Replies: 7
    Last Post: 04-30-2004, 07:37 PM