我正在尝试获取mu C ++代码以作为目标文件(.o)进行编译,但是我可以以(.a,.dylib,可执行文件)形式获得它
我已经尝试过此答案:Copy out plain .o files with cmake
但是实际上并不理解该解决方案,它也不起作用。
我该如何实现?
这是我的CMake文件:
cmake_minimum_required(VERSION 3.10)
project(myProject)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(LIBS_DIR ${PROJECT_SOURCE_DIR}/../libs)
file(GLOB SOURCES
src/*.cpp
)
find_library(SQLITE3
NAMES libsqlite3.0.tbd
)
MACRO(HEADER_DIRECTORIES return_list)
FILE(GLOB_RECURSE new_list ${LIBS_DIR}/*.h*)
SET(dir_list "")
FOREACH(file_path ${new_list})
GET_FILENAME_COMPONENT(dir_path ${file_path} PATH)
SET(dir_list ${dir_list} ${dir_path})
ENDFOREACH()
LIST(REMOVE_DUPLICATES dir_list)
SET(${return_list} ${dir_list})
ENDMACRO()
add_library(${PROJECT_NAME}_obj OBJECT ${SOURCES})
HEADER_DIRECTORIES(HDR_DIRS)
target_include_directories(${PROJECT_NAME}_obj PUBLIC
${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/../fmt
${PROJECT_SOURCE_DIR}/../include
${HDR_DIRS}
)
target_link_libraries(${PROJECT_NAME}_obj ${SQLITE3})
您不能将多个翻译单元合并到一个目标文件中(由于链接器(ld util)的功能。仅适用于库或elf。
早期的gcc可以将多个文件合并为一个目标文件,但是该功能已删除