Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
1,176 Views

Error in Including Altera libraries file into uClinux

Hi everyone, 

 

Recently I'm finally successfully booted uClinux into DE2-115. Now I want to change a project from using Nios II Software Build Tools for Eclipse into uClinux. Before I do this, I would like to try to add a simple project which previously built in Eclipse as well into uClinux. 

 

However, when I try to compile the code using nios2-linux-uclibc-gcc hello_world.c -o hello -elf2flt, it give an error : no such file or directory.

Then I try to locate the the header file that I need and write the full location of the header file in the program as shown in the code below. However, even after I write the full location, it still gives error. The header file that I included, did include other header file and it cannot be found automatically as well.

 

Hence, I would like to ask how can I solve this problem? or I need to change some settings in my Quartus or uClinux-dist?

Hope someone can give me some help. Thank you very much!

Please see attached for the hello_world.c code built in Eclipse and the error

 

Regards,

Jun Mun

0 Kudos
6 Replies
Altera_Forum
Honored Contributor I
29 Views

Hi, 

 

 

--- Quote Start ---  

 

Recently I'm finally successfully booted uClinux into DE2-115. Now I want to change a project from using Nios II Software Build Tools for Eclipse into uClinux. Before I do this, I would like to try to add a simple project which previously built in Eclipse as well into uClinux.  

 

However, when I try to compile the code using nios2-linux-uclibc-gcc hello_world.c -o hello -elf2flt, it give an error : no such file or directory. 

Then I try to locate the the header file that I need and write the full location of the header file in the program as shown in the code below. However, even after I write the full location, it still gives error. The header file that I included, did include other header file and it cannot be found automatically as well. 

 

--- Quote End ---  

 

 

You can instruct the header file search path by the compiler switch -I"search path". Please refer to the manual of GCC. But maybe, I think you are using uClinux without MMU. If you want to use Bluetooth applications, I recommend you to install genuine Linux with MMU. 

 

Kazu
Altera_Forum
Honored Contributor I
29 Views

Dear Kazu,  

 

Finally I have solved the include path problem by setting path to C_INCLUDE_PATH. Thank for you help.  

However, it still gives these error. I have searched online for the solution. Maybe the project is not linked to the library. 

Then I tried to set some path to LD_LIBRARY_PATH. However, the error still there. 

I think I didn't set the correct library path. 

Do you know where should the library path of SD controller located? Will it be in the Project or Project_BSP folder? 

Or actually it's due to other problem? 

Thank you so much for you help. 

 

 

