在linux

时间:2018-03-03 20:33:45

标签: cmake linker static-libraries

我正在尝试使用CMake的find_package()命令链接库(SFML)。如果我将SFML的库直接放入/ usr / local / lib文件夹,一切正常,但是一旦我创建了一个子文件夹(出于组织目的),我就会收到以下错误:

CMake Error at cmake_modules/FindSFML.cmake:355 (message):
  Could NOT find SFML (missing: SFML_GRAPHICS_LIBRARY SFML_WINDOW_LIBRARY
  SFML_SYSTEM_LIBRARY)
Call Stack (most recent call first):
CMakeLists.txt:11 (find_package)

然后我尝试搜索指定新目录(顺便说一下,只是/ usr / local / lib / SFML)到find_package()函数的方法,但我发现的任何东西似乎都没有用。

的CMakeLists.txt

# initialize project
cmake_minimum_required(VERSION 3.10.0)
project(Proj)

# compiler flags
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# load packages
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules)
find_package(SFML REQUIRED COMPONENTS graphics window system)

# headers directories
include_directories(${SFML_INCLUDE_DIR})

# project directories
include_directories(headers)

# project sources
file(GLOB SRC src/*.cpp)

# create exectuables
add_executable(Proj ${SRC}) 

# link libraries
target_link_libraries(Proj ${SFML_LIBRARIES} ${SFML_DPENDENCIES})

1 个答案:

答案 0 :(得分:2)

在&#34之外;发现"脚本,CMake不支持指定其他库的子目录。但您可以通过CMAKE_LIBRARY_PATH变量指定确切的库目录:

set(CMAKE_LIBRARY_PATH "/usr/local/lib/SFML")
find_package(SFML ...)

实际上,变量CMAKE_LIBRARY_PATH会影响find_library次来电,但大多数"查找"脚本使用此命令搜索库。