[orocosusers] CMAKE, libraries, linking problem

?I have two packages, A & B.

A is a catkin package with the following structure:

??? CMakeLists.txt

??? include

? ??? A

? ??? C1.hpp

? ??? C2.hpp

? ??? C3.hpp

??? msg

??? package.xml

??? src

??? C1.cpp

??? C2.cpp

??? C2.cpp

Some header files H1, H2, H3 with class declarations with their
corresponding implementations in src/ directory.

In CMakeLists I have

catkin_package(

INCLUDE_DIRS include

LIBRARIES C1 C2 C3 ${catkin_LIBRARIES}

)

add_library(C1 src/C1.cpp)

add_library(C2 src/C2.cpp)

add_library(C3 src/C3.cpp)

---------------

---------------

B is an orocos component with the following structure

??? CMakeLists.txt

??? package.xml

??? src

??? CMakeLists.txt

??? COMP.cpp

??? COMP.hpp

In CMakeLists I have:

find_package(catkin REQUIRED COMPONENTS A)

include_directories(${catkin_INCLUDE_DIRS})

and in src/CMakeLists :

orocos_component(COMP COMP.hpp COMP.cpp)

target_link_libraries(COMP ${catkin_LIBRARIES} ${USE_OROCOS_LIBRARIES})

orocos_install_headers(COMP.hpp)

------------------

-----------------

So everything compiles nicely here.

However, when I run deployer-gnulinux and import(“COMP”) I get an error
with the library.

Could not load library
'/devel/lib/orocos/gnulinux/COMP/libCOMP-gnulinux.so':

6.619 [ ERROR ][ComponentLoader::import(path_list)] /devel/lib/libC1.so:
undefined symbol: _ZN3Ev...

Note that after the compilation inside devel/lib/ directory I have all the
compiled libraries including libC1.so libC2.so libC3.so

I looked this up and it’s apparently linking problem. So I noticed that if
inside package A if I

-

remove add_library(C1 src/C1.cpp) statement,
-

Then catkin_make
-

Run deployer-gnulinux and then I am able to import(“COMP”) without any
error.

If I manually remove the lib??.so files, without add_library statement in
package A, I cannot compile….

So what is the solution here? What am I doing wrong?

In case you are not using HTML world and this email doesn’t look nice
enough, I attached a PDF file which makes the description a bit more
readable.?

AttachmentSize
library_linking_error.pdf147.36 KB

[orocosusers] CMAKE, libraries, linking problem

Hi Keivan,

your approach should work and I do not see an obvious mistake that explains
the linking problem. See inline comments below.

If I have to guess, then you did not link library C1 to another library
which provides the missing symbol. When building shared libraries
unresolved symbols are not necessarily an error, but if you used the
orocos_component() macro to build the component library, cmake should have
added the -Wl,-z,defs linker flag in UseOROCOS-RTT.cmake:69
<https://github.com/orocos-toolchain/rtt/blob/master/UseOROCOS-RTT.cmake#L69>,
that tells the linker to not allow unresolved symbols. But I am not sure
whether this flag applies recursively, so that it would also complain if
the symbol was already unresolved in libC1.so.

At run-time, when Orocos loads the library, all symbols must be resolvable
or otherwise you will see the "undefined symbol" error. If you do not link
COMP to C1, it also does not see the unresolved symbol in C1 and there is
no problem. Apparently your component COMP does not require library C1 if
you can omit it?

You can also test by adding a simple executable to package A that calls a
function or class method defined in C1, without even using Orocos. For
executables all symbols must be resolvable by the linker.

Maybe the full symbol name that was abbreviated in the output can serve as
a hint? You can demangle it with

echo _ZN3Ev... | c++filt

or by piping your complete output through c++filt.

On 8 August 2017 at 15:49, Keivan Zavari <keivan [dot] zavari [..] ...> wrote:

