Re: G++ Help
- From: moma <moma@xxxxxxxxxxx>
- Date: Mon, 23 Jan 2006 19:09:27 +0100
carbonrocket@xxxxxxxxx wrote:
> Hi all,
> would anyone be able to help me complie a g++ app that uses the
> pthreads library?
>
> Ive created a class that wraps pthreads based on a listing from a book.
> Mine did not compile so now I am trying to compile the code from the
> book first. I have uploaded th source to crellbar.com/pthreads/
>
> I try "g++ -lpthread Listing1-6.cpp" and it does not work, i assume
> this is because I am using the linker incorrectly or something along
> those lines. I did something similar in MS VS.net where I forgot to
> compile with MFC but cant find a fix for g++ with pthreads under linux.
>
> Essentially I am asking if I am compiling the files correctly.
>
> Cheers.
> Paul.
>
Hello Paul,
In thread.cpp:
1) Obviously missing
#include <iostream>
2) A few syntax errors
Eg. missing "std::" in
Thread::Thread(std::auto_ptr<Runnable> runnable .....
-------------------------------------
It's best to create and use a Makefile !
------
But this is how to compile and link your code manually.
First compile thread.cpp and runnable.cpp. The result is object files
thread.o and runnable.o
g++ -c thread.cpp
g++ -c runnable.cpp
Now compile the main program (Listing1-6.cpp) and link all modules
together with the libpthread library.
g++ -o Listing1-6 -lpthread thread.o runnable.o Listing1-6.cpp
And finally run it
../Listing1-6
-------------------
Now learn howto to create and use a Makefile.
Recommended reading: "Advanced Linux programming(pdf)"
Yuo'll find a link to this book here
http://www.futuredesktop.org/opportunities.html
---------------------
Sincerely
//moma
http://www.futuredesktop.org/how2burn.html#Ubuntu <-- Ubuntu resources
.
- Follow-Ups:
- Re: G++ Help
- From: carbonrocket
- Re: G++ Help
- References:
- G++ Help
- From: carbonrocket
- G++ Help
- Prev by Date: post build step and Makefile.am
- Next by Date: Re: G++ Help
- Previous by thread: Re: G++ Help
- Next by thread: Re: G++ Help
- Index(es):
Relevant Pages
|