Re: [Anjuta-list] re: How to build a project with threads



On Fri, 2003-07-18 at 04:49, Jeff Tickle wrote:
> This information is not well documented, but I had the same problem so
> I've been up for the last hour trying to figure it out.
> 
> In Anjuta, go to the Settings menu, then Compiler and Linker Settings. 
> Click the Others tab.  In the Linker flags box, put:
> 
> LDFLAGS='-lpthread'
> 
> and that's it!  Should build just fine.

Actually, it won't in all cases.

The problem is that some things have conditional compilation dependent
on whether threading is enabled or not, and other things may also change
(such as the memory management used, for instance).

On gcc/Linux, simply adding "-pthread" to every invocation (compilation
and linking) will do the trick. On other compilers, it can be much
trickier - on some systems such as AIX, I understand you need to use a
wholly different compiler.

In any case, you may well find that many libraries require different
versions to be used for multithreaded stuff, typically -lfoo might need
to be changed to -lfoo_r.

While the suggestion above from Jeff will work in most cases, it's quite
likely to explode violently when used with C++, since the std::allocator
implementation need to know whether threading is being used or not.

(FWIW, std::allocator will use a global lock in threading mode, and
moreover any possibility of two threads trying to delete the same object
at the same time will likely crash.)

There's some macros in the autoconf archive which you can stick into
configure.ac to handle selecting the right compiler options and
suchlike, but be aware they only change the CFLAGS, not the CXXFLAGS the
C++ compiler uses. (What fun.)

Hope this helps.

Dave.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]