Issue
I am trying to build my Project using cmake. With 3rd Party headerfiles and libarys. The headers are in /usr/local/include/
and the libary in /usr/local/lib/
. And I think the compiler finds the files because I get no error on the includes but when I try to compile it it doesn´t find the functions I´m calling.
/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
If I compile it with G++ and this parameters g++ main.cpp -lola -lolacommon -lprotobuf
it works.
I tried to use the Option Mentioned in this Post but it didn´t change anything.
My Question is how do i translate this from g++ to cmake ?
Solution
It would be nice to have more information about what you are doing, but this is what I have for you.
The compiler can't find the implementation for the functions you're calling. It finds the headers, but it doesn't link the library with the actual implementations. With CMake
, specify the libraries to link.
I don't know what version of C++ you are on, so change it accordingly.
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)
Answered By - Ben A. Answer Checked By - Clifford M. (WPSolving Volunteer)