[CMake] Use FIND_LIBRARY to search & link for an executable?

Michael Wild themiwi at gmail.com
Fri Sep 18 04:09:47 EDT 2009


On 18. Sep, 2009, at 9:15, Christian Ehrlicher wrote:

>> Von: Michael Wild
>>
>> On 18. Sep, 2009, at 8:14, Christian Ehrlicher wrote:
>>
>>> Hi,
>>>
>>> I've an external project which made the decision to create an
>>> executable which exports symbols. This means if you want to write a
>>> plugin for this project you have to link your plugin against this
>>> executable.
>>> Now I've the problem that FIND_LIBRARY doesn't find this executable.
>>> Does anybody knows a hack to be able to link against an executable
>>> which is not built by the project?
>>>
>>> I'm really lost here but I can't convince them to fix it... :(
>>> Managing an own patch to work around this problem isn't a good long-
>>> term perspective.
>>>
>>> Thx,
>>> Christian
>>
>> find_program?
>>
> You're right - I did not know that TARGET_LINK_LIBRARIES accepts this.

If you pass a full path to TARGET_LINK_LIBRARIES, it doesn't too much  
checking. I think it will do some basic checks that the file is valid  
(there was a discussion on that some time ago), but otherwise just  
passes the file on the link-line.

>> And that is a REALLY broken design (and AFAIK only works on Windows).
>>
> I'm currently investigating and think it doesn't work on linux at  
> all (which would be very good for me). I'm getting duplicate  
> symbols :)
>
> -->
> FIND_PROGRAM(STAGE_LIB STAGE PATHS /opt/3dviewer/bin)
> ADD_LIBRARY(dummy SHARED dummy.cpp)
> TARGET_LINK_LIBRARIES(dummy ${STAGE_LIB})
> -->
> /usr/local/bin/c++  -fPIC -g  -shared -Wl,-soname,libdummy.so -o  
> libdummy.so CMakeFiles/dummy.dir/dummy.cpp.o /opt/3dviewer/bin/STAGE
> /opt/3dviewer/bin/STAGE: In function `_fini':
> /usr/src/packages/BUILD/glibc-2.9/cc-nptl/csu/crti.S:37: multiple  
> definition of `_fini'
> /usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../lib64/crti.o:/usr/ 
> src/packages/BUILD/glibc-2.9/cc-nptl/csu/crti.S:37: first defined here
> /opt/3dviewer/bin/STAGE: In function `_init':
> /usr/src/packages/BUILD/glibc-2.9/cc-nptl/csu/crti.S:25: multiple  
> definition of `_init'
> /usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../lib64/crti.o:/usr/ 
> src/packages/BUILD/glibc-2.9/cc-nptl/csu/crti.S:25: first defined here
> /usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/ 
> bin/ld: libdummy.so: version node not found for symbol vtable for  
> __cxxabiv1::__class_type_info@@CXXABI_1.3
> /usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/ 
> bin/ld: failed to set dynamic section sizes: Bad value
> collect2: ld returned 1 exit status
> -->
>
> I should have tried this earlier :)
>
> Thx,
> Christian
>

Probably you CAN get around these multiple definitions error by using  
a linker-script when building this STAGE program. The later errors are  
more worrying...

Michael



More information about the CMake mailing list