You are not logged in.
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
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
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
Thank you all. That was my stupid mistake. Because I knew this before.
Offline