• Home
  • Help
  • Search
  • Login
  • Register
Pages: [1]
Author Topic: Cross compile with libusb  (Read 5278 times)
edsousa84
Newbie
*

Karma: 0
Posts: 14


View Profile
« on: June 18, 2012, 08:28:25 AM »

Hi there first of all thanks for all the help you can give me.

I am triyng to cross compile to ARM (to run on th plugcomputer) a code that uses libusb.

I am using a PC with debian squeeze I have installed:
libusb-0.1-4
libusb-1.0-0
libusb-1.0-0-dev
libusb-dev
libusb++-dev

Using apt-get install

I also installed the cross compiler using http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/

I have a make file like this one
Code:
LINKFILE=
CC = /opt/gcc-arm/bin/arm-none-linux-gnueabi-gcc
#CC = gcc

CFLAGS = -DDEVEL -DDEBUG -DLINUX -DX10DEMO -c
LFLAGS = -DDEVEL -DDEBUG -DLINUX -DX10DEMO -g /lib/libpthread* -o $@

PROGS = cm15ademo
EXTLIBS = -lusb -lm

all: $(PROGS)


cm15ademo: cm15ademo.c libusbahp.c config.h onetext.h libusbahp.c libusbahp.h cm15ax10.c
$(CC) $(LFLAGS) cm15ax10.c cm15ademo.c libusbahp.c $(EXTLIBS)

%.o: %.c
$(CC) $(CFLAGS) $<

clean:
rm -f *.o $(PROGS)


But when I make the Makefile it gives me the folowing erros:
Code:
edu@gimli:~/workspace/Tests/Cpp/X10/ARM/cm15ademo$ make
/opt/gcc-arm/bin/arm-none-linux-gnueabi-gcc -DDEVEL -DDEBUG -DLINUX -DX10DEMO -g /lib/libpthread* -o cm15ademo cm15ax10.c cm15ademo.c libusbahp.c -lusb -lm
In file included from cm15ax10.c:11:
libusbahp.h:5: fatal error: usb.h: No such file or directory
compilation terminated.
In file included from cm15ademo.c:7:
libusbahp.h:5: fatal error: usb.h: No such file or directory
compilation terminated.
In file included from libusbahp.c:7:
libusbahp.h:5: fatal error: usb.h: No such file or directory
compilation terminated.
make: *** [cm15ademo] Error 1


What am I doing wrong?

I checked the /usr/include and the usb.h is there.

I f I compile it for x86 "CC=gcc" (on the Makefile) It compiles without a problem.

Is there a way to say to the compiler to use the system header files?

Or is there a better cross compiler?
Logged

mentor
Jr. Member
**

Karma: 2
Posts: 67


View Profile
« Reply #1 on: June 20, 2012, 02:47:43 AM »

I don't know your are using which plug computer

base on your discribe , you should add "-I <your header file path>" into your make file
Logged

edsousa84
Newbie
*

Karma: 0
Posts: 14


View Profile
« Reply #2 on: June 20, 2012, 06:17:21 AM »

Quote
I don't know your are using which plug computer

base on your discribe , you should add "-I <your header file path>" into your make file

That is not realy the best option. Later on I will try it but i dont think that will work because it will need the shared .so files.

What I managed to do is to recompile and install the libusb-1.0.9 by doing this:

The cross compiler is in /opt/gcc-arm/arm-none-linux-gnueabi/
So I cross compiled  using this:
Code:
edu@gimli:~/workspace/Tests/Cpp/X10/ARM/libusb-1.0.9$ ./configure --host=arm-none-linux-gnueabi --prefix=/opt/gcc-arm/arm-none-linux-gnueabi
Then i do:
Code:
make
and then
Code:
make install

This (I think) compiled the libusb-1.0.9 and instaled the files in the cross compiles folder  (--prefix=/opt/gcc-arm/arm-none-linux-gnueabi)
I cheked the folder to see if the fiels are there and they are.

