c++ C Makelist的G++参数

esyap4oy  于 2023-08-09  发布在  其他
关注(0)|答案(1)|浏览(127)

我正在尝试使用cmake构建我的项目。第三方头文件和库。头文件在/usr/local/include/中,库文件在/usr/local/lib/中。我认为编译器找到了这些文件,因为我在包含的内容上没有错误,但是当我试图编译它时,它没有找到我正在调用的函数。

/mnt/c/Users/Max/CLionProjects/Lightning_Controller/main.cpp:12: undefined reference to `ola::InitLogging(ola::log_level, ola::log_output)'
/usr/bin/ld: /mnt/c/Users/Max/CLionProjects/Lightning_Controller/main.cpp:13: undefined reference to `ola::DmxBuffer::DmxBuffer()'
/usr/bin/ld: /mnt/c/Users/Max/CLionProjects/Lightning_Controller/main.cpp:14: undefined reference to `ola::DmxBuffer::Blackout()'
/usr/bin/ld: /mnt/c/Users/Max/CLionProjects/Lightning_Controller/main.cpp:17: undefined reference to `ola::client::StreamingClient::StreamingClient(ola::client::StreamingClient::Options const&)'
/usr/bin/ld: /mnt/c/Users/Max/CLionProjects/Lightning_Controller/main.cpp:19: undefined reference to `ola::client::StreamingClient::Setup()'
/usr/bin/ld: /mnt/c/Users/Max/CLionProjects/Lightning_Controller/main.cpp:26: undefined reference to `ola::DmxBuffer::SetChannel(unsigned int, unsigned char)'
/usr/bin/ld: /mnt/c/Users/Max/CLionProjects/Lightning_Controller/main.cpp:27: undefined reference to `ola::client::StreamingClient::SendDmx(unsigned int, ola::DmxBuffer const&)'
/usr/bin/ld: /mnt/c/Users/Max/CLionProjects/Lightning_Controller/main.cpp:34: undefined reference to `ola::client::StreamingClient::~StreamingClient()'
/usr/bin/ld: /mnt/c/Users/Max/CLionProjects/Lightning_Controller/main.cpp:34: undefined reference to `ola::DmxBuffer::~DmxBuffer()'
/usr/bin/ld: /mnt/c/Users/Max/CLionProjects/Lightning_Controller/main.cpp:34: undefined reference to `ola::client::StreamingClient::~StreamingClient()'
/usr/bin/ld: /mnt/c/Users/Max/CLionProjects/Lightning_Controller/main.cpp:34: undefined reference to `ola::DmxBuffer::~DmxBuffer()'
collect2: error: ld returned 1 exit status

字符串
如果我用G和这个参数g++ main.cpp -lola -lolacommon -lprotobuf编译它,它就能工作。
我尝试使用这个Post中提到的选项,但它没有改变任何东西。
我的问题是如何将它从g
转换为cmake?

xqkwcwgp

xqkwcwgp1#

这将是很好的有更多的信息,你在做什么,但这是我为你。
编译器找不到您所调用的函数的实现。它会找到头文件,但不会将库与实际的实现链接起来。使用CMake,指定要链接的库。
我不知道你用的是什么版本的C++,所以相应地修改一下。

cmake_minimum_required(VERSION 3.10)
project(Lightning_Controller)

set(CMAKE_CXX_STANDARD 14)

include_directories(/usr/local/include/)

add_executable(Lightning_Controller main.cpp)

link_directories(/usr/local/lib/)

target_link_libraries(Lightning_Controller ola olacommon protobuf)

字符串

相关问题