且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

具体连接cmake的交叉编译并不参数传递给armlink可以

更新时间:2023-10-22 23:39:34

CMake的V3.5 你并不需要一个工具链对了ARM的Keil C / C ++编译工具:


  

添加了对ARM编译器(arm.com)与编译器ID ARMCC支持。


块引用>

只需相应地设置你的C / CXX编译器变量

  cmake的-DCMAKE_C_COMPILER:PATH =C:\\ Program Files文件(x86)的\\ DS-5 \\ BIN \\ armcc.exe
      -DCMAKE_CXX_COMPILER:PATH =C:\\ Program Files文件(x86)的\\ DS-5 \\ BIN \\ armcc.exe
      ...

参考

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

Starting with CMake v3.5 you don't need a toolchain anymore for Keil ARM C/C++ compilation tools:

Support was added for the ARM Compiler (arm.com) with compiler id ARMCC.

Just set your C/CXX compiler variables accordingly

cmake -DCMAKE_C_COMPILER:PATH="C:\Program Files (x86)\DS-5\bin\armcc.exe"
      -DCMAKE_CXX_COMPILER:PATH="C:\Program Files (x86)\DS-5\bin\armcc.exe"
      ...

References