下面的cMakeLists.txt文件出现错误。错误是
对象库目标“ cm”可能未链接到任何内容。
问题出在第target_link_libraries(cm corebase)
行
这在Linux上构建正常,但我在Windows上发生此错误。
我会感谢您的想法吗?
file(GLOB base
"*.cpp"
)
file (GLOB model
"*.cpp"
)
file(GLOB logger
"*.cpp"
)
file(GLOB pass
"*.cpp"
)
file(GLOB compiler
"src/compiler/*"
)
add_subdirectory(meta)
if (MSVC)
add_library(cm OBJECT ${compiler} ${pass})
add_library(corebase OBJECT ${base} ${logger})
add_library(model OBJECT ${model})
target_link_libraries(cm corebase)
add_dependencies(cm generate-comp-api)
add_dependencies(model generate-comp-api)
else()
add_library(cm SHARED ${base} ${logger} ${pass} ${compiler})
add_library(corebase SHARED ${base} ${logger})
add_library(model SHARED ${model})
target_link_libraries(cm corebase metamodel)
add_dependencies(cm generate-comp-api)
add_dependencies(model generate-comp-api)
add_subdirectory(python/api)
add_subdirectory(tests)
add_subdirectory(contrib/googletest)
#add_subdirectory(recordings)
endif(MSVC)
答案 0 :(得分:1)
错误消息是正确的:OBJECT libraries不应链接到任何内容。相反,需要使用与库相对应的目标文件作为可执行文件/其他库的源文件:
# Create an OBJECT library
add_library(corebase OBJECT ${base} ${logger})
# And use its objects for other library.
add_library(cm OBJECT ${compiler} ${pass} $<TARGET_OBJECTS:corebase>)