Ask Your Question

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

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

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} )








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

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

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, you should just do:


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


thx very much, it's done.

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


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

Seen: 1,451 times

Last updated: Nov 25 '14