cmake target_link_libraries公共继承

发布于 2025-02-09 16:33:50 字数 1443 浏览 1 评论 0 原文

我正在接受 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 是共享库而背后的原因吗?

I am educating myself on a CMakeLists.txt of implot library. The imgui library, which is a library on which implot is based, declares the link libraries to be of type PUBLIC, as shown below.

# ...

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()

Since imgui is PUBLICly linked against glfw, glad, OpenGL::GL, imm32, does it mean that implot and whoever that uses implot will also be PUBLICly linked against glfw, glad, OpenGL::GL, imm32?

Is the reason behind this because of imgui being a shared library?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染墨丶若流云 2025-02-16 16:33:50

由于IMGUI与GLFW公开联系,Glad,OpenGl :: GL,Imm32,这是否意味着Inflot和使用Inflot的任何人也将与GLFW公开联系,GLFW,GLAIN,OPENGL :: GL,IMM32?

是的。更多详细信息可以在构建规范和使用要求

是因为IMGUI是共享库,这是此背后的原因吗?

是的。因为共享或 static 命名参数,用户可以通过提供 -dbuild_shared_libs:bool = off cmake(1) 参数。因此,要与之链接,链接器需要所有依赖关系列表。这是一个很好的做法,可以让他选择如何构建您的项目;-)

Since imgui is PUBLICly linked against glfw, glad, OpenGL::GL, imm32, does it mean that implot and whoever that uses implot will also be PUBLICly linked against glfw, glad, OpenGL::GL, imm32?

Yes, it is. More details could be found in the official documentation in the section Build Specification and Usage Requirements.

Is the reason behind this because of imgui being a shared library?

Yes, it is. Since add_library() does not have any SHARED or STATIC 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 ;-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文