Now I need to compile the libusb-compat-0.1.4
So I repeat the process
Code:
edu@gimli:~/workspace/Tests/Cpp/X10/ARM/libusb-compat-0.1.4$ ./configure --host=arm-none-linux-gnueabi --prefix=/opt/gcc-arm/arm-none-linux-gnueabi
....
....edu@gimli:/media/GimliD/edu/workspaces/Tests/Cpp/X10/ARM/libusb-compat-0.1.4$ make
make  all-recursive
make[1]: Entering directory `/media/GimliD/edu/workspaces/Tests/Cpp/X10/ARM/libusb-compat-0.1.4'
Making all in libusb
make[2]: Entering directory `/media/GimliD/edu/workspaces/Tests/Cpp/X10/ARM/libusb-compat-0.1.4/libusb'
/bin/sh ../libtool  --tag=CC   --mode=compile arm-none-linux-gnueabi-gcc -DHAVE_CONFIG_H -I. -I..    -fvisibility=hidden -std=gnu99 -fgnu89-inline -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration -Wno-pointer-sign -Wshadow -I/usr/local/include/libusb-1.0   -g -O2 -MT libusb_la-core.lo -MD -MP -MF .deps/libusb_la-core.Tpo -c -o libusb_la-core.lo `test -f 'core.c' || echo './'`core.c
libtool: compile:  arm-none-linux-gnueabi-gcc -DHAVE_CONFIG_H -I. -I.. -fvisibility=hidden -std=gnu99 -fgnu89-inline -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration -Wno-pointer-sign -Wshadow -I/usr/local/include/libusb-1.0 -g -O2 -MT libusb_la-core.lo -MD -MP -MF .deps/libusb_la-core.Tpo -c core.c  -fPIC -DPIC -o .libs/libusb_la-core.o
cc1: warning: include location "/usr/local/include/libusb-1.0" is unsafe for cross-compilation [-Wpoison-system-directories]
libtool: compile:  arm-none-linux-gnueabi-gcc -DHAVE_CONFIG_H -I. -I.. -fvisibility=hidden -std=gnu99 -fgnu89-inline -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration -Wno-pointer-sign -Wshadow -I/usr/local/include/libusb-1.0 -g -O2 -MT libusb_la-core.lo -MD -MP -MF .deps/libusb_la-core.Tpo -c core.c -o libusb_la-core.o >/dev/null 2>&1
mv -f .deps/libusb_la-core.Tpo .deps/libusb_la-core.Plo
/bin/sh ../libtool --tag=CC   --mode=link arm-none-linux-gnueabi-gcc -fvisibility=hidden -std=gnu99 -fgnu89-inline -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration -Wno-pointer-sign -Wshadow -I/usr/local/include/libusb-1.0   -g -O2 -version-info 8:4:4 -release 0.1  -o libusb.la -rpath /opt/gcc-arm/arm-none-linux-gnueabi/lib libusb_la-core.lo -L/usr/local/lib -lusb-1.0   
libtool: link: arm-none-linux-gnueabi-gcc -shared  .libs/libusb_la-core.o   -L/usr/local/lib /usr/local/lib/libusb-1.0.so -lrt    -pthread -Wl,-soname -Wl,libusb-0.1.so.4 -o .libs/libusb-0.1.so.4.4.4
/opt/gcc-arm/bin/../lib/gcc/arm-none-linux-gnueabi/4.6.3/../../../../arm-none-linux-gnueabi/bin/ld: warning: library search path "/usr/local/lib" is unsafe for cross-compilation
/usr/local/lib/libusb-1.0.so: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
make[2]: *** [libusb.la] Error 1
make[2]: Leaving directory `/media/GimliD/edu/workspaces/Tests/Cpp/X10/ARM/libusb-compat-0.1.4/libusb'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/media/GimliD/edu/workspaces/Tests/Cpp/X10/ARM/libusb-compat-0.1.4'
make: *** [all] Error 2
edu@gimli:/media/GimliD/edu/workspaces/Tests/Cpp/X10/ARM/libusb-compat-0.1.4$


As you can see in the lines:
0.1.so.4 -o .libs/libusb-0.1.so.4.4.4
/opt/gcc-arm/bin/../lib/gcc/arm-none-linux-gnueabi/4.6.3/../../../../arm-none-linux-gnueabi/bin/ld: warning: library search path "/usr/local/lib" is unsafe for cross-compilation
/usr/local/lib/libusb-1.0.so: could not read symbols: File in wrong format


It is trying to find the shares files in /usr/local/lib/ (the ones for x86)
How can i tell the ./configure to use the fiels in my arm cross compiler? (located in  /opt/gcc-arm/arm-none-linux-gnueabi)
Logged

mentor
Jr. Member
**

Karma: 2
Posts: 67


View Profile
« Reply #3 on: June 20, 2012, 07:25:33 PM »

there are two options

one is add some parmter for configure, you just need type ./configure --help , search like "CC" word add your compiler path like "CC=<your path>

another one , as I remember like D2plug , gcc has been pre-install ,so you could treat it as a computer , you could move your package to like D2Plug, just like you done at host (x86)PC ,but this time you don't need install cross_compiler , beacuse you build and run it at same device , just follow ./configure than make all should be done
Logged

edsousa84
Newbie
*

Karma: 0
Posts: 14


View Profile
« Reply #4 on: June 21, 2012, 02:10:26 AM »

Quote
one is add some parmter for configure, you just need type ./configure --help , search like "CC" word add your compiler path like "CC=<your path>

It knows were the compiler is. The problem is that it is searching for the libusb on /usr/local instead of  /opt/gcc-arm/arm-none-linux-gnueabi

The question is how can i define the bin, include, sbinetc paths?
Logged

mentor
Jr. Member
**

Karma: 2
Posts: 67


View Profile
« Reply #5 on: June 21, 2012, 03:30:13 AM »

Sorry ,misunderstand your question , you issue look like library path wrong

at this case I  think you could add some parameter to avoid this case , I list some lib configure help as below, you could see if you want to used some lib that path not

as default , you need to add "LDFLAG" to specified the library path BTW , if your header at some path need to be specified, you need add more "CPPFLAGS" info to

configure

./configure --help

...
 LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    C/C++/Objective C preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir
...
Logged

edsousa84
Newbie
*

Karma: 0
Posts: 14


View Profile
« Reply #6 on: June 21, 2012, 03:37:58 AM »

LOL

I just finished doing that before I read that you replyed...

And yes that was on the help but I did not know how to use it I bash my head against the monitor and then I got to this solution.

Code:
./configure --build=i686-linux --host=arm-none-linux-gnueabi --prefix=/opt/gcc-arm/arm-none-linux-gnueabi LIBUSB_1_0_LIBS=-L/opt/gcc-arm/arm-none-linux-gnueabi/lib LIBUSB_1_0_CFLAGS=-I /opt/gcc-arm/arm-none-linux-gnueabi/include/libusb-1.0

And I THINK it worked at least the make and make install worked.

Now I just have to find a way to compile my program... But that is another story...


Thanks for your help...
Logged

edsousa84
Newbie
*

Karma: 0
Posts: 14


View Profile
« Reply #7 on: June 21, 2012, 08:18:00 AM »

So I managed to compile the libusb-1.0.9 and the libusb-compat-0.1.4 to ARM and install in to my toolchain.

But I cannot cross compile the simple lsusb.c (in attach) program.

I am cross compiling using the following command:

Code:
arm-none-linux-gnueabi-gcc -Wall -W lsusb.c -o lsusb_exe -lusb-1.0
and it gives me the folowing errors:
Code:
edu@gimli:/media/GimliD/edu/workspaces/Tests/Cpp/X10/ARM/lsusb$ arm-none-linux-gnueabi-gcc -Wall -W lsusb.c -o lsusb_exe -lusb-1.0
/tmp/ccSqklgw.o: In function `main':
lsusb.c:(.text+0x378): undefined reference to `usb_init'
lsusb.c:(.text+0x37c): undefined reference to `usb_find_busses'
lsusb.c:(.text+0x380): undefined reference to `usb_find_devices'
lsusb.c:(.text+0x3ec): undefined reference to `usb_open'
lsusb.c:(.text+0x434): undefined reference to `usb_get_string_simple'
lsusb.c:(.text+0x49c): undefined reference to `usb_get_string_simple'
lsusb.c:(.text+0x504): undefined reference to `usb_get_string_simple'
lsusb.c:(.text+0x53c): undefined reference to `usb_close'
lsusb.c:(.text+0x604): undefined reference to `usb_busses'
collect2: ld returned 1 exit status

What am I doing wrong?
I tried the following diferences but with the same result:
Code:
arm-none-linux-gnueabi-gcc -Wall -W lsusb.c -o lsusb_exe -lusb-1.0 -L/opt/gcc-arm/arm-none-linux-gnueabi/lib -I /opt/gcc-arm/arm-none-linux-gnueabi/include/libusb-1.0
arm-none-linux-gnueabi-gcc -Wall -W lsusb.c -o lsusb_exe -lusb-1.0 -L/opt/gcc-arm/arm-none-linux-gnueabi/lib -I /opt/gcc-arm/arm-none-linux-gnueabi/include
arm-none-linux-gnueabi-gcc -Wall -W lsusb.c -o lsusb -lusb-1.0 -I/opt/gcc-arm/arm-none-linux-gnueabi/include
arm-none-linux-gnueabi-gcc -Wall -W lsusb.c -o lsusb -lusb-1.0 -I/opt/gcc-arm/arm-none-linux-gnueabi/include/libusb-1.0
arm-none-linux-gnueabi-gcc -Wall -W lsusb.c -o lsusb -lusb-1.0 -L/opt/gcc-arm/arm-none-linux-gnueabi/lib

 

* lsusb.c (4.27 KB - downloaded 104 times.)
Logged

mentor
Jr. Member
**

Karma: 2
Posts: 67


View Profile
« Reply #8 on: June 21, 2012, 08:01:53 PM »

base on your result

I will do below things to check
1. check the unreference function like "usb_init" , has be found at your compiler path
2. used file command to check the library format is you wanted
3. as I remember when you compiler this kind of library ,you should need to point out the kernel source to them ( I found you didn't mention it)
4.I still suggest to use plug computer native build , there will be more easy for you
Logged

edsousa84
Newbie
*

Karma: 0
Posts: 14


View Profile
« Reply #9 on: June 26, 2012, 02:43:08 AM »

I solved my problem.

i started using emdebian and instead of -lusb-2.0 i started using -lusb

That solved the problem thanks for your help
Logged

edsousa84
Newbie
*

Karma: 0
Posts: 14


View Profile
« Reply #10 on: June 26, 2012, 02:46:17 AM »

sorry I made a mistake instaed of -lusb-2.0 sowould read -lusb-1.0
Logged

Pages: [1]
Print
Jump to: