cmake - 使用 CMake 和 PkgConfig 链接库

标签 cmake glfw pkg-config

我正在尝试将静态库 (GLFW) 链接到我正在构建的自己的库。为了做到这一点,我在 CMakeLists.txt 文件中有以下内容:

pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})
target_link_libraries(${LIBRARY_NAME} ${GLFW_STATIC_LIBRARIES})

链接我的库时,出现以下错误:ld: library not found for -lglfw3
然而,正在运行 pkg-config --libs glfw3在控制台中给出:
-L/usr/local/lib -lglfw3 

所以我知道安装了GLFW库。当我尝试使用 CMake 进行链接时,为什么没有找到该库?

最佳答案

使用参数 -lglfw3 时我遇到了同样的错误,经过多次反复试验,我发现我需要使用 -lglfw.3

关于cmake - 使用 CMake 和 PkgConfig 链接库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21030186/

相关文章:

c++ - 未定义的引用链接 yaml-cpp 程序与 mingw-w64 + cmake

Android CMake 使用预构建 .a 库

无法将 BLAS 库与 Clion 2016.1.2 和 Fedora 22 链接,获取 undefined reference

c++ - 非方形屏幕上的 OpenGL 绘图线

c++ - 如何将 OpenSSL 包含在 Linux 上的 Qt 程序中?

ffmpeg - 使用 x265 编译 FFMPEG 出现错误 : x265 not found using pkg-config

fuse - pkg-config --exists fuse 失败

linux - CMake:找不到没有绝对路径的库

macos - mac os 雪豹上的 freeglut 问题(通过 macports 构建良好)

使用无效参数调用 cmake target_include_directories