0

After multiple hours of researching the internet for an solution (I know there are somewhat similar questions but none were helping) I am close to throwing in the towel, so help is highly appreciated.

Preliminary: I want to use the C99 library open62541 for my own C++ project. I used the adequate build options for PubSub, since this is what I'm mostly interested in. I also configured the install path to /home/user/install/open62541.

Problem description: At first I was able to build everything as expected with this CMakeLists.txt. But at the moment I try to add the subscription capabilities of open62541 into the project but CMake is refusing to link the library into the project as it is supposed to:

  • I copied this example code from the tutorials to the project and added add_executable(subscriber ${CMAKE_CURRENT_SOURCE_DIR}/tutorial_pubsub_subscribe.cpp) and target_link_libraries(subscriber PUBLIC open62541) to my CMakeLists.txt.
  • CMake complains about the following: undefined reference to 'UA_PubSubConnection_regist'
  • I then went to the lib folder of my install path to find the libopen62541.so and
  • inspected the shared object with the nm command nm libopen62541.so | grep UA_PubSubConnection_regist
  • nm returned "t",

so i suppose the build of open62541 cannot be the reason for the linking error.

  • I don't understand why find_library isn't all you need? That function sets an output variable, whose name use you with target_link_libraries for your executable. – James K. Lowden Dec 11 '20 at 00:20
  • I tried find_library(open62541) in multiple variations but unfortunately non seemed to help. – marcomarmelade Dec 11 '20 at 00:34
  • If you know the exact path to your library, then just pass this pass to target_link_libraries, like `target_link_libraries(subscriber PUBLIC /home/user/install/open62541/lib/libopen62541.so)`. If this doesn't resolve "undefined reference" error, then the problem is not in `CMakeLists.txt`. – Tsyvarev Dec 11 '20 at 08:24
  • Instead of specifying the full path in `target_link_libraries` I'd instead specify an imported target, since this allows you to attach include directories ect. too and could be a way of specifying different lib files for different configurations.`add_library(open62541 SHARED IMPORTED) set_target_properties(open62541 PROPERTIES IMPORTED_LOCATION /home/user/install/open62541/lib/libopen62541.so) target_include_directories(open62541 INTERFACE /home/user/install/open62541/include)` or similar.First check, if the installation includes a cmake config file though since this would already contain this – fabian Dec 11 '20 at 16:28
  • I will check your suggestions and give an update when i find a solution. thank you a lot. – marcomarmelade Dec 11 '20 at 17:48
  • So I manged to get the a basic server client connection running. As you suggested the issue was not in the CMakeLists.txt but with the build of open62541. I had to first downgrade my cmake to 3.12. Only then I was getting helpful debug messages leading me to building the lib without using the encryption option. because when I build the library with encryption enabled, I get and linking error to my systems mbedtls. So for now I think its fine to work without encryption but this might be an issue to solve for me in the near future. Thank you guys for helping me finding a solution, cheers marco. – marcomarmelade Dec 13 '20 at 13:33

0 Answers0