gpt4 book ai didi

c++ - 将已编译的库和包含文件添加到 CMake 项目?

转载 作者:可可西里 更新时间:2023-11-01 15:03:59 36 4
gpt4 key购买 nike

将预建库包含到 cmake 项目中的最佳方法是什么?我想将 FreeType 包含到我正在处理的项目中,文件结构如下:

  • Build
    • MacOS
      • Make/
      • XCode/
    • Windows
      • VisualStudio/
  • Source
    • libs
      • MacOS
        • libfreetype
      • Windows
        • freetype.dll
    • includes
      • freetype/ (Various header files that are included automatically by ftbuild.h)
      • ftbuild.h (this is what is included in code from my understanding.)
    • MyProject
      • main.cpp
      • foo.cpp
      • foo.h

库已经编译。 MyProject 是当前项目的名称。

谢谢!迈克

最佳答案

只需将 target_link_libraries 与预构建库的完整路径一起使用。

所以,像这样:

# In the file Source/MyProject/CMakeLists.txt
add_executable(my_exe main.cpp foo.cpp foo.h)
if(WIN32)
target_link_libraries(my_exe ${CMAKE_CURRENT_SOURCE_DIR}/../libs/Windows/freetype.lib)
endif()
if(APPLE)
target_link_libraries(my_exe ${CMAKE_CURRENT_SOURCE_DIR}/../libs/MacOS/libfreetype.a)
endif()

关于c++ - 将已编译的库和包含文件添加到 CMake 项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2601798/

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