Re: G++ Help



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


.



Relevant Pages

  • Re: Controlling recent APC UPS via USB
    ... Pulling apcupsd from CVS resulted in a bunch of errors in and around pthreads, but I haven't gone much down that road. ... int i, rc, ci, phys; ... Without most of these changes it will fail to compile, and later, link on my 4.2 i386 box. ...
    (comp.unix.bsd.openbsd.misc)
  • Re: /beta/pth207b.zip seems to need 686+
    ... I think it turns out that GNU pthreads 2.0.7 ... I tried again with FSU Pthreads, ... Tried this too, also didn't compile p7zip. ...
    (comp.os.msdos.djgpp)
  • Re: G++ Help
    ... > 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. ... Randy Crawford http://www.ruf.rice.edu/~rand rand AT rice DOT edu ...
    (comp.programming.threads)
  • Re: Controlling recent APC UPS via USB
    ... pthreads). ... Pulling apcupsd from CVS resulted in a bunch of errors in and around pthreads, but I haven't gone much down that road. ... int i, rc, ci, phys; ... Without most of these changes it will fail to compile, and later, link on my 4.2 i386 box. ...
    (comp.unix.bsd.openbsd.misc)
  • Re: Want to compile my roguelike
    ... you don't need a makefile with lcc-win32. ... The aboove applies to compiling Vanilla Angband 3.0.6 on my ... Cosmic Gerbil ... I've been working nearly all day trying to compile. ...
    (rec.games.roguelike.angband)