<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body><div>Hex,</div><div><br></div><div>Can you see what else is in /opt/arm-none-eabi/lib/thumb/v7-ar/fpv3/hard (the same directory as libc.a)? There might be another system library that contains the _exit() implementation that isn't being linked due to your use of the -nostartfiles flag.</div><div><br></div><div>Kyle</div><div><br></div><div>On Fri, 2019-02-01 at 22:15 +0000, hex wrote:</div><blockquote type="cite">
<p>hello, <br>
</p>
<p>I am trying to include a static library that contains the startup
code for ARM processor to my CMake project for cross compilation.
<br>
</p>
<p> I included the linker script and added it to the executable.
Flags and include files are properly set in the CMake build
output. The path to the library is also correctly seen. <br>
</p>
<p>The linker fails on the startup code:</p>
<p><br>
</p>
<pre><code>Scanning dependencies of target testApp
[ 50%] Building CXX object CMakeFiles/testApp.dir/src/main.c.obj
[100%] Linking CXX executable testApp
/opt/gcc-arm-none-eabi-7-2017-q4-major/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/thumb/v7-ar/fpv3/hard/libc.a(lib_a-exit.o): In function `exit':
exit.c:(.text.exit+0x1c): undefined reference to `_exit'
/opt/gcc-arm-none-eabi-7-2017-q4-major/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/thumb/v7-ar/fpv3/hard/libc.a(lib_a-fini.o): In function `__libc_fini_array':
fini.c:(.text.__libc_fini_array+0x2c): undefined reference to `_fini'
/opt/gcc-arm-none-eabi-7-2017-q4-major/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/thumb/v7-ar/fpv3/hard/libc.a(lib_a-init.o): In function `__libc_init_array':
init.c:(.text.__libc_init_array+0x38): undefined reference to `_init'
collect2: error: ld returned 1 exit status
Here is my CMakeLists file:
<b>cmake_minimum_required(VERSION 3.5.1)</b><b>
</b><b>project (hello-world)</b><b>
</b><b>
</b><b>set(SOURCE_FILES src/main.c)</b><b>
</b><b>
</b><b>set (LINKER_SCRIPT linker_script.ld)</b><b>
</b><b>
</b><b>add_executable(${TARGET_NAME} ${SOURCE_FILES})</b><b>
</b><b>
</b><b>set_target_properties( ${TARGET_NAME} PROPERTIES LINK_DEPENDS ${LINKER_SCRIPT})</b><b>
</b><b>
</b><b>set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-build-id=none -Wl,-T ${LINKER_SCRIPT} " CACHE STRING "" FORCE )</b><b>
</b><b>
</b><b>set(COMMON_FLAGS "${COMMON_FLAGS} -march=armv7-a")</b><b>
</b><b>set(COMMON_FLAGS "${COMMON_FLAGS} -mfpu=vfpv3")</b><b>
</b><b>set(COMMON_FLAGS "${COMMON_FLAGS} -mfloat-abi=hard")</b><b>
</b><b>set(COMMON_FLAGS "${COMMON_FLAGS} -Wall")</b><b>
</b><b>set(COMMON_FLAGS "${COMMON_FLAGS} -O0")</b><b>
</b><b>set(COMMON_FLAGS "${COMMON_FLAGS} -nostartfiles")</b><b>
</b><b>set(COMMON_FLAGS "${COMMON_FLAGS} -fmessage-length=0")</b><b>
</b><b>set(COMMON_FLAGS "${COMMON_FLAGS} -fno-exceptions")</b><b>
</b><b>set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAGS}")</b><b>
</b><b>set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAGS}")</b><b>
</b><b>
</b><b>include_directories( inc )</b><b>
</b><b>
</b><b>find_library(LIB_C NAMES libc PATHS "lib" )</b><b>
</b><b>
</b><b>target_link_libraries(${TARGET_NAME} ${LIB_C})</b><b>
</b>
How can I solve this problem? The only dependency here is the library itself...
Thank you in advance for any response.
</code></pre>
<pre>--
Powered by <a href="http://www.kitware.com">www.kitware.com</a>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ">http://www.cmake.org/Wiki/CMake_FAQ</a>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:
CMake Support: <a href="http://cmake.org/cmake/help/support.html">http://cmake.org/cmake/help/support.html</a>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html">http://cmake.org/cmake/help/consulting.html</a>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html">http://cmake.org/cmake/help/training.html</a>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a>
Follow this link to subscribe/unsubscribe:
<a href="https://cmake.org/mailman/listinfo/cmake">https://cmake.org/mailman/listinfo/cmake</a>
</pre></blockquote></body></html>