CMake - 报错:Missing variable is: CMAKE_FIND_LIBRARY_PREFIXES

问题描述:

今天学习ZeroMQ, 写了一个HelloWorld的测试程序,cmake的时候,报错Missing variable is: CMAKE_FIND_LIBRARY_PREFIXES

具体CMakeLists.txt内容为:

cmake_minimum_required(VERSION 3.10)

find_package(PkgConfig REQUIRED)
pkg_check_modules(ZMQ libzmq)
link_directories(${ZMQ_LIBRARY_DIRS})
include_directories(${ZMQ_INCLUDE_DIRS})

# set the project name
project(HelloWorld)

# add the executable
add_executable(hello_world_client hello_world_client.cpp)
target_link_libraries(hello_world_client ${ZMQ_LIBRARIES})

add_executable(hello_world_server hello_world_server.cpp)
target_link_libraries(hello_world_server ${ZMQ_LIBRARIES})

报错信息:

-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29") 
-- Checking for module 'libzmq'
--   Found libzmq, version 4.3.1
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_FIND_LIBRARY_PREFIXES
CMake Error: Error required internal CMake variable not set, cmake may not be built correctly.
Missing variable is:
CMAKE_FIND_LIBRARY_SUFFIXES
-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring incomplete, errors occurred!
See also "/home/lammork/Desktop/zeromq_demo/build/CMakeFiles/CMakeOutput.log".

问题根因:

findpackage() 应该在 project()之后

问题解决:

修改CMakeLists.txt

cmake_minimum_required(VERSION 3.10)

# set the project name
project(HelloWorld)

find_package(PkgConfig REQUIRED)
pkg_check_modules(ZMQ libzmq)
link_directories(${ZMQ_LIBRARY_DIRS})
include_directories(${ZMQ_INCLUDE_DIRS})

# add the executable
add_executable(hello_world_client hello_world_client.cpp)
target_link_libraries(hello_world_client ${ZMQ_LIBRARIES})

add_executable(hello_world_server hello_world_server.cpp)
target_link_libraries(hello_world_server ${ZMQ_LIBRARIES})

你可能感兴趣的:(笔记,linux,cmake,zeromq)