Libusb undefined reference to

后端 未结 4 1575
生来不讨喜
生来不讨喜 2020-12-10 05:08

I\'m trying to set up libusb API on my OS. I downloaded libusb api on libusb.org. I followed the standard installation procedure:

cd into directory
./configu         


        
相关标签:
4条回答
  • 2020-12-10 05:41

    I did face the same problem. But I was able to solve it by adding '-lusb-1.0' to the linker.

    e.g : g++ myfile.cpp -lusb-1.0

    0 讨论(0)
  • 2020-12-10 05:45

    you have to set the library linker flag for compilation in the linker, you can get a full list in the console by executing

    pkg-config --list-all
    

    These are the libraries which you have installed on your system and you have to link against the ones you want to use. so in your example it is libusb so you do

    pkg-config --libs libusb
    

    there should be the output

    -lusb
    

    or

    -lusb-1.0
    

    This gives you the flag you have to pass to the linker. e.g.

    g++ myfile.cpp -lusb[-1.0]
    

    Then you edit the configuration of the project and search for the linkerflags, there should be a textfield for that somewhere in the buildoptions. i'm not quite shure where to find it but googling for it suggested:

    Project -> Properties -> C/C++
    Build -> Miscellaneous -> flags
    

    After you found it, just add the linker flag in the textfield and you should be fine.

    EDIT

    since my answer is the accepted one, I also added the other flag that seems to work for a lot of people.

    0 讨论(0)
  • 2020-12-10 05:53

    What is your linker command line? You need to have -lusb in the linking command; just having the header included won't work.

    0 讨论(0)
  • 2020-12-10 05:56

    I don't use Eclipse C/C++ but I am pretty sure the reason is the same that I faced some while ago when setting up a C project in Netbeans.

    It's not enough to have the #include in your code and the library at the right location - you also have to tell Eclipse where to look for them and how to use them. This turorial shows you how to set it up in Eclipse.

    0 讨论(0)
提交回复
热议问题