Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
12409 Discussions

uclinux user application linking to lib

Honored Contributor II

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? 



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



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
Honored Contributor II

any help would be appreciated

Honored Contributor II

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.
Honored Contributor II

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? 


Honored Contributor II

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.