How can I compile codes with external libraries?

Cloe Lee
 
Posts: 2
Joined: Wed Mar 07, 2018 2:57 am

How can I compile codes with external libraries?

Wed Mar 07, 2018 3:13 am

Hello,

I am trying to compile my USB driver codes using openwrt-gcc. I could not find a way how to build a program using external libraries (libusb). Here is how I did, and errors I got.

alias for openwrt_gcc
Code: Select all
alias openwrt_gcc='/home/cloe/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mipsel-openwrt-linux-gcc'


I found the libusb flag using this command.
Code: Select all
pkg-config --libs libusb


Code: Select all
cloe@spike:~/src/vocoreUSBdriver$ openwrt_gcc -g main.c -o -lusb-1.0  vocoreUSBdriver
mipsel-openwrt-linux-gcc: error: vocoreUSBdriver: No such file or directory
cloe@spike:~/src/vocoreUSBdriver$ openwrt_gcc -o main main.c -lusb-1.0
mipsel-openwrt-linux-gcc: warning: environment variable 'STAGING_DIR' not defined
mipsel-openwrt-linux-gcc: warning: environment variable 'STAGING_DIR' not defined
mipsel-openwrt-linux-gcc: warning: environment variable 'STAGING_DIR' not defined
/home/cloe/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/bin/ld: cannot find -lusb-1.0
collect2: error: ld returned 1 exit status


Code: Select all
cloe@spike:~/src/vocoreUSBdriver$ openwrt_gcc -o main main.c -lusb
mipsel-openwrt-linux-gcc: warning: environment variable 'STAGING_DIR' not defined
mipsel-openwrt-linux-gcc: warning: environment variable 'STAGING_DIR' not defined
mipsel-openwrt-linux-gcc: warning: environment variable 'STAGING_DIR' not defined
/home/cloe/openwrt/staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mipsel-openwrt-linux-uclibc/4.8.3/../../../../mipsel-openwrt-linux-uclibc/bin/ld: cannot find -lusb
collect2: error: ld returned 1 exit status


Please let me know if you have an answer for this!

Thank you

Vonger
 
Posts: 669
Joined: Sun Oct 19, 2014 6:00 am

Re: How can I compile codes with external libraries?

Wed Mar 07, 2018 9:54 am

Please fully compile openwrt first, then you will get a full toolchain.
And libusb is not -lusb, it is -lusb-1.0
also you must make sure libusb-1.0.so or libusb-1.0.a in your library search path. you can add it to your search path by use -L, for example, if it is in ./openwrt/staging_dir/xxxxxxx/lib, you should add -L./openwrt/staging_dir/xxxxxxx/lib to gcc when you do compile.

Cloe Lee
 
Posts: 2
Joined: Wed Mar 07, 2018 2:57 am

Re: How can I compile codes with external libraries?

Fri Mar 09, 2018 10:49 pm

Fixed problem using,
Code: Select all
openwrt_gcc -g main.c -L/home/cloe/openwrt/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/usr/lib -lusb-1.0 -o vocoreUSBdriver


perfectly works now.

Thank you!

Return to VoCore2

Who is online

Users browsing this forum: No registered users and 3 guests