[CMake] cmake cross-compile (arm) -> linker error: undefined
reference to `__CTOR_LIST__'
Henty Waker
hentyw at ipay.co.za
Fri Jul 28 19:05:59 EDT 2006
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).
for 4) Linking useing -l is probably a better option anyway.
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)?
Many thanks
Henty
*** More detailed output from the cmake generated Makefile:
Linking C executable ../../dist/bin/lmt3000s/iPayMobilePos
/usr/bin/cmake -E remove -f ../../dist/bin/lmt3000s/iPayMobilePos
cd /home/hentyw/projects/ipay/iPayMobilePos-talexus.cmake/src/mposMain
&& arm-elf-gcc -O3 -march=armv4t -mtune=arm7tdmi -Wall --static -fPIC
--static -elf2flt "CMakeFiles/iPayMobilePos.dir/logon.o"
<snip list of object files>
-o ../../dist/bin/lmt3000s/iPayMobilePos
-rdynamic
-L/home/hentyw/projects/ipay/iPayMobilePos-
talexus.cmake/build/lib/lmt3000s
<snip list of link directories>
-lmposmod-cell -lmposmod-cellstock -lmposmod-elec -lmposmod-elecstock -
lmposmod-elec2way -lmposmod-elec2way-lmt3000s -lmposmod-fin -lmposmod-
retailmng -lmposmod-termmng -lmposmod-metro -lmpos -lmpos-lmt3000s -
lscew -lexpat -lbz2 -lftp -lz -lkeymap -lkeybox -lm -llmt3000s_sf -Wl,-
rpath,/home/hentyw/projects/ipay/iPayMobilePos-
talexus.cmake/build/lib/lmt3000s:/home/hentyw/projects/ipay/iPayMobilePos-talexus.cmake/lib/bin/lmt3000s:/usr/local/arm-elf/lib:/usr/local/linudix/lib3000s/lib
arm-elf-gcc: unrecognized option `-rdynamic'
/usr/local/linudix/lib3000s/lib/liblmt3000s_sf.a(inputbox.o)(.text
+0x1d44): In function `lmt_inputbox_double_right':
: undefined reference to `ceil'
/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__'
collect2: ld returned 1 exit status
*** Detailed, edited, output from my old self-generated Makefile:
arm-elf-gcc -O3 -DLINUDIX -march=armv4t -mtune=arm7tdmi -Wall -Werror -
I./../../../ipayapp/include -I./../../../ipaylib/include -
I./../../../ipaymodules/include -
I./../../../ipaymodules/elec2way/port/linudix/include -
I./../../../ipaylib/port/linudix/include -I./../../../lib/include -
I/usr/local/linudix/lib3000s/include -o ipaypos --static
-elf2flt
./../../../ipayapp/src/logon.o
<snip object list>
./../../../ipaymodules/retailmng/port/linudix/libmodretailmng.a
./../../../ipaymodules/elec2way/port/linudix/libmodelec2way.a
./../../../ipaymodules/termmng/port/linudix/libmodtermmng.a
<snip lib list>
/usr/local/arm-elf/lib/libm.a
*** Extracts from various cmake files. Can provide full files if
required:
***From a macro file
MACRO (MPOS_PLATFORM_LMT3000S)
SET(MPOS_PLATFORM lmt3000s)
ADD_DEFINITIONS(-DMPOS_PLATFORM=lmt3000s -
DMPOS_PLATFORM_MODEL=lmt3000se)
SET(C_CROSS_COMPILER arm-elf-)
SET(CMAKE_C_COMPILER "${C_CROSS_COMPILER}gcc")
SET(CMAKE_RANLIB "${C_CROSS_COMPILER}ranlib")
SET(CMAKE_AR "${C_CROSS_COMPILER}ar")
SET(CMAKE_C_FLAGS "-O3 -march=armv4t -mtune=arm7tdmi -Wall --static")
SET(CMAKE_COMPILER_IS_GNUCC 1)
SET(CMAKE_COMPILER_IS_GNUCXX 0)
SET(BUILD_SHARED_LIBS OFF)
# SET(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <FLAGS> -o <OBJECT> -c
<SOURCE>")
# SET(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <OBJECTS> -o
<TARGET> <LINK_LIBRARIES>")
ENDMACRO (MPOS_PLATFORM_LMT3000S)
***Called at a top level CMakeLists.txt file
MPOS_PLATFORM_LMT3000S()
***Called from the lower level CMakeLists.txt file that actually
***builds the exe.
ADD_EXECUTABLE(iPayMobilePos ${MPOS_MAIN_SRCS})
TARGET_LINK_LIBRARIES(iPayMobilePos ${MPOS_MODULE_LIBS} ${MPOS_LIBS}
${THIRD_PARTY_LIBS} ${MPOS_PLATFORM_LIBS})
SET_TARGET_PROPERTIES(iPayMobilePos PROPERTIES LINK_FLAGS "--static -
elf2flt")
#SET_TARGET_PROPERTIES(iPayMobilePos PROPERTIES SKIP_BUILD_RPATH TRUE)
#SET_TARGET_PROPERTIES(iPayMobilePos PROPERTIES LINKER_LANGUAGE C)
More information about the CMake
mailing list