eProsima / Fast-DDS-docs

Documentation of Fast RTPS (MarkDown Files). Looking for commercial support? Contact info@eprosima.com
Apache License 2.0
83 stars 45 forks source link

Building Fast-DDS with eProsima/Foonathan cause a link error [13853] #338

Closed Nir-Az closed 2 years ago

Nir-Az commented 2 years ago

Hi,

I am trying to integrate FastDDS with it's dependencies on my CMake project and I get some linkage errors.

I tried diving in and I see for start that the foonathan instructions have some issues: according to the docs:

cmake -DCMAKE_INSTALL_PREFIX=%USERPROFILE%/Fast-DDS/install ^
   -DBUILD_SHARED_LIBS=OFF -DFOONATHAN_MEMORY_BUILD_TOOLS=ON ^
   -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DFOONATHAN_MEMORY_BUILD_TESTS=OFF ..

While looking on https://github.com/eProsima/foonathan_memory_vendor I see this issues: Option FOONATHAN_MEMORY_BUILD_TOOLS does not exist and should be BUILD_MEMORY_TOOLS Option FOONATHAN_MEMORY_BUILD_TESTS does not exist and should be BUILD_MEMORY_TESTS

CMAKE_POSITION_INDEPENDENT_CODE does not exist and is set automatically when BUILD_SHARED_LIBS=ON No option exist for it. The comment say

if(BUILD_SHARED_LIBS)
    # Library will be statically created with PIC code

If the user chose shared lib it will be statically created? https://github.com/eProsima/foonathan_memory_vendor/blob/da062db05975d24a4b53de5a4122b47f6824997f/CMakeLists.txt#L30

The issues I get on my build is :

/usr/bin/ld: ../../fastdds/fastdds_install/lib/libfastrtps.a(IPLocator.cpp.o): relocation R_X86_64_TPOFF32 against symbol `_ZN4asio6detail15keyword_tss_ptrINS0_10call_stackINS0_14thread_contextENS0_16thread_info_baseEE7contextEE6value_E' can not be used when making a shared object; recompile with -fPIC

Is that familiar? Any help on overcoming it? My CMake source code is here:

https://github.com/Nir-Az/librealsense/blob/link_fastcdr/CMake/external_fastdds.cmake

Thanks

EduPonz commented 2 years ago

Hi @Nir-Az ,

Thanks for the report! I've issued eProsima/foonathan_memory_vendor#55 to propagate CMake flags from the vendor to foonathan/memory properly. I've also issued #339 to patch the documentation. It'd be great if you could test using the branch from the vendor and the new instructions and tell me whether these changes fix your issue.

Nir-Az commented 2 years ago

Sure, thanks I will try, 1 more thing about the docs that is confusing is that on foonathan section you link to the original repo and the code example clones your repo (which is different) with no explanation

  *`Foonathan memory <https://github.com/foonathan/memory>`_*
     .. code-block:: bash
         cd %USERPROFILE%\Fast-DDS
         git clone https://github.com/eProsima/foonathan_memory_vendor.git
EduPonz commented 2 years ago

Hi Nir,

You're right! I've added a small explanation about it in 290b2c. Furthermore, I've removed the CMake options passed there, as I think there are not needed anymore. If BUILD_SHARED_LIBS is not specified, then foonathan memory will be linked statically, and as far as I can tell we won't need the position independent code. Please do let me know.

Nir-Az commented 2 years ago

Currently I got some serious issues with integrating FastDDS on my CMake project so I am not sure this is the only issue I have. STATIC_CRT is also not handled properly and it seems like FastDDS is not built to be added as an ExternalProject_Add API, so I think of moving to FetchContent API. I am on it so I will let you know once I get it working..

EduPonz commented 2 years ago

Hi @Nir-Az ,

STATIC_CRT is also not handled properly and it seems like FastDDS is not built to be added as an ExternalProject_Add API,

I'm not sure about what STATIC_CRT is, so I'm assuming that what you mean is that you want to link statically with the CRT. Here you can take a look at a project that does exactly that (see here and here). That mechanism leverages CMake's 3.15 MSVC_RUNTIME_LIBRARY in combination with CMP0091.

In any case, as far as I understand, newer versions for VS (since 2017) solve this problem by linking with the universal run-time, so I guess that upgrading may solve the need of static linking with the CRT (unless you need it for any other reason).

Maybe it'd be advisable to open a thread in Fast DDS Q&A to get some tracking there for future reference.

Nir-Az commented 2 years ago

It took me some time to get to know the CMP0091 thing.. (See discussion 2461 ) 13 days ago with no response.. somehow the discussions are not receiving too much attention..

As a utility package, I suggest you make the users an easy life and consider adding a BUILD_WITH_STATIC_CRT CMake flag and let the user pass this obstacle with 1 click :)

And if we are discussing it, the major issue of integrating FastDDS easily using CMake is this: 2428 and 2418

Thanks for the pointing 👍