> ?I have two packages, A & B.
>
> A is a catkin package with the following structure:
>
>
> ??? CMakeLists.txt
>
> ??? include
>
> ? ??? A
>
> ? ??? C1.hpp
>
> ? ??? C2.hpp
>
> ? ??? C3.hpp
>
> ??? msg
>
> ??? package.xml
>
> ??? src
>
> ??? C1.cpp
>
> ??? C2.cpp
>
> ??? C2.cpp
>
> Some header files H1, H2, H3 with class declarations with their
> corresponding implementations in src/ directory.
>
> In CMakeLists I have
>
> catkin_package(
>
> INCLUDE_DIRS include
>
> LIBRARIES C1 C2 C3 ${catkin_LIBRARIES}
>

You should not add ${catkin_LIBRARIES} here. Only list the libraries that
are built by this package and that you want to expose. But you eventually
have to add DEPENDS or CATKIN_DEPENDS arguments and list all the
dependencies that are not only used internally by your implementation, or
in other words, that all users of your package also need to link to. See
http://wiki.ros.org/catkin/CMakeLists.txt#catkin_package.28.29 or
https://answers.ros.org/question/237431/what-is-the-use-of-catkin_depend...
for some more details.

> )
>
> add_library(C1 src/C1.cpp)
>
> add_library(C2 src/C2.cpp)
>
> add_library(C3 src/C3.cpp)
>
> ---------------
>
> ---------------
>
> B is an orocos component with the following structure
>
> ??? CMakeLists.txt
>
> ??? package.xml
>
> ??? src
>
> ??? CMakeLists.txt
>
> ??? COMP.cpp
>
> ??? COMP.hpp
>
> In CMakeLists I have:
>
> find_package(catkin REQUIRED COMPONENTS A)
>
> include_directories(${catkin_INCLUDE_DIRS})
>
> and in src/CMakeLists :
>
> orocos_component(COMP COMP.hpp COMP.cpp)
>
> target_link_libraries(COMP ${catkin_LIBRARIES} ${USE_OROCOS_LIBRARIES})
>

${USE_OROCOS_LIBRARIES} is not needed here. The orocos_component() macro
already links to ${USE_OROCOS_LIBRARIES} in UseOROCOS-RTT.cmake:298
<https://github.com/orocos-toolchain/rtt/blob/master/UseOROCOS-RTT.cmake#L298>
unless
you disabled auto-linking.

orocos_install_headers(COMP.hpp)
>
> ------------------
>
> -----------------
>
> So everything compiles nicely here.
>
> However, when I run deployer-gnulinux and import(“COMP”) I get an error
> with the library.
>
> Could not load library '/devel/lib/orocos/gnulinux/
> COMP/libCOMP-gnulinux.so':
>
> 6.619 [ ERROR ][ComponentLoader::import(path_list)] /devel/lib/libC1.so:
> undefined symbol: _ZN3Ev...
>
> Note that after the compilation inside devel/lib/ directory I have all the
> compiled libraries including libC1.so libC2.so libC3.so
>
> I looked this up and it’s apparently linking problem. So I noticed that if
> inside package A if I
>
> -
>
> remove add_library(C1 src/C1.cpp) statement,
> -
>
> Then catkin_make
> -
>
> Run deployer-gnulinux and then I am able to import(“COMP”) without any
> error.
>
>
Not sure if I understood this correctly. You removed the add_library()
command and rebuilt, but without cleaning the workspace? In that case an
older version of libC1.so is still available in devel-space and can be used
by package B. But I have no idea why suddenly the missing symbol can be
resolved unless you also changed something else?

>
> If I manually remove the lib??.so files, without add_library statement in
> package A, I cannot compile….
>

>
> So what is the solution here? What am I doing wrong?
>
> In case you are not using HTML world and this email doesn’t look nice
> enough, I attached a PDF file which makes the description a bit more
> readable.?
>
>

Hope I could help or at least point you to right direction.

Kind regards
Johannes

[orocosusers] CMAKE, libraries, linking problem

Hi Johannes

You guess was right. I had forgotten to link C1 to another library which
provided the missing symbol. I did that and it was solved.

Thank you for the extra information. I removed the unnecessary parts in
CMakeLists...

Regards
Keivan

On 8 August 2017 at 23:48, Johannes Meyer <johannes [..] ...> wrote:

