CMake 错误:AR19DD~1.EXE:致命错误:无法使用 -c、-S 或 -E 指定 -o 并终止多个文件编译

问题描述

我正在尝试从一个纯粹由 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\"")

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)