Libusb undefined reference to

后端 未结 4 1595
生来不讨喜
生来不讨喜 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: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.

提交回复
热议问题