Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12586 Discussions

uclinux user application linking to lib

Altera_Forum
Honored Contributor II
1,037 Views

Hello all, 

 

I am new to linux and just starting out and have encountred a small problem. I have got uClinux running on my DE2-115 and have writen a user application to print hello world. I put my hello.c file and makefile in the folder uClinux-dist/user/hello and that has worked it will print the hello message and can view it in the console. 

 

Now the problem is I want to include libusb and call some of its function from my hello.c program. I downloaded libusb-0.1.12.tar.gz and have extracted this and compiled it into uClinux-dist/lib/libusb-0.1.12 

 

I am thinking i need to tell the compiler somehow to link the lib/libusb-0.1.12/ so it can find this include as its not in the regular location for the standard includes. How will i do this? 

 

hello.c 

#include <stdio.h># include "usbpp.h" int main() { printf("Hello world"); } 

 

Makefile 

EXEC = hello OBJS = hello.c all: $(EXEC) $(EXEC): $(OBJS) $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS) romfs: $(ROMFSINST) /bin/$(EXEC) clean: -rm -f $(EXEC) *.elf *.gdb *.o 

 

I think i may need to edit this makefile to link the libusb library. 

 

The error i get is: 

usbpp.h: no such file or directory 

 

Anyhelp is appreciated!
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
281 Views

any help would be appreciated

0 Kudos
Altera_Forum
Honored Contributor II
281 Views

Please try adding the following lines to (the beginning of) your Makefile 

 

(sorry, I can't make sure it works without your setup) 

 

LDFLAGS = -L/path/to/libusb/dir -lusb CFLAGS = -I/path/to/libusb/include/dir  

 

 

Also, make sure you have cross-compiled libusb within the nios2-uclinux environment. If you compile libusb for your system by simply typing "make" from the libusb source dir it won't ever work on uclinux.
0 Kudos
Altera_Forum
Honored Contributor II
281 Views

Thanks for the help, I used ./configure to include the args to cross compile for nios2-uclinux. Do i also need to make or make install after this? 

 

Thanks
0 Kudos
Altera_Forum
Honored Contributor II
281 Views

You used ./configure for the lib, right? Did you use the --host switch and set CC in order to specify you want to cross-compile for the nios2 architecture? I haven't tried it so I can't tell you the exact command. 

 

Actually I'm not sure about how you should build your library. I thought you were just having a hard time to link it, so my hint was to add those lines to your application's Makefile.
0 Kudos
Reply