依赖编译Foonathan memory
$ cmake ..
$ cmake --build . --target install
编译生成的是,静态链接库。并且编译之后生成的相关文件存储在build文件夹下的install文件夹内。
如果安装这种情况,编译Fast-RTPS,将会出现找不到Foonathan memory的库文件。
--- stderr: fastrtps
CMake Error at CMakeLists.txt:215 (find_package):
By not providing "Findfoonathan_memory.cmake" in CMAKE_MODULE_PATH this
project has asked CMake to find a package configuration file provided by
"foonathan_memory", but CMake did not find one.
Could not find a package configuration file provided by "foonathan_memory"
with any of the following names:
foonathan_memoryConfig.cmake
foonathan_memory-config.cmake
Add the installation prefix of "foonathan_memory" to CMAKE_PREFIX_PATH or
set "foonathan_memory_DIR" to a directory containing one of the above
files. If "foonathan_memory" provides a separate development package or
SDK, be sure it has been installed.
make: *** [cmake_check_build_system] Error 1
---
question ONE
.....
[ 97%] Building C object src/cpp/CMakeFiles/fastrtps.dir/rtps/persistence/sqlite3.c.o
[ 97%] Building CXX object src/cpp/CMakeFiles/fastrtps.dir/utils/TimedConditionVariable.cpp.o
[ 98%] Building CXX object src/cpp/CMakeFiles/fastrtps.dir/transport/TCPChannelResourceSecure.cpp.o
[ 99%] Building CXX object src/cpp/CMakeFiles/fastrtps.dir/transport/TCPAcceptorSecure.cpp.o
[100%] Linking CXX shared library libfastrtps.so
/usr/bin/ld: /usr/local/lib/libfoonathan_memory-0.6.1.a(free_list.cpp.o): relocation R_X86_64_PC32 against symbol `_ZN9foonathan6memory6detail13list_get_nextEPv' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
src/cpp/CMakeFiles/fastrtps.dir/build.make:3557: recipe for target 'src/cpp/libfastrtps.so.1.9.0' failed
make[2]: *** [src/cpp/libfastrtps.so.1.9.0] Error 1
CMakeFiles/Makefile2:981: recipe for target 'src/cpp/CMakeFiles/fastrtps.dir/all' failed
make[1]: *** [src/cpp/CMakeFiles/fastrtps.dir/all] Error 2
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2
此处的错误,经过必应搜索,是编译生成的动态库用到了已经生成的静态库文件,这种用法是错误的。我们应该将libfoonathan_memory-0.6.1.a静态库 更换为 相应的动态库文件。
解决方案
在编译Foonathan memory时:
利用
$ cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=ON ..
取代
$ cmake ..
-DCMAKE_INSTALL_PREFIX=/usr/local
指明的是安装路径