首页 > 解决方案 > CMake 错误:AR19DD~1.EXE:致命错误:无法指定 -o 与 -c、-S 或 -E 与多个文件编译终止

问题描述

我正在尝试从一个纯粹由 C 文件组成的项目创建一个可执行文件。当我尝试创建一个库时,如下所示:

add_library(application)
target_sources(application PUBLIC main.c)
target_include_directories(application PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(application PUBLIC lib1 lib2 lib3)

图书馆创建成功。但是,如果我添加类似于以下内容的内容,我需要的是一个可执行文件(更准确地说是 .elf 文件):

add_executable(application.elf)
target_sources(application.elf PUBLIC main.c)
target_include_directories(application.elf PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(application.elf PUBLIC lib1 lib2 lib3)  

我收到以下错误: AR19DD~1.EXE: fatal error: cannot specify -o with -c, -S or -E with multiple files compilation terminated.

以下是我的编译器和链接器标志:

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -x c -mthumb -D__SAM3X8E__ -DDEBUG -DBOARD=ARDUINO_DUE_X -Dscanf=iscanf -DARM_MATH_CM3=true -Dprintf=iprintf -D__SAM3X8E__ -fdata-sections -ffunction-sections -mlong-calls -g3 -Wall -mcpu=cortex-m3 -c -pipe -fno-strict-aliasing -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror-implicit-function-declaration -Wpointer-arith -std=gnu99 -ffunction-sections -fdata-sections -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int -Wmain -Wparentheses -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef -Wshadow -Wbad-function-cast -Wwrite-strings -Wsign-compare -Waggregate-return  -Wmissing-declarations -Wformat -Wmissing-format-attribute -Wno-deprecated-declarations -Wpacked -Wredundant-decls -Wnested-externs -Wlong-long -Wunreachable-code -Wcast-align --param max-inline-insns-single=500")
set(CMAKE_EXE_LINKER_FLAGS "-mthumb -Wl,--gc-sections -mcpu=cortex-m3 -Wl,--entry=Reset_Handler -Wl,-T\"../flash.ld\"")

标签: cmakearm-none-eabi-gcc

解决方案


推荐阅读