Link module with an external library #976
-
Hello, I'm trying to link a module with an external library /usr/bin/ld : XComponentImpl.cpp:(.text+0x209) : undefined reference to " functionX(x, y) " In order to make my module link properly I tried several methods. First I added I searched the fprime directory and found the options below but I still get the error. set(INPUT_DEPS
./libs/libfoo.a
)
set(LINK_DEPS
-lfoo
) I tried these different techniques in the CMakeList of my module and in the CMakeList at the root of the project. I already tried what @LeStarch says in this thread but it doesn't work for me. Has anyone ever succeeded in linking a module depending on an external library? -Ugo |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 11 replies
-
I found a project using F' that integrates a static library for one of its components : FS @lewisjaggi. The component that uses libpng (here) is the PiCamera and here is the cmakefile of its component where it specifies the dependency on libpng: include_directories(../lib/include)
include_directories(../lib/include/libpng16)
find_library(RASPICAM raspicam /usr/local/lib)
find_library(PNG png ../lib/lib)
target_link_libraries(App_PiCamera ${RASPICAM} ${PNG}) I don't know if it worked in his case, I guess it did, but you can see if it helps? Maybe you can follow up if you try to implement it. |
Beta Was this translation helpful? Give feedback.
-
If you tried to link an external C library, make sure you have the Then in the # Retrieve the name of the module that converts the root path of your project to a underscore, i.e. Fw/Types becomes Fw_Types.
get_module_name("${CMAKE_CURRENT_LIST_DIR}")
# Tell the compiler the path to the library header file.
include_directories("${PROJECT_SOURCE_DIR}/libs")
# Find all the libraries contained in the directory you specified.
find_library(LIBQUATERNION Quaternion "${PROJECT_SOURCE_DIR}/libs")
# Note: in my case the LIBQUATERNION equals /home/ThibFrgsGmz/Documents/CODES/fprime-poc/libs/libQuaternion.a
# Specify to the linker the libraries to use when linking the given component and its dependents.
target_link_libraries("${MODULE_NAME}" ${LIBQUATERNION}) If I remove the Hopefully this solves your problem. |
Beta Was this translation helpful? Give feedback.
If you tried to link an external C library, make sure you have the
external "c"
tag so that the C++ compiler does not add extra manipulation information to the function name symbols.Then in the
CMakeLists.txt
of the component in which you want to use the external library you must add the following lines. In my case I try to link a quaternion calculation library (named libQuaternion.a).