views:

750

answers:

2

I am trying to compile a program I wrote in C++ for an assignment that uses pthreads. I am using Eclipse in Linux, and I didn't have any problems compiling, after I added "-lpthread" to the compiler arguments (to g++, gcc and linker). However, when I was about to run and debug, Eclipse gave me an error message window "Launch failed. Binary not found."

I tried to manually compiling it with gcc and g++, with suffixes -pthread and -lpthread, and the result it similar - "gcc: –pthread: No such file or directory".

Not sure what wrong, because it does compile without problems, just doesn't produce an exe. I believe I might need to apt-get something.

anything I should do?

+4  A: 

How are you compiling? This should work just fine:

gcc -o foo foo.c -lpthread

cartman
gcc –pthread ./*.cpp -o Ex2.exeg++ –pthread ./*.cpp -o Ex2.exegcc –lpthread ./*.cpp -o Ex2.exeg++ –lpthread ./*.cpp -o Ex2.exenon of which work.
Nefzen
@Nefzen - don't use two dashes before pthread, it's just a single dash.
Jason Coco
You only need one pthread statement and -lpthread at the end is enough.
cartman
ok, I added the -lpthread to the linker only in Eclipse, now it works. hurray. happy debugging now.
Nefzen
Cool, feel free to mark my answer :)
cartman
+1  A: 

g++ -pthread -ggdb -Wall -pedantic -o myexe *.cpp -lpthread should work.

Nikolai N Fetissov
now it gives me an "undefined reference to `void* Run<Dispatcher>(void*)' " error, though still no error in Eclipse, and yet still it does not produce a binary.
Nefzen
This means the linker cannot find the template expansion for the Run() function.
Nikolai N Fetissov
yes, I moved the template to the header, should have picked it up before. Well it's running, but I'm getting an exception it's not catching, probably in another thread :\
Nefzen
Uncaught exception will terminate the program. If you get a "core" file - load that into debugger with "gdb prog core-file" to see where it's being raised. The following gdb commands come useful when debugging threaded apps: "info threads", "thread apply all bt", "thread <tid>".
Nikolai N Fetissov