ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to solve the 'undefined reference to libusb' error in ros?

asked 2014-11-25 02:48:31 -0500

fromandto gravatar image

I am trying to transfer a camera(non-uvc) stream program to ros platform.

I've already got the camera driver running

and Makefile is like this:


g++ main.cpp -o test_gui -g -I /usr/local/include -L /usr/local/lib -D_LIN -D_DEBUG -L../lib/x64 -I../include -lASICamera -lpthread -lusb -DGLIBC_20 -m64 -lrt -I/opt


Now I want to do this in a ros node, so I write a node in which the CMakelists is like this:


include_directories( ${catkin_INCLUDE_DIRS} )

include_directories(/usr/local/include)

include_directories(/root/catkin_ws/src/asi_converter_real/include/asi_converter_real)

link_directories(/usr/local/lib)

link_libraries(pthread)

link_libraries(usb)

link_libraries(libASICamera.a)

link_libraries(libASICamera.so)

add_executable(asi_converter_real src/asi_converter_real.cpp)

target_link_libraries(asi_converter_real ${catkin_LIBRARIES})


And the Makefile line generated into /catkin_ws/build/*/ is like this:


/usr/bin/c++ CMakeFiles/asi_converter_real.dir/src/asi_converter_real.cpp.o -o /root/catkin_ws/devel/lib/asi_converter_real/asi_converter_real -rdynamic -L/usr/local/lib -lpthread -lusb -Wl,-Bstatic -lASICamera -Wl,-Bdynamic -lASICamera


But it seems that the system cannot find the dynamic libraries of libusb, coz' it reports


undefined reference to `libusb_set_configuration'

undefined reference to `libusb_claim_interface'

/usr/local/lib/libASICamera.a(ASI174MM.o): In function `WorkingFunc(void*)':

undefined reference to `libusb_bulk_transfer'

undefined reference to `libusb_bulk_transfer'


[1]Could anyone tell me how to solve this problem ?

[2]How to find the .a and .so of libusb in my computer ? (I am sure I have them, coz' I can pkg-config --cflags/--libs them)

[3]How could I explicitly link a dynamic library in ros CMakelists ? or just link_libraries(usb) is enough for both static and dynamic libriries ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-11-25 06:46:43 -0500

ahendrix gravatar image

You shouldn't link to both static and dynamic libraries. One or the other is sufficient.

In your case, instead of linking to libASICamera.a and libASICamera.so, you should just do:

link_libraries(ASICamera)

And cmake will find the appropriate static or dynamic library depending on how you're linking your executable.

Also note that if your libraries have undefined symbols the linking order matters - libraries with undefined symbols should be listed first, and the libraries which contain those symbols should be listed later.

Finally, the link_libraries() command is pretty heavy-handed; it will cause all of your executables to be linked against every library you specify. Use target_link_libraries() instead, and note that you can list multiple libraries in a single linking command.

Maybe try:

target_link_libraries(asi_converter_real ${catkin_LIBRARIES} pthread ASICamera usb)
edit flag offensive delete link more

Comments

thx very much, it's done.

fromandto gravatar image fromandto  ( 2014-11-25 10:03:10 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-11-25 02:48:31 -0500

Seen: 2,110 times

Last updated: Nov 25 '14