PDA

View Full Version : I can compile a program in redhat but not in ubuntu



shevin
October 27th, 2011, 07:50 AM
guys
I wrote a code for an assignment, I can compile it on the university's redhat server
but it gives me this error on ubuntu


g++ -lpthread telephoneGame.cpp -o telephoneGame

/tmp/ccQBQKsY.o: In function `main':
telephoneGame.cpp:(.text+0x27a): undefined reference to `pthread_create'
telephoneGame.cpp:(.text+0x2b2): undefined reference to `pthread_join'
collect2: ld returned 1 exit status

cguy
October 27th, 2011, 09:39 AM
You need to link the pthread library. Add "-lpthread" to your "gcc" command.

Zugzwang
October 27th, 2011, 11:06 AM
g++ -lpthread telephoneGame.cpp -o telephoneGame


Try putting "-lpthread" at the end of the line - the order of parameters might be important here.

shevin
October 27th, 2011, 03:38 PM
Try putting "-lpthread" at the end of the line - the order of parameters might be important here.

still no luck ! the thing is, the gcc on both computers are same versions but one is redhat and one is ubuntu ...whats wrong ?

karlson
October 27th, 2011, 03:44 PM
still no luck ! the thing is, the gcc on both computers are same versions but one is redhat and one is ubuntu ...whats wrong ?

Try running


gcc -pthread TelephoneGame.cpp -o TelephoneGame -lpthread


You may have to compare gcc specs files to find the differences between the two.

MadCow108
October 27th, 2011, 10:47 PM
placing -lpthread at the end or using -pthread must solve the issue.
see e.g. for a similar problem
http://ubuntuforums.org/showthread.php?t=1869838

caused by ld --as-needed now default in ubuntu 11.10

shevin
October 31st, 2011, 10:57 PM
placing -lpthread at the end or using -pthread must solve the issue.
see e.g. for a similar problem
http://ubuntuforums.org/showthread.php?t=1869838

caused by ld --as-needed now default in ubuntu 11.10

if u looka t my first post , I had put -lpthread , but still in redhat it compiled very well and not in ubuntu ...anyway I changed my code , and now my new code compiles in both

MadCow108
October 31st, 2011, 11:19 PM
if u looka t my first post , I had put -lpthread , but still in redhat it compiled very well and not in ubuntu ...anyway I changed my code , and now my new code compiles in both

your first post is _wrong_, you must put the -lpthread to the end of the command line (or use -pthread).
yes that is important in ubuntu 11.10.

shevin
November 20th, 2011, 11:48 AM
your first post is _wrong_, you must put the -lpthread to the end of the command line (or use -pthread).
yes that is important in ubuntu 11.10.


I tried with both -lpthread and -pthread , in the begining, in the end, alone or with combination of both .
and still get these errors in ubuntu :



telephoneGame.cpp: In member function ‘void Sentence::imperfectlyTransmit()’:
telephoneGame.cpp:126:26: error: ‘rand’ was not declared in this scope
telephoneGame.cpp: In function ‘void* child(void*)’:
telephoneGame.cpp:289:17: error: ‘rand’ was not declared in this scope
telephoneGame.cpp: In function ‘int main(int, const char**)’:
telephoneGame.cpp:353:35: error: ‘atoi’ was not declared in this scope
telephoneGame.cpp:360:41: error: ‘atoi’ was not declared in this scope
telephoneGame.cpp:363:22: error: ‘srand’ was not declared in this scope
telephoneGame.cpp:396:12: error: ‘EXIT_SUCCESS’ was not declared in this scope




but in redhat it compiles beautifuly !


what is wrong with ubuntu ?

Bachstelze
November 20th, 2011, 12:07 PM
Nothing is wrong with Ubuntu. Something is wrong with your posts, though: we need the entire error message, not just bits and pieces.

gateway67
November 20th, 2011, 03:50 PM
I tried with both -lpthread and -pthread , in the begining, in the end, alone or with combination of both .
and still get these errors in ubuntu :

Include stdlib.h in your code.