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

Re: [MiNT] g++ & --enable-threads=posix



Alan Hourihane wrote:
Hi Vincent,

I've compiled my version of gcc 4.2.3 natively with the extra flag
--enable-threads=posix.

This changes things for libstdc++, in that any program that is C++
compiled will need to link against pthreads.

Is there a way internally in the compiler to force linkage against
pthreads ?

One way to achieve this is to use a custom linker script.
The default linker scripts are embedded inside ld.
A copy (not used) of the linker scripts is in the file
/usr/local/cross-mint/m68k-atari-mint/lib/ldscripts/m68kmint.x (cross)
/usr/lib/ldscripts/m68kmint.x (native)

You can use the file m68kmint.x as a starting point and create a script named, for example, myscript, in the ldscripts directory.

Useful documentation can be found here:
http://sourceware.org/binutils/docs-2.18/ld/File-Commands.html#File-Commands

You need to add an INPUT statement at the top of the script.
For example, INPUT(-lpthread).
It behaves just if that input file/library was added on the linker command line.

But if you want to use your modified linker script, you have 2 solutions:
1) Pass it on the command line with the -T option
2) Modify the script template and recompile the binutils

Example using the command line:
$ cat /usr/local/cross-mint/m68k-atari-mint/lib/ldscripts/myscript
/* Default linker script, for normal executables */
OUTPUT_FORMAT("a.out-mintprg")
SEARCH_DIR("/usr/local/cross-mint/m68k-atari-mint/lib");
INPUT(-lpthread)
SECTIONS
{
...

$ m68k-atari-mint-gcc hello.c -o hello.o -Tldscripts/myscript

Warning, the INPUT statement in the linker script insert the file/library *at the same command line position as the -T option*.

Note that -T is a linker option. But is seems that gcc accepts it, too (undocumented), and pass it to the linker.
The good syntax should be -Wl,-Tldscripts/myscript

Anyway, that linker script method doesn't seem to be the right way to do what you want, because adding an extra parameter on the command line or rebuilding the binutils is not very transparent... Maybe it is possible to achieve some equivalent result with an environment variable, or with some GCC mechanism ?

Filnally: I had a quick look at the default linker script of Cygwin and Linux, there is no additional INPUT directive, so I'm not really sure it is a good idea to play with that.

Anyway, good luck !

--
Vincent Rivière