[CMake] How to specify -fpic ?
Michael Wild
themiwi at gmail.com
Thu Sep 30 07:19:47 EDT 2010
On 30. Sep, 2010, at 13:05 , David Aldrich wrote:
> Hi
>
> Ok, by following the link to the wiki suggested by Michael Loose, I used:
>
> target_link_libraries( myProj -Wl,-whole-archive Kernel -Wl,-no-whole-archive)
>
> This has fixed my problem. The executable links and runs correctly.
>
> My link command is now:
>
> /usr/bin/c++ -O3 -DNDEBUG -Wall -m64 -Wl,--export-dynamic -o myProj -Wl,-whole-archive Kernel/libKernel.a -Wl,-no-whole-archive -ldl -lpython2.4
>
> I don't need portability so I think this is ok.
>
> Michael Wild wrote:
>
>> The -whole-archive flag is pretty useless with executables
>> (unless, you plan to use it as a library too, but that is
>> outlandish). --export-dynamic may be also necessary, if
>> your dlopen'ed libraries use symbols in your executable.
>
> So my concern is now: am I being 'outlandish' ? The dlopen'ed libraries do use functions in libKernel.a that is linked to the executable. Is this outlandish? Is there a better way?
The "outlandish" referred to using an executable also as a library, so you're fine :-) But I think I found the reason for why you need this -whole-archive flag: Since your executable doesn't use all of the functions in the Kernel library, the linker throws them away. This results in your dlopen'ed functions to fail.
So, the options are:
- use -whole-archive as you do now
- make the Kernel library shared
- link the dlopen'ed libraries against Kernel
Michael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100930/47054e69/attachment.pgp>
More information about the CMake
mailing list