Results 1 to 3 of 3

Thread: Add lpthread in makefile

  1. #1
    Join Date
    Jan 2009
    Beans
    323

    Add lpthread in makefile

    Hi,
    How to add lpthread option to my makefile?
    My make command output is as bellow:
    Code:
    huangyingw@laptop:/media/volgrp/myproject/git/cplusplus/linux/fundamental/semaphore$ make
    g++ -ansi -W -Wall -lstdc++ -I../test -lpthread test.o -o test.exe
    test.o: In function `main':
    test.cc:(.text+0xbc): undefined reference to `pthread_create'
    test.cc:(.text+0xd7): undefined reference to `pthread_create'
    test.cc:(.text+0xe8): undefined reference to `pthread_join'
    test.cc:(.text+0xf9): undefined reference to `pthread_join'
    collect2: error: ld returned 1 exit status
    make: *** [test.exe] Error 1
    the content of my makefile:
    Code:
    huangyingw@laptop:/media/volgrp/myproject/git/cplusplus/linux/fundamental/semaphore$ cat makefile 
    OBJECTS = test.exe
    include /home/huangyingw/myproject/git/makefile/GNU_makefile_template
    LOCFLAGS = -I../test
    LOCFLAGS += -lpthread
    the content of /home/huangyingw/myproject/git/makefile/GNU_makefile_template:
    Code:
    huangyingw@laptop:/media/volgrp/myproject/git/cplusplus/linux/fundamental/semaphore$ cat /home/huangyingw/myproject/git/makefile/GNU_makefile_template
    CC = g++
    CCFLAGS = -ansi -W -Wall -lstdc++
    LOCFLAGS =
    all: $(OBJECTS)
    %.o: %.cc %.cpp
    	$(CC) $(CCFLAGS) $(LOCFLAGS) -c $< -o $@
    %.exe: %.o
    	$(CC) $(CCFLAGS) $(LOCFLAGS) $< -o $@
    clean:
    	rm -rf *.o core *.stackdump
    clobber: clean
    	rm -rf *.exe

  2. #2
    Join Date
    Apr 2009
    Location
    Germany
    Beans
    2,134
    Distro
    Ubuntu Development Release

    Re: Add lpthread in makefile

    its best to add -pthread to CCFLAGS that handles required compile and link time changes

    to only use -lpthread (which you should not) do something like this:
    Code:
    LIBS ?= -lpthread
    
    %.exe: %.o
    	$(CC) $(CCFLAGS) $(LOCFLAGS) $< $(LIBS) -o $@
    libraries after objects

  3. #3
    Join Date
    Jan 2009
    Beans
    323

    Re: Add lpthread in makefile

    Quote Originally Posted by MadCow108 View Post
    its best to add -pthread to CCFLAGS that handles required compile and link time changes

    to only use -lpthread (which you should not) do something like this:
    Code:
    LIBS ?= -lpthread
    
    %.exe: %.o
    	$(CC) $(CCFLAGS) $(LOCFLAGS) $< $(LIBS) -o $@
    libraries after objects
    Great thanks.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •