运行'make'时,CMake无法找到-'libraryname'

时间:2018-01-22 15:20:27

标签: cmake

我正在学习CMake,我遇到了问题。 我有一个名为'libLibraryName'的库(我之前用CMake创建过)(我知道,不是最好的名字)。这个库只包含一个打印消息的函数,它是通过组合两个文件形成的(1个头文件与函数原型和一个.cpp及其实现)。

现在我将该函数放在一个文件夹中,我正在尝试使用.cpp文件来使用这个库。这是我的文件夹的结构(正如您可以看到库位于... / Library文件夹中)。

.
├── build
├── CMakeLists.txt
├── include
│   └── header.h
├── Library
│   └── libLibraryName.so
├── main.cpp
└── src
    └── header.cpp

我写了这篇CMakeLists:

cmake_minimum_required(VERSION 3.5.1)

# Project name
project(Project_Name)

# Include the existing library's name and then link it's path
# Make sure to provide a valid library name
set( PROJECT_LINK_LIBS libLibraryName.so )
link_directories(/home/uidr0938/CMake_Exercises/Library)

# Add path of the header files
include_directories(include)

# Create an executable with your main application's code
add_executable(Application main.cpp)

# And link the library to that application
target_link_libraries(Application ${PROJECT_LINK_LIBS})

然后我进入构建并运行'cmake ..'。这很有效。但是当我写'make'时,我得到以下错误:

/usr/bin/ld: cannot find -lLibraryName
collect2: error: ld returned 1 exit status
CMakeFiles/Application.dir/build.make:94: recipe for target 'Application' failed
make[2]: *** [Application] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/Application.dir/all' failed
make[1]: *** [CMakeFiles/Application.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

如果程序正在寻找不同路径的库,而不是我使用link_directories命令提供的路径。

请帮我解决这个问题,以便我可以将该库与我的主要功能一起使用。 谢谢。

我在这个例子中使用了虚拟linux机器。

0 个答案:

没有答案
相关问题