> Hi Keivan,
>
> your approach should work and I do not see an obvious mistake that
> explains the linking problem. See inline comments below.
>
> If I have to guess, then you did not link library C1 to another library
> which provides the missing symbol. When building shared libraries
> unresolved symbols are not necessarily an error, but if you used the
> orocos_component() macro to build the component library, cmake should have
> added the -Wl,-z,defs linker flag in UseOROCOS-RTT.cmake:69
> <https://github.com/orocos-toolchain/rtt/blob/master/UseOROCOS-RTT.cmake#L69>,
> that tells the linker to not allow unresolved symbols. But I am not sure
> whether this flag applies recursively, so that it would also complain if
> the symbol was already unresolved in libC1.so.
>
> At run-time, when Orocos loads the library, all symbols must be resolvable
> or otherwise you will see the "undefined symbol" error. If you do not link
> COMP to C1, it also does not see the unresolved symbol in C1 and there is
> no problem. Apparently your component COMP does not require library C1 if
> you can omit it?
>
> You can also test by adding a simple executable to package A that calls a
> function or class method defined in C1, without even using Orocos. For
> executables all symbols must be resolvable by the linker.
>
> Maybe the full symbol name that was abbreviated in the output can serve as
> a hint? You can demangle it with
>
> echo _ZN3Ev... | c++filt
>
> or by piping your complete output through c++filt.
>
>
> On 8 August 2017 at 15:49, Keivan Zavari <keivan [dot] zavari [..] ...> wrote:
>
>> ?I have two packages, A & B.
>>
>> A is a catkin package with the following structure:
>>
>>
>> ??? CMakeLists.txt
>>
>> ??? include
>>
>> ? ??? A
>>
>> ? ??? C1.hpp
>>
>> ? ??? C2.hpp
>>
>> ? ??? C3.hpp
>>
>> ??? msg
>>
>> ??? package.xml
>>
>> ??? src
>>
>> ??? C1.cpp
>>
>> ??? C2.cpp
>>
>> ??? C2.cpp
>>
>> Some header files H1, H2, H3 with class declarations with their
>> corresponding implementations in src/ directory.
>>
>> In CMakeLists I have
>>
>> catkin_package(
>>
>> INCLUDE_DIRS include
>>
>> LIBRARIES C1 C2 C3 ${catkin_LIBRARIES}
>>
>
> You should not add ${catkin_LIBRARIES} here. Only list the libraries that
> are built by this package and that you want to expose. But you eventually
> have to add DEPENDS or CATKIN_DEPENDS arguments and list all the
> dependencies that are not only used internally by your implementation, or
> in other words, that all users of your package also need to link to. See
> http://wiki.ros.org/catkin/CMakeLists.txt#catkin_package.28.29 or
> https://answers.ros.org/question/237431/what-is-the-
> use-of-catkin_depends-in-catkin_package-cmakeliststxt/ for some more
> details.
>
>
>
>> )
>>
>> add_library(C1 src/C1.cpp)
>>
>> add_library(C2 src/C2.cpp)
>>
>> add_library(C3 src/C3.cpp)
>>
>> ---------------
>>
>> ---------------
>>
>> B is an orocos component with the following structure
>>
>> ??? CMakeLists.txt
>>
>> ??? package.xml
>>
>> ??? src
>>
>> ??? CMakeLists.txt
>>
>> ??? COMP.cpp
>>
>> ??? COMP.hpp
>>
>> In CMakeLists I have:
>>
>> find_package(catkin REQUIRED COMPONENTS A)
>>
>> include_directories(${catkin_INCLUDE_DIRS})
>>
>> and in src/CMakeLists :
>>
>> orocos_component(COMP COMP.hpp COMP.cpp)
>>
>> target_link_libraries(COMP ${catkin_LIBRARIES} ${USE_OROCOS_LIBRARIES})
>>
>
> ${USE_OROCOS_LIBRARIES} is not needed here. The orocos_component() macro
> already links to ${USE_OROCOS_LIBRARIES} in UseOROCOS-RTT.cmake:298
> <https://github.com/orocos-toolchain/rtt/blob/master/UseOROCOS-RTT.cmake#L298>
> unless you disabled auto-linking.
>
>
> orocos_install_headers(COMP.hpp)
>>
>> ------------------
>>
>> -----------------
>>
>> So everything compiles nicely here.
>>
>> However, when I run deployer-gnulinux and import(“COMP”) I get an error
>> with the library.
>>
>> Could not load library '/devel/lib/orocos/gnulinux/CO
>> MP/libCOMP-gnulinux.so':
>>
>> 6.619 [ ERROR ][ComponentLoader::import(path_list)]
>> /devel/lib/libC1.so: undefined symbol: _ZN3Ev...
>>
>> Note that after the compilation inside devel/lib/ directory I have all
>> the compiled libraries including libC1.so libC2.so libC3.so
>>
>> I looked this up and it’s apparently linking problem. So I noticed that
>> if inside package A if I
>>
>> -
>>
>> remove add_library(C1 src/C1.cpp) statement,
>> -
>>
>> Then catkin_make
>> -
>>
>> Run deployer-gnulinux and then I am able to import(“COMP”) without
>> any error.
>>
>>
> Not sure if I understood this correctly. You removed the add_library()
> command and rebuilt, but without cleaning the workspace? In that case an
> older version of libC1.so is still available in devel-space and can be used
> by package B. But I have no idea why suddenly the missing symbol can be
> resolved unless you also changed something else?
>
>
>>
>> If I manually remove the lib??.so files, without add_library statement
>> in package A, I cannot compile….
>>
>
>
>
>>
>> So what is the solution here? What am I doing wrong?
>>
>> In case you are not using HTML world and this email doesn’t look nice
>> enough, I attached a PDF file which makes the description a bit more
>> readable.?
>>
>>
>
> Hope I could help or at least point you to right direction.
>
> Kind regards
> Johannes
>
> --
> Johannes Meyer, Roboticist
> +32 468 139828
> Intermodalics - Gaston Geenslaan 9, 3001 Heverlee - BELGIUM
> www.intermodalics.eu
>