首页 > 解决方案 > 如何使用文件夹路径和cmake“链接所有”动态和/或静态库?

问题描述

在我的测试项目中,我的文件夹结构如下

-Root/
 -Lib_so/   //folder where it contains all of the .so file
 -Lib_a/    //folder where it contains all of the .a file
 -Lib_dll/  //folder where it contains all of the dll file
 -Includes/ //folder where it contains all of the header files
 -main.cpp

我想编写一个生成单个可执行文件的 CMakeLists.txt:

  1. 仅通过上面显示的文件夹路径自动链接所有 .so 、 .a 和/或 dll 文件。
  2. 链接已安装的二进制文件(例如 mac 上 brew 安装的 GLFW)

我试过以下

cmake_minimum_required(VERSION 3.0)
project(FirstOpenGL)
set(SOURCE main.cpp)
add_executable(myapp ${SOURCE})

#Below Im trying to link ALL of the libs under the "project's local path"
include_directories(${CMAKE_SOURCE_DIR}/Includes)
link_directories(LinkPathSo  ${CMAKE_SOURCE_DIR}/Lib_so)
link_directories(LinkPathA   ${CMAKE_SOURCE_DIR}/Lib_a)
link_directories(LinkPathDll ${CMAKE_SOURCE_DIR}/Lib_dll)

target_link_libraries(myapp LinkPathSo)
target_link_libraries(myapp LinkPathA)  
target_link_libraries(myapp LinkPathDll)  


# Below: Im trying to link the installed binaries on mac
find_package(glfw3 3.2 REQUIRED)
find_package(OpenGL REQUIRED)

target_include_directories(myapp ${OPENGL_INCLUDE_DIR})
target_link_libraries(myapp ${OPENGL_gl_LIBRARY})
target_link_libraries(myapp ${OPENGL_glu_LIBRARY})

谢谢大家

标签: c++macosbuildcmakedevops

解决方案


推荐阅读