[CMake] Weird linking error while cross compiling

Andreas Pakulat apaku at gmx.de
Wed Oct 26 04:28:29 EDT 2011


On 26.10.11 03:54:02, Jose wrote:
> Sorry for not being very specific.
> 
> This is the command that Cmake is running while linking :
> 
> /usr/bin/i686-pc-mingw32-g++  -O3 -O3    -Wl,-Bstatic -static-libgcc
> -Wl,--whole-archive CMakeFiles/sqt2pin.dir/objects.a -Wl,--no-whole-archive
> -o sqt2pin.exe -Wl,--out-implib,libsqt2pin.dll.a
> -Wl,--major-image-version,0,--minor-image-version,0
> -L/home/fedora/percolator/percolator/src/converters/../../src
> libconverters.a libperclibrary_part.a MSToolkit/libMSToolkit.a
> MSToolkit/RAMP/libRAMP.a -lxerces-c -lportablexdr
> /home/fedora/percolator/percolator/src/converters/libs/dll/libtokyocabinet.a
> -lz -lsqlite3 -Wl,-Bstatic -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32
> -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
> /usr/lib/gcc/i686-pc-mingw32/4.5.3/../../../../i686-pc-mingw32/bin/ld:
> cannot find -lxerces-c
> /usr/lib/gcc/i686-pc-mingw32/4.5.3/../../../../i686-pc-mingw32/bin/ld:
> cannot find -lportablexdr
> /usr/lib/gcc/i686-pc-mingw32/4.5.3/../../../../i686-pc-mingw32/bin/ld:
> cannot find -lz
> /usr/lib/gcc/i686-pc-mingw32/4.5.3/../../../../i686-pc-mingw32/bin/ld:
> cannot find -lsqlite3
> 
> That is weird cos I "load" all the libraries in the same way and they all
> the variables content the right paths to the libraries : (for example)
> 
> Xercesc : /usr/i686-pc-mingw32/sys-root/mingw/lib/libxerces-c.dll.a , XDR :
> /usr/i686-pc-mingw32/sys-root/mingw/lib/libportablexdr.dll.a
> 
> This is how I link :
> 
> #COMPILING SQT2PIN
> include_directories(. MSToolkit/RAMP MSToolkit )
> add_executable(sqt2pin Sqt2Pin.cpp )
> IF(STATIC AND MINGW)
>   set_property(TARGET sqt2pin PROPERTY LINK_SEARCH_END_STATIC ON)
>   set_target_properties(sqt2pin PROPERTIES LINK_FLAGS "-Wl,-Bstatic
> -static-libgcc")
> ENDIF()
> message(STATUS "Xercesc : ${XERCESC_LIBRARIES} , XDR :
> ${PORTABLEXDR_LIBRARIES}")
> target_link_libraries(sqt2pin converters perclibrary_part  MSToolkit RAMP
> ${XERCESC_LIBRARIES} ${PORTABLEXDR_LIBRARIES} ${TOKYOCABINET_LIBRARIES} )
> 
> I might  be missing something very stupid because I use the same prodecure
> to search for the librarys....the FindXXX.cmake macros that are tested and
> working with other programs.
> 
> Could it be the include_directories("library include dir") which is messing
> this up? it looks like the linker disregard the path of the library that Im
> pasinng and looks for -lxerces-c instead. Is that xerces-c defined somehow
> before?

This happens if the library is considered to be in a 'system path' since
in that case specifying the path is not necessary for the linker to find
it. However in your specific case it seems like cmake does this even for
static libraries, which is of course wrong. I'd suggest to file a
bugreport for this with a small self-contained example.

Andreas



More information about the CMake mailing list