[Coin-discuss] Missing flags when building COIN projects on x86_64 (AMD64)?
Andreas Waechter
andreasw at watson.ibm.com
Tue Nov 28 16:06:47 EST 2006
Hi Kish,
I guess I can say a little bit about this:
We are using the GNU facility "libtool" to find out about flags for
compiling and linking libraries.
Libtool does correctly set the PIC flags on all supported platforms, when
it compiles code for shared libraries. In fact, if you run configure with
both --enable-static and --enable-shared, each source file is compiled
twice, once for the a static archive and once for a shared library.
If you would use the COIN makefiles etc to create the shared libraries for
the individual COIN projects, everything should work fine for you.
However, I assume that you don't want to do this, because you don't want
to have everything collected into your own shared library?
The easiest way to have the COIN Makefiles create static .a archives with
PIC code is, as you suggested, to pass the -fPIC flag to the compiler.
However, I strongly suggest that you don't overwrite CFLAGS etc directly,
as you wrote, since this is also overwrite any optimization and other
flags.
Instead, you can use the configuration variables
ADD_CFLAGS
ADD_CXXFLAGS
ADD_FFLAGS
and set them to contain -fPIC, like
configure --enable-static ADD_CFLAGS="-fPIC" ADD_CXXFLAGS="-fPIC"
This will cause our configuration scripts to still detect good compiler
flags on its own, but add those indicated flags in addition.
I just realized that this is not yet documented in
https://projects.coin-or.org/CoinHelp/wiki/user-configure#VariableArgumentsforconfigure
so I will add this information now.
I hope this solves your problem.
Andreas
On Sat, 25 Nov 2006, Kish Shen wrote:
> Hi,
>
> I have ran into some problems with a Cbc built on x86_64 (or more precisely, the AMD64 variant)
> Linux with the standard configure and make:
>
> the main problem is during compilation of the Coin libraries, the flag -fPIC is needed to get gcc
> to generate PIC (Position Independent Code). PIC is needed because we link the Coin libraries
> (.so, .a and .o) into our own dynamic (.so) library, i.e. we are doing something like
>
> gcc -shared mycode.o -lCbc -o mylib.so
>
> I get an error saying that -fPIC is needed.
>
> I worked around this by giving extra flags during configure:
>
> configure --enable-static CFLAGS="-fPIC" CXXFLAGS="-fPIC"
>
> However, it would be nice if configure could detect this automatically and add the flags
> automatically. [the -fPIC flag can be given even if the resulting code is not linked to produce
> .so files]
>
> On a related topic -- the same AMD64 processor I used had SunOS (Solaris) installed on
> it previously, and for our own code, in addition to the -fPIC flag, we needed -m64 for both
> compiling and linking to get the 64 bit code to be generated (otherwise 32 bit code is generated
> by default). Here we would need to configure as follow:
>
> configure --enable-static CFLAGS="-fPIC -m64" CXXFLAGS="-fPIC -m64" LDFLAGS="-m64"
>
> Again, it would be useful if these can be generated automatically by configure. [the -m64 flag
> can also be given for the x86_64 Linux, but is not needed]
>
> While I was compiling Cbc, I think the same issue applies to other COIN project (I have tried
> SYMPHONY).
>
> --Kish Shen
> _______________________________________________
> Coin-discuss mailing list
> Coin-discuss at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/coin-discuss
>
More information about the Coin-discuss
mailing list