gpt4 book ai didi

C++ CMake 编译错误 (/usr/bin/ld : cannot find )

转载 作者:行者123 更新时间:2023-11-30 05:30:05 25 4
gpt4 key购买 nike

*我知道有很多关于此的问题,但在谈论 CMake 时它们根本没有多大帮助,因此我决定提出这个问题 *

所以我在 CLion 上工作,它使用 CMake 来导入编译器并为编译器提供参数,并成功包含(导入)位于名为“ExternalLibraries”的文件夹中的外部库( Cereal :将类序列化为 json 文件)它位于我的项目文件夹的根目录中。它工作得很好,直到我重新启动 IDE 并尝试再次运行代码......它返回了一个编译错误(我认为)。

我的 CMake 文件如下所示:

cmake_minimum_required(VERSION 3.3)
project(xMemory)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

include_directories ("${PROJECT_SOURCE_DIR}/ExternalLibraries/cereal-1.1.2/include/")

set(SOURCE_FILES main.cpp xObject.cpp xObject.h)
add_executable(xMemory ${SOURCE_FILES})
target_link_libraries (xMemory cereal)

当我尝试运行/编译 shell 时,它给了我这个:

/home/lunaticsoul/Documents/clion-1.2.4/bin/cmake/bin/cmake --build /home/lunaticsoul/.CLion12/system/cmake/generated/95701c38/95701c38/Debug0 --target xMemory -- -j 4
Scanning dependencies of target xMemory
[ 33%] Building CXX object CMakeFiles/xMemory.dir/xObject.cpp.o
[ 66%] Building CXX object CMakeFiles/xMemory.dir/main.cpp.o
[100%] Linking CXX executable xMemory
/usr/bin/ld: cannot find -lcereal
collect2: error: ld returned 1 exit status
make[3]: *** [xMemory] Error 1
make[2]: *** [CMakeFiles/xMemory.dir/all] Error 2
make[1]: *** [CMakeFiles/xMemory.dir/rule] Error 2
make: *** [xMemory] Error 2

我不确定发生了什么,因为库似乎实际上导入了代码(包括麦片时没有红色字母),正如我之前所说,我认为它只是停止工作了。

有人可以告诉我我的 CMake 文件是否有问题吗?

PD:这是一个屏幕截图,以防万一有人需要它。

PD2:我正在使用基本操作系统:Freya (Ubuntu 14.04)

enter image description here

最佳答案

你应该使用

link_directories(directory1 directory2 ...)

指定库目录的指令。

https://cmake.org/cmake/help/v3.0/command/link_directories.html

关于C++ CMake 编译错误 (/usr/bin/ld : cannot find <LIBRARY_NAME>),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36152619/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com