cmake与静态库的链接-您是否必须告诉cmake在哪里看? [英] cmake linking against static libraries - do you have to tell cmake where to look?

查看:210
本文介绍了cmake与静态库的链接-您是否必须告诉cmake在哪里看?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Linux机器上安装了c ++库 pcapplusplus ,并且已将 .a 文件放入其中 / usr / local / lib 。我现在正在尝试使用 target_link_libraries($ {PROJECT_NAME} libCommon ++。a libPacket ++。a libPcap ++。a)在cmake中将我的项目与其链接。但是,它找不到 PackPack.h ,它是 libPacket ++。a 的一部分。我在这里做错了什么?我是否必须告诉cmake在哪里看?

I've installed the c++ library pcapplusplus on my linux machine and the .a files have been put in /usr/local/lib. I am now trying to link my project with it in cmake using target_link_libraries(${PROJECT_NAME} libCommon++.a libPacket++.a libPcap++.a). However, it can't find Packet.h which is part of libPacket++.a. What am I doing wrong here? Do I have to tell cmake where to look?

cmake_minimum_required(VERSION 2.8.9)
project(networksniffer)
# The version number.
set (networksniffer_VERSION_MAJOR 1)
set (networksniffer_VERSION_MINOR 0)

set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/build)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(PROJECT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src)

# The following folder will be included
include_directories("/usr/local/include/pcapplusplus")

#add_executable(networksniffer ${SOURCES})
add_executable(networksniffer ${PROJECT_SOURCE_DIR}/networksniffer.cpp)

target_link_libraries(${PROJECT_NAME} libCommon++.a libPacket++.a libPcap++.a)


推荐答案

Packet.h 不是 libPacket ++。a 的一部分。

libPacket ++。a 是一个库, Packet.h 是一个头文件。

libPacket++.a is a library, Packet.h is a header file.

CMake不能知道两者是否相互关联,除非您这样说。

CMake can't know that both relate to each other unless you tell it so.

我建议使用 find_package 以正确定位这两个地址( https://cmake.org/ cmake / help / v3.0 / command / find_package.html )。

I suggest using find_package to properly locate both (https://cmake.org/cmake/help/v3.0/command/find_package.html).

使用 target_include_directories 然后包括头文件的路径。

Use target_include_directories then to include the path to the header file.

这篇关于cmake与静态库的链接-您是否必须告诉cmake在哪里看?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