ethz-asl/lpp

Compiling error in MODE_DEFAULT

Closed this issue · 3 comments

rikba commented

The following minimum example does not work for me:

In CMakeLists.txt

add_executable(my_executable src/my_executable.cc)
target_link_libraries(my_executable ${catkin_LIBRARIES})
target_compile_definitions(my_executable PRIVATE MODE_DEFAULT)

The code:

#include <log++.h>
#include <omav_hovery_interface/omav_base_client.h>

int main(int argc, char** argv) {
  omV::OMAVBaseClient<_PWM> motor_client;
}

The error warning is:

/usr/bin/ld: CMakeFiles/thrust_test.dir/src/thrust_test.cc.o: in function `omV::ll::PollingThread::stop()':
thrust_test.cc:(.text._ZN3omV2ll13PollingThread4stopEv[_ZN3omV2ll13PollingThread4stopEv]+0xba): undefined reference to `google::LogMessage::LogMessage(char const*, int)'
/usr/bin/ld: thrust_test.cc:(.text._ZN3omV2ll13PollingThread4stopEv[_ZN3omV2ll13PollingThread4stopEv]+0xc6): undefined reference to `google::LogMessage::stream()'
/usr/bin/ld: thrust_test.cc:(.text._ZN3omV2ll13PollingThread4stopEv[_ZN3omV2ll13PollingThread4stopEv]+0x106): undefined reference to `google::LogMessage::~LogMessage()'
/usr/bin/ld: thrust_test.cc:(.text._ZN3omV2ll13PollingThread4stopEv[_ZN3omV2ll13PollingThread4stopEv]+0x11b): undefined reference to `google::LogMessage::~LogMessage()'
/usr/bin/ld: CMakeFiles/thrust_test.dir/src/thrust_test.cc.o: in function `omV::OMAVBaseClient<(omV::ll::MotorType)0>::task()':
thrust_test.cc:(.text._ZN3omV14OMAVBaseClientIJLNS_2ll9MotorTypeE0EEE4taskEv[_ZN3omV14OMAVBaseClientIJLNS_2ll9MotorTypeE0EEE4taskEv]+0x1c8): undefined reference to `google::LogMessage::LogMessage(char const*, int, int)'
/usr/bin/ld: thrust_test.cc:(.text._ZN3omV14OMAVBaseClientIJLNS_2ll9MotorTypeE0EEE4taskEv[_ZN3omV14OMAVBaseClientIJLNS_2ll9MotorTypeE0EEE4taskEv]+0x1d7): undefined reference to `google::LogMessage::stream()'
/usr/bin/ld: thrust_test.cc:(.text._ZN3omV14OMAVBaseClientIJLNS_2ll9MotorTypeE0EEE4taskEv[_ZN3omV14OMAVBaseClientIJLNS_2ll9MotorTypeE0EEE4taskEv]+0x1f5): undefined reference to `google::LogMessage::~LogMessage()'
/usr/bin/ld: thrust_test.cc:(.text._ZN3omV14OMAVBaseClientIJLNS_2ll9MotorTypeE0EEE4taskEv[_ZN3omV14OMAVBaseClientIJLNS_2ll9MotorTypeE0EEE4taskEv]+0x25e): undefined reference to `google::LogMessage::LogMessage(char const*, int, int)'
/usr/bin/ld: thrust_test.cc:(.text._ZN3omV14OMAVBaseClientIJLNS_2ll9MotorTypeE0EEE4taskEv[_ZN3omV14OMAVBaseClientIJLNS_2ll9MotorTypeE0EEE4taskEv]+0x26d): undefined reference to `google::LogMessage::stream()'
/usr/bin/ld: thrust_test.cc:(.text._ZN3omV14OMAVBaseClientIJLNS_2ll9MotorTypeE0EEE4taskEv[_ZN3omV14OMAVBaseClientIJLNS_2ll9MotorTypeE0EEE4taskEv]+0x28b): undefined reference to `google::LogMessage::~LogMessage()'
/usr/bin/ld: thrust_test.cc:(.text._ZN3omV14OMAVBaseClientIJLNS_2ll9MotorTypeE0EEE4taskEv[_ZN3omV14OMAVBaseClientIJLNS_2ll9MotorTypeE0EEE4taskEv]+0x4b8): undefined reference to `google::LogMessage::~LogMessage()'
/usr/bin/ld: thrust_test.cc:(.text._ZN3omV14OMAVBaseClientIJLNS_2ll9MotorTypeE0EEE4taskEv[_ZN3omV14OMAVBaseClientIJLNS_2ll9MotorTypeE0EEE4taskEv]+0x4d0): undefined reference to `google::LogMessage::~LogMessage()'
collect2: error: ld returned 1 exit status

I guess the problem is similar to https://github.com/ethz-asl/lpp/pulls?q=is%3Apr+is%3Aclosed

The code runs for example in MODE_ROSLOG

4c3y commented

Do you link glog against your executable? MODE_DEFAULT requires both glog and rosconsole, otherwise linker errors are generated.

rikba commented

I see. I only linked it against roscpp. So by default including LPP requires target_link_libraries(my_project glog rosconsole). Is this correct?

4c3y commented

Yes, because in MODE_DEFAULT the rosconsole/glog logging functions are not redefined by lpp