Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » GCC lpthread compilation woes
GCC lpthread compilation woes [message #1817309] Wed, 20 November 2019 10:15 Go to next message
Huyen John is currently offline Huyen JohnFriend
Messages: 1
Registered: November 2019
Junior Member
Let me preface this by saying I'm doing this for a class. Generally I live in SQL, this is one of my first forays into Linux and C. A header and code file were provided with the text book, they require the lpthread flag to be set during compilation and linking. Below are the commands eclipse issues to build the project. When I compile with eclipse, here's the error I'm running into.


**** Build of configuration Debug for project HW2 ****

make all
Building file: ../src/csapp.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -lpthread -MMD -MP -MF"src/csapp.d" -MT"src/csapp.d" -o "src/csapp.o" "../src/csapp.c"
Finished building: ../src/csapp.c

Building file: ../src/problem10.6.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -lpthread -MMD -MP -MF"src/problem10.6.d" -MT"src/problem10.6.d" -o "src/problem10.6.o" "../src/problem10.6.c"
Finished building: ../src/problem10.6.c

Building target: HW2
Invoking: GCC C Linker
gcc -lpthread -o "HW2" ./src/csapp.o ./src/problem10.6.o
./src/csapp.o: In function `Pthread_create':
/home/sonek/Documents/Workspace/HW2/Debug/../src/csapp.c:461: undefined reference to `pthread_create'
./src/csapp.o: In function `Pthread_cancel':
/home/sonek/Documents/Workspace/HW2/Debug/../src/csapp.c:468: undefined reference to `pthread_cancel'
./src/csapp.o: In function `Pthread_join':
/home/sonek/Documents/Workspace/HW2/Debug/../src/csapp.c:475: undefined reference to `pthread_join'
./src/csapp.o: In function `Pthread_detach':
/home/sonek/Documents/Workspace/HW2/Debug/../src/csapp.c:483: undefined reference to `pthread_detach'
./src/csapp.o: In function `Pthread_once':
/home/sonek/Documents/Workspace/HW2/Debug/../src/csapp.c:497: undefined reference to `pthread_once'
./src/csapp.o: In function `Sem_init':
/home/sonek/Documents/Workspace/HW2/Debug/../src/csapp.c:506: undefined reference to `sem_init'
./src/csapp.o: In function `P':
/home/sonek/Documents/Workspace/HW2/Debug/../src/csapp.c:512: undefined reference to `sem_wait'
./src/csapp.o: In function `V':
/home/sonek/Documents/Workspace/HW2/Debug/../src/csapp.c:518: undefined reference to `sem_post'
collect2: ld returned 1 exit status
make: *** [HW2] Error 1

**** Build Finished ****

When I copied the scr directory to the desktop and compiled directly through GCC and terminal, it worked. Here are the slightly modified commands I executed.

gcc -O0 -g3 -Wall -c -fmessage-length=0 -lpthread -MMD -MP -MF"csapp.d" -MT"csapp.d" -o "csapp.o" "csapp.c"
gcc -O0 -g3 -Wall -c -fmessage-length=0 -lpthread -MMD -MP -MF"problem.d" -MT"problem.d" -o "problem.o" "problem.c"
gcc -lpthread -o "HW2" csapp.o problem.o

So it seems I have the library installed but eclipse is having trouble finding it. Anyone know what I'm doing wrong?

I'm building this on a freshly build Ubuntu VM
Re: GCC lpthread compilation woes [message #1817323 is a reply to message #1817309] Wed, 20 November 2019 12:22 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30688
Registered: July 2009
Senior Member
It's best to ask on the CDT forum:

https://www.eclipse.org/forums/index.php?t=thread&frm_id=80
Previous Topic:Hi everybody
Next Topic:Hi all, im new and cant post to xtext subforum
Goto Forum:
  


Current Time: Tue Dec 10 15:58:31 GMT 2019

Powered by FUDForum. Page generated in 0.02843 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top