eclipse-cyclonedds / cyclonedds

Eclipse Cyclone DDS project
https://projects.eclipse.org/projects/iot.cyclonedds
Other
889 stars 363 forks source link

Undefined reference to MODULE_TOPIC_desc when building with C++ in CycloneDDS 0.10.5 #2087

Closed failys closed 2 months ago

failys commented 2 months ago

I'm currently using the CycloneDDS C API in a C++ project. However, I seem to get link errors due undefined references to MODULE_TOPIC_desc.

This can be reproduced quite easily in the helloworld example by: (1) renaming publisher.c and subscriber.c to publisher.cpp and subscriber.cpp respectively, (2) changing LANGUAGES at the top of CMakeLists.txt from C to CXX, (3) renaming publisher.c and subscriber.c in CMakeLists.txt to publisher.cpp and subscriber.cpp

When building this example with CMake, you should get an error similar to the below: /usr/bin/ld: CMakeFiles/HelloworldPublisher.dir/publisher.cpp.o: in function 'main': publisher.cpp:(.text+0x96): undefined reference to 'HelloWorldData_Msg_desc' collect2: error: ld returned 1 exit status

Perhaps this is a feature rather than a bug. If it is, any thoughts about how I might use CycloneDDS in a C++ project without building/using the C++ bindings would be helpful.

failys commented 2 months ago

I think I've managed to resolve this problem myself, through a combination of fixing the languages in the CMake file and adding -l cxx to idlc.