cmake cross-compile with specific linker doesn't pass arguments to armlink

匿名 (未验证) 提交于 2019-12-03 03:03:02

问题:

I am trying to cross-compile a project for embedded ARM Cortex builds but unable to get the linker working. I want to use armlink but no files are passed to armlink and hence no .elf file is produced.

My CMakeLists.txt is pretty simple and given below. The failure is shown after that which shows that armlink was invoked by the makefile without any arguments.

Any pointers will help - I searched and read many posts but they all seem to have more involved requirements.

cmake_minimum_required(VERSION 2.8)  project(test_arm) enable_language(C ASM)  # cross-compilation for ARM SET(CMAKE_C_COMPILER armcc) SET(CMAKE_LINKER armlink) SET(CMAKE_C_LINK_EXECUTABLE armlink)  SET(CMAKE_C_FLAGS "--cpu=Cortex-M3") SET(LINK_FLAGS "--map --ro-base=0x0 --rw-base=0x0008000 --first='boot.o(RESET)' --datacompressor=off") SET(CMAKE_EXE_LINKER_FLAGS "--map --ro-base=0x0 --rw-base=0x0008000 --first='boot.o(RESET)' --datacompressor=off")  include_directories(../include)  add_executable( blinky blinky.c ) set_target_properties( blinky PROPERTIES LINKER_LANGUAGE C)

The failure is as follows but I guess it would be obvious to someone given that I have some stupid issue in my CMakeLists:

$ make VERBOSE=1 [100%] Building C object CMakeFiles/blinky.dir/blinky.c.o /usr/bin/cmake -E cmake_link_script CMakeFiles/blinky.dir/link.txt --verbose=1 armlink Linking C executable blinky Product: DS-5 Professional 5.21.0 [5210017] Component: ARM Compiler 5.05 update 1 (build 106) Tool: armlink [4d0efa] For support see http://www.arm.com/support/ Software supplied by: ARM Limited Usage: armlink option-list input-file-list where ....

I was expecting the CMake generated Makefile to invoke armlink with something like:

armlink --map --ro-base=0x0 --rw-base=0x0008000 \   --first='boot.o(RESET)' --datacompressor=off \   CMakeFiles/blinky.dir/blinky.c.o -o blinky.elf

回答1:

From my experience, you cannot set CMAKE_EXE_LINKER_FLAGS in a CMakeLists.txt-file but it has to be passed via a CMAKE_TOOLCHAIN_FILE when cmake is invoked the very first time in a build-dir.

I don't find any documentation regarding this problem, but there is the cross-compilation with cmake-page which you should use it if you do cross-compilation.

For a start just put your set-calls in a toolchain-file and run

cmake -DCMAKE_TOOLCHAIN_FILE=

in a clean build-dir.



回答2:

A toolchain file may be a good idea. Here is what I've came up the last time I tried CMake 2.8.10 with the DS-5 toolchain (could still be optimized, but it should give you a starting point):

INCLUDE(CMakeForceCompiler)  # this one is important SET(CMAKE_SYSTEM_NAME Generic) SET(CMAKE_SYSTEM_PROCESSOR arm)  # specify the cross compiler SET(CMAKE_C_COMPILER "C:/Program Files (x86)/DS-5/bin/armcc.exe") SET(CMAKE_CXX_COMPILER "C:/Program Files (x86)/DS-5/bin/armcc.exe") SET(CMAKE_AR "C:/Program Files (x86)/DS-5/bin/armar.exe" CACHE FILEPATH "Archiver")  #CMAKE_FORCE_C_COMPILER("C:/Program Files (x86)/DS-5/sw/gcc/bin/arm-linux-gnueabihf-gcc.exe" GNU) #CMAKE_FORCE_CXX_COMPILER("C:/Program Files (x86)/DS-5/sw/gcc/bin/arm-linux-gnueabihf-g++.exe" GNU)  UNSET(CMAKE_C_FLAGS CACHE) SET(CMAKE_C_FLAGS "--cpu=Cortex-A9 --thumb -Ospace" CACHE STRING "" FORCE) UNSET(CMAKE_CXX_FLAGS CACHE) SET(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS} CACHE STRING "" FORCE) UNSET(CMAKE_EXE_LINKER_FLAGS CACHE) SET(CMAKE_EXE_LINKER_FLAGS "" CACHE STRING "" FORCE) UNSET(CMAKE_AR_FLAGS CACHE) SET(CMAKE_AR_FLAGS "-p -armcc,-Ospace" CACHE STRING "" FORCE)  # set(CMAKE_C_ARCHIVE_CREATE " cr   ") SET(CMAKE_C_ARCHIVE_CREATE " ${CMAKE_AR_FLAGS} -o  " CACHE STRING "C Archive Create") # set(CMAKE_CXX_ARCHIVE_CREATE " cr   ") SET(CMAKE_CXX_ARCHIVE_CREATE " ${CMAKE_AR_FLAGS} -o  " CACHE STRING "CXX Archive Create")  include_directories("C:/Program Files (x86)/DS-5/include") #include_directories("C:/Program Files (x86)/DS-5/sw/gcc/arm-linux-gnueabihf/libc/usr/include/arm-linux-gnueabi")  # where is the target environment  SET(CMAKE_FIND_ROOT_PATH "C:/Program Files (x86)/DS-5")  # search for programs in the build host directories SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # for libraries and headers in the target directories SET(
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!