You are not logged in.

#1 2011-10-26 15:49:34

allencch
Member
Registered: 2011-03-25
Posts: 119

How to compile this source code (USB development)?

I tried the following coding, but I failed to link. Does anyone help me about this?

//hello.c
#include <stdio.h>
#include <usb.h>

int main(int argc,char** argv) {
	printf("hello\n");
	usb_find_busses();
	usb_find_devices();

	return 0;
}
#makefile
all: hello
	hello
	
hello : hello.o
	gcc -o hello hello.o -L/usb/lib -lusb

hello.o : hello.c
	gcc -I/usr/include/ -o hello.o hello.c

The result I get is:

gcc -I/usr/include/ -o hello.o hello.c
/tmp/ccsdiOcK.o: In function `main':
hello.c:(.text+0x7): undefined reference to `usb_find_busses'
hello.c:(.text+0xc): undefined reference to `usb_find_devices'
collect2: ld returned 1 exit status
make: *** [hello.o] Error 1

Offline

#2 2011-10-26 16:31:08

linux-ka
Member
From: ADL
Registered: 2010-05-07
Posts: 232

Re: How to compile this source code (USB development)?

you did direct compiling with linking.

In order to obtain the not linked object you need to:

gcc -l usb -c hello.c

Finally you can link it to the binary as you did at hello:hello.o.

Offline

#3 2011-10-26 17:03:31

stqn
Member
Registered: 2010-03-19
Posts: 1,191
Website

Re: How to compile this source code (USB development)?

hello.o : hello.c
	gcc -I/usr/include/ -o hello.o hello.c

Add "-c" to that last line in order to get an object file.

Offline

#4 2011-10-27 00:03:11

allencch
Member
Registered: 2011-03-25
Posts: 119

Re: How to compile this source code (USB development)?

Thank you all. That was my stupid mistake. Because I knew this before.

Offline

Board footer

Powered by FluxBB