roboception / rc_genicam_api

Roboception convenience layer around GenICam and GigE Vision.
Other
114 stars 45 forks source link

Linking in cmake #35

Open MyronRodrigues-StreetDrone opened 2 years ago

MyronRodrigues-StreetDrone commented 2 years ago

Thank you for this library.

Installed v2.5.14 with the following flags

cmake -DCMAKE_INSTALL_PREFIX=/opt/rc_genicam -DINSTALL_COMPLETION=ON ..
make
sudo make install

Been trying to link it in CMakeLists after installing into /opt/rc_genicam

CMakeLists.txt

find_package(RC_GENICAM_API REQUIRED HINTS "/opt/rc_genicam")

message("found RCG includes: ${RC_GENICAM_API_INCLUDE_DIRS}")
message("found RCG libs: ${RC_GENICAM_API_LIBRARIES}")

include_directories(
    include
    ${RC_GENICAM_API_INCLUDE_DIRS}
)

add_executable(cam src/cam2cv_producer.cpp)
target_link_libraries(cam ${RC_GENICAM_API_LIBRARIES})

on cmake.. i get

found RCG includes: /opt/rc_genicam/include;/opt/rc_genicam/include/rc_genicam_api/genicam
found RCG libs: /opt/rc_genicam/lib/libGCBase_gcc48_v3_3.so;/opt/rc_genicam/lib/libGenApi_gcc48_v3_3.so;/opt/rc_genicam/lib/liblog4cpp_gcc48_v3_3.so;/opt/rc_genicam/lib/libLog_gcc48_v3_3.so;/opt/rc_genicam/lib/libMathParser_gcc48_v3_3.so;/opt/rc_genicam/lib/libNodeMapData_gcc48_v3_3.so;/opt/rc_genicam/lib/libXmlParser_gcc48_v3_3.so;rc_genicam_api
-- Configuring done
-- Generating done
-- Build files have been written to: /home/myron/dev/cam-share/build

but make fails with

/usr/bin/ld: cannot find -lrc_genicam_api
heikohimu commented 2 years ago

Looks like it fails, because you built and installed the package for a non-standard location. It cannot find the library there. I agree that it should work, I am just not sure how to fix it. But even if building would work, you would need to set the LD_LIBRARY_PATH to /opt/rc_genicam/lib to find the library at runtime of your program.

As workaround, you could run cmake with CMAKE_INSTALL_PREFIX=/usr which is the default. /usr/local may also work. If you are working on Ubuntu, you may also do 'make package' for building a package that you can nicely install and de-install.

MyronRodrigues-StreetDrone commented 2 years ago

I'm not sure if LD_LIBRARY_PATH is necessary, the HINT pointed out find_package in the right place as you see the message() outputs below. The only part missing is the librc_genicam_api.so in the rc_genicam_api/lib directory which is appended as a whole in the ${RC_GENICAM_API_LIBRARIES}" instead of the shared object. A fix in the cmakelists should do it i think, but my knowledge is limited there.

found RCG includes: /opt/rc_genicam/include;/opt/rc_genicam/include/rc_genicam_api/genicam
found RCG libs: /opt/rc_genicam/lib/libGCBase_gcc48_v3_3.so;/opt/rc_genicam/lib/libGenApi_gcc48_v3_3.so;/opt/rc_genicam/lib/liblog4cpp_gcc48_v3_3.so;/opt/rc_genicam/lib/libLog_gcc48_v3_3.so;/opt/rc_genicam/lib/libMathParser_gcc48_v3_3.so;/opt/rc_genicam/lib/libNodeMapData_gcc48_v3_3.so;/opt/rc_genicam/lib/libXmlParser_gcc48_v3_3.so;rc_genicam_api
-- Configuring done
-- Generating done
-- Build files have been written to: /home/myron/dev/cam-share/build

output of ls /opt/rc_genicam/lib

libGCBase_gcc48_v3_3.so      libNodeMapData_gcc48_v3_3.so
libGenApi_gcc48_v3_3.so      librc_genicam_api.so
liblog4cpp_gcc48_v3_3.so     librc_genicam_api.so.2.5
libLog_gcc48_v3_3.so         libXmlParser_gcc48_v3_3.so
libMathParser_gcc48_v3_3.so  rc_genicam_api

Also the install prefix was intentional, I prefer keeping non os libraries in /opt instead of /usr.

heikohimu commented 2 years ago

Yes, for compiling, there is just "rc_genicam_api" as library given in the RC_GENICAM_API_LIBRARIES variable. This only works if the lib can be found, e.g. in a standard location. I agree that this should also work when installing the package to another location as you did.

However, for execution, your program needs to know where the shared libraries are. This is normally not compiled into your program (i.e. via rpath), but your program will look into the system locations (e.g. /usr/lib) and also check the LD_LIBRARY_PATH variable. If it cannot find the library there, then you program wont run. This runtime issue has nothing to do with cmake and the issue above. Thats why I would suggest putting the rc_genicam_api package into a standard location.

MyronRodrigues-StreetDrone commented 2 years ago

Just made that PR which saves the user from manually setting the LD_LIBRARY_PATH. I avoid using it after reading this

For the linking problem I think it could be line 87 in cmake/PROJECTConfig.cmake.in. The @PROJECT_LIBRARIES@ translates to rc_genicam_api instead of the actual targets. I'm not sure how to solve it though, tried a few things but no results that work.

list(APPEND @PROJECT_NAME_UPPER@_LIBRARIES @PROJECT_LIBRARIES@)