PDA

View Full Version : gcc problem.


realno
October 22nd, 2005, 12:48 PM
I wrote a small program using multi-thread(pthread_create etc.). I used the command "gcc a.c" to compile it on my old computer. After I install ubuntu 5.10, I have to use "gcc -lpthread a.c" to compile or I will get the information "undefined reference pthread_create". What is the problem here?

Thanks!!!

thumper
October 22nd, 2005, 01:17 PM
Did you do a typo in your code or in the message?

pthread_create with an E.

LordHunter317
October 22nd, 2005, 01:21 PM
Don't use -lpthread, use -pthreads.

realno
October 22nd, 2005, 02:33 PM
Sorry, that is a typo... But I did it right in the program . Thanks very much for the replys
I can compile the program. I just wonder if there is a way to avoid the command -lpthread or -pthreads.

LordHunter317
October 22nd, 2005, 02:38 PM
Nope. You must use if it you want multithreading support.

realno
October 23rd, 2005, 01:52 AM
But I'm very sure It don't need this command on my old computer and my school's computer:confused:

so weird:confused:

realno
October 23rd, 2005, 01:20 PM
BTW, my previous system is Redhat LINUX.

thumper
October 23rd, 2005, 05:01 PM
I don't suppose you have a sample of the work that you compiled on your previous system along with the command line?

realno
October 23rd, 2005, 05:20 PM
It just use pthread_create and mutex, very simple program.

And I used" gcc name.c -o name" to compile it.

LordHunter317
October 23rd, 2005, 05:39 PM
You got lucky, as pthread_Create is in libc, so libc can use it.

Multithreaded programs must be compiled -pthread. It's not optional.

realno
October 23rd, 2005, 06:17 PM
Thanks for all the helps:)
I'm so happy that I was so lucky :p