[CMake] cmake cross-compile (arm) -> linker error: undefined
reference to `__CTOR_LIST__'
Brad King
brad.king at kitware.com
Mon Jul 31 11:11:08 EDT 2006
Henty Waker wrote:
> Hi there
>
> I have some C code that I cross compiled for a small mobile point-of-
> sale device running uClinux on an arm processor.
>
> I currently use plain Makefiles to build a number of static libs that
> are linked to a single exe. The Makefiles work fine, but they're messy.
> I want to move over to cmake because it seems simpler and neater.
>
> Building the libs with Cmake is fine.
> However when I try and link the libs into the final exe I get:
>
> /usr/local/lib/gcc-lib/arm-elf/2.95.3/libgcc.a(__main.o)(.text+0xc4): In
> function `__do_global_ctors':
> : undefined reference to `__CTOR_LIST__'
> /usr/local/lib/gcc-lib/arm-elf/2.95.3/libgcc.a(__main.o)(.data+0x0):
> undefined reference to `__DTOR_LIST__'
>
> I don't get this using my standard Makefiles.
>
> A quick search indicates that these references are used by C++
> constructors and destructors, so I'm not sure what they have to do with
> my plain-old-C code.
>
> So I'm guessing that the cmake-generated Makefile is doing something
> different to my Normal Makefile. Details output from both methods is
> listed below, but in summary the differences seem to be:
>
> 1) cmake adds: -fPIC
> 2) cmake adds: -Wl,-rpath,..........
> 3) cmake adds: -rdynamic
> 4) cmake links libs using -llib-name whereas my Makefile was simply
> treating the .a lib like an object file.
>
> for 1) I can get rid of the -fPIC by redefining CMAKE_C_COMPILE_OBJECT
> (or was it CMAKE_C_LINK_EXECUTABLE).
Yes.
> for 4) Linking useing -l is probably a better option anyway.
Yes.
> However I can't get rid of 2) and 3).
>
> Can anyone give me a clue as to what might be wrong and if it's likely
> to be related to 2) and 3). If so, how can I change 2) and 3)?
For #2:
SET(CMAKE_SKIP_RPATH ON)
For #3:
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS)
ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
That variable is used when building executables in case they link shared
libraries.
If after these changes you still get the errors please continue to
compare the command lines used to invoke the compiler/linker by CMake
and your old makefiles.
-Brad
More information about the CMake
mailing list