mun@ubuntu:~/Hello$ nios2-linux-gnu-gcc hello_world.c -o hello hello_world.c: In function 'main': hello_world.c:40: warning: incompatible implicit declaration of built-in function 'calloc' hello_world.c:40: warning: initialization from incompatible pointer type /tmp/cc7uxjmj.o: In function `main': hello_world.c:(.text+0x1e8): undefined reference to `sd_set_clock_to_max' hello_world.c:(.text+0x1f4): undefined reference to `sd_fat_mount_all' hello_world.c:(.text+0x310): undefined reference to `_impure_ptr' hello_world.c:(.text+0x314): undefined reference to `_impure_ptr' hello_world.c:(.text+0x368): undefined reference to `alt_up_char_buffer_open_dev' hello_world.c:(.text+0x374): undefined reference to `alt_up_char_buffer_init' hello_world.c:(.text+0x37c): undefined reference to `alt_up_char_buffer_clear' hello_world.c:(.text+0x450): undefined reference to `alt_up_char_buffer_string' hello_world.c:(.text+0x464): undefined reference to `alt_up_char_buffer_string' hello_world.c:(.text+0x478): undefined reference to `alt_up_char_buffer_string' hello_world.c:(.text+0x71c): undefined reference to `alt_up_char_buffer_draw' hello_world.c:(.text+0x75c): undefined reference to `alt_up_char_buffer_string' collect2: ld returned 1 exit status  

 

 

 

--- Quote Start ---  

Hi, 

 

You can instruct the header file search path by the compiler switch -I"search path". Please refer to the manual of GCC. But maybe, I think you are using uClinux without MMU. If you want to use Bluetooth applications, I recommend you to install genuine Linux with MMU. 

 

Kazu 

--- Quote End ---  

 

 

What do you meant by genuine Linux with MMU? 

 

I did followed the link below to build the hardware architechture in QSYS: 

https://www.youtube.com/watch?v=rxlyezof0rs 

 

The uClinux dist that I used is downloaded from the link below: 

ftp://ftp.altera.com/outgoing/nios2-linux/20120802/ 

 

The Linux OS that I used is Ubuntu 14.04.4 LTS 32-bit. 

 

 

Best Regards, 

Jun Mun
Altera_Forum
Honored Contributor I
29 Views

Hi, 

 

and what is the difference between nios2-linux-gnu-gcc an nios2-linux-uclibc-gcc command?  

I refer to many resources, but some use nios2-linux-gnu-gcc and some use nios2-linux-uclibc-gcc to compile the program.  

Then flat format file created will be put into ~/uClinux-dist/romfs/bin before make image. 

 

 

Jun Mun
Altera_Forum
Honored Contributor I
29 Views

Hi, 

 

 

--- Quote Start ---  

 

What do you meant by genuine Linux with MMU? 

 

I did followed the link below to build the hardware architechture in QSYS: 

https://www.youtube.com/watch?v=rxlyezof0rs 

 

The uClinux dist that I used is downloaded from the link below: 

ftp://ftp.altera.com/outgoing/nios2-linux/20120802/ 

 

--- Quote End ---  

 

 

There are two kinds of Linux kernel. One is using MMU and I sometimes call it 'genuine Linux'. Another can be executed in a small CPU which has no MMU and it's called 'uClinux'. uClinux has excellent features e.g. it does not require much memories, but also it has some disadvantages e.g. we can't use 'bash' on it. If you are using Nios's MMU, it's OK. no problem.  

 

 

--- Quote Start ---  

 

and what is the difference between nios2-linux-gnu-gcc an nios2-linux-uclibc-gcc command?  

I refer to many resources, but some use nios2-linux-gnu-gcc and some use nios2-linux-uclibc-gcc to compile the program.  

Then flat format file created will be put into ~/uClinux-dist/romfs/bin before make image. 

 

--- Quote End ---  

 

 

So you are using the Linux with MMU, you should use the tools in the folder 'nios2-linux-toolchain-mmu-***'. 

 

 

--- Quote Start ---  

 

However, it still gives these error. I have searched online for the solution. Maybe the project is not linked to the library. 

Then I tried to set some path to LD_LIBRARY_PATH. However, the error still there. 

I think I didn't set the correct library path. 

Do you know where should the library path of SD controller located? Will it be in the Project or Project_BSP folder? 

Or actually it's due to other problem? 

 

mun@ubuntu:~/Hello$ nios2-linux-gnu-gcc hello_world.c -o hello hello_world.c: In function 'main': hello_world.c:40: warning: incompatible implicit declaration of built-in function 'calloc' hello_world.c:40: warning: initialization from incompatible pointer type /tmp/cc7uxjmj.o: In function `main': hello_world.c:(.text+0x1e8): undefined reference to `sd_set_clock_to_max' hello_world.c:(.text+0x1f4): undefined reference to `sd_fat_mount_all' hello_world.c:(.text+0x310): undefined reference to `_impure_ptr' hello_world.c:(.text+0x314): undefined reference to `_impure_ptr' hello_world.c:(.text+0x368): undefined reference to `alt_up_char_buffer_open_dev' hello_world.c:(.text+0x374): undefined reference to `alt_up_char_buffer_init' hello_world.c:(.text+0x37c): undefined reference to `alt_up_char_buffer_clear' hello_world.c:(.text+0x450): undefined reference to `alt_up_char_buffer_string' hello_world.c:(.text+0x464): undefined reference to `alt_up_char_buffer_string' hello_world.c:(.text+0x478): undefined reference to `alt_up_char_buffer_string' hello_world.c:(.text+0x71c): undefined reference to `alt_up_char_buffer_draw' hello_world.c:(.text+0x75c): undefined reference to `alt_up_char_buffer_string' collect2: ld returned 1 exit status  

 

--- Quote End ---  

 

 

Maybe, you are misunderstanding the feature of operating systems. The functions 'alt_up_char_buffer_***' are Altera's library functions and you can't use those in your Linux system. Moreover, you can't access the registers directly from the user-land. So If you execute the code 

 

//Switches a = IORD(SWITCHES_BASE,0);  

 

the kernel will evoke a fault and stop your application.  

 

Kazu
Altera_Forum
Honored Contributor I
29 Views

Hi Kazu, 

 

There are two kinds of Linux kernel. One is using MMU and I sometimes call it 'genuine Linux'. Another can be executed in a small CPU which has no MMU and it's called 'uClinux'. uClinux has excellent features e.g. it does not require much memories, but also it has some disadvantages e.g. we can't use 'bash' on it. If you are using Nios's MMU, it's OK. no problem. So you are using the Linux with MMU, you should use the tools in the folder 'nios2-linux-toolchain-mmu-***'. 

Then I think I'm using uclinux with MMU. Thanks for the explanation. 

 

 

 

--- Quote Start ---  

 

 

Maybe, you are misunderstanding the feature of operating systems. The functions 'alt_up_char_buffer_***' are Altera's library functions and you can't use those in your Linux system. Moreover, you can't access the registers directly from the user-land. So If you execute the code 

 

//Switches a = IORD(SWITCHES_BASE,0);  

 

the kernel will evoke a fault and stop your application.  

 

Kazu 

--- Quote End ---  

 

 

Then I must be misunderstood it. I'm actually totally new to Linux system and started to learn it recently. I thought that Altera's library fuctions can apply directly in linux system too.  

Besides, I found this in a reference but I'm still not very sure how to use it to access IO ports.  

 

To access IO ports, we can define them as memory pointer access (uncached). Nios2-Linux does not lock access to the memory like normal Linux distros, so it is not a problem : (*(volatile unsigned *)(port)) //for read, replace port with the hardware address (*(volatile unsigned *)(port))=(d) //for write, replace port with the hardware address To maintain the IORD and IOWR standard, which is used in Nios II systems, these macros can be defined at the beginning of the source code to ease portability : # define IORD(address,offset) (*(volatile unsigned *)(((address)|0x80000000)+4*(offset))) # define IOWR(address,offset,value) (*(volatile unsigned *)(((address)|0x80000000)+4*(offset)))=(value) 

 

May I know is there any reference that can help me to understand more in programming DE2-115 in linux system? 

like some sample coding to display some words in LCD,or control the LEDs and so on. 

Because I find it hard to find a good reference for that. 

Really thanks a lot for your help. 

 

 

Best Regards, 

Jun Mun
Altera_Forum
Honored Contributor I
29 Views

Hi, 

 

 

--- Quote Start ---  

 

Besides, I found this in a reference but I'm still not very sure how to use it to access IO ports.  

 

To access IO ports, we can define them as memory pointer access (uncached). Nios2-Linux does not lock access to the memory like normal Linux distros, so it is not a problem : (*(volatile unsigned *)(port)) //for read, replace port with the hardware address (*(volatile unsigned *)(port))=(d) //for write, replace port with the hardware address To maintain the IORD and IOWR standard, which is used in Nios II systems, these macros can be defined at the beginning of the source code to ease portability : # define IORD(address,offset) (*(volatile unsigned *)(((address)|0x80000000)+4*(offset))) # define IOWR(address,offset,value) (*(volatile unsigned *)(((address)|0x80000000)+4*(offset)))=(value) 

 

--- Quote End ---  

 

 

Maybe, this code is a sample for uClinux. To access your IO ports, you need to make a kernel driver. 

 

 

--- Quote Start ---  

 

 

May I know is there any reference that can help me to understand more in programming DE2-115 in linux system? 

like some sample coding to display some words in LCD,or control the LEDs and so on. 

Because I find it hard to find a good reference for that. 

 

--- Quote End ---  

 

 

It is a little bit difficult for a beginner to write kernel drivers...But I recommend you to find a existing driver which has similar behavior what you want. 

 

Kazu