cmake target_link_libraries公共继承
我正在接受 Inffot 库。 imgui
库,该库是 Inflot
基于的库,将链接库声明为类型 public
,如下所示。
# ...
add_library(imgui ${IMGUI_HEADERS} ${IMGUI_SRC})
if(MSVC)
target_compile_options(imgui PRIVATE /W4 /WX /arch:AVX2 /fp:fast)
endif()
target_link_libraries(imgui PUBLIC glfw glad OpenGL::GL imm32)
target_compile_definitions(imgui PRIVATE IMGUI_DLL_EXPORT)
# ...
add_library(implot ${IMPLOT_HEADERS} ${IMPLOT_SRC})
target_link_libraries(implot PUBLIC imgui)
target_compile_definitions(implot PUBLIC IMPLOT_DEBUG IMPLOT_DLL_EXPORT IMPLOT_BACKEND_ENABLE_OPENGL3 IMGUI_IMPL_OPENGL_LOADER_GLAD)
set_property(TARGET implot PROPERTY CXX_STANDARD 11)
if(MSVC)
target_compile_options(implot PRIVATE /W4 /WX /arch:AVX2 /fp:fast /permissive-)
else()
target_compile_options(implot PRIVATE -Wall -Wextra -pedantic -Werror -mavx2 -Ofast)
endif()
由于 imgui
是 public
ly ly链接到 glfw
, glap
, opentgl :: gl , IMM32
,是否意味着 feffot
以及使用 Inflot
的人也将是 public
ly ly ly链接在 > glfw
, glad
, opengl :: gl
, inm32
?
这是因为 imgui
是共享库而背后的原因吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。更多详细信息可以在构建规范和使用要求。
是的。因为共享或
static
命名参数,用户可以通过提供-dbuild_shared_libs:bool = off
cmake(1)
参数。因此,要与之链接,链接器需要所有依赖关系列表。这是一个很好的做法,可以让他选择如何构建您的项目;-)Yes, it is. More details could be found in the official documentation in the section Build Specification and Usage Requirements.
Yes, it is. Since
add_library()
does not have anySHARED
orSTATIC
named parameter, a user may decide to build it statically by providing-DBUILD_SHARED_LIBS:BOOL=OFF
cmake(1)
parameter. So to link with it, a linker needs all the dependencies list. And this is a good practice to give him a choice on how to build your project ;-)