gpt4 book ai didi

build - CMAKE-对象库目标可能无法链接到任何内容

转载 作者:行者123 更新时间:2023-12-04 03:11:51 25 4
gpt4 key购买 nike

下面的 cMakeLists.txt 文件出现错误。错误是

Object library target "cm" may not link to anything.



问题出在线路 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)

最佳答案

错误信息是正确的: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>)

关于build - CMAKE-对象库目标可能无法链接到任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53416527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com