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})
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值