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++
12589 Discussions

how to set char by uart use fopen and fclose ?

Altera_Forum
Honored Contributor II
1,511 Views

why it give me this message "undefined reference to `fopen'","undefined reference to `fclose'" , when i use fopen and fclose to uart 

 

if i miss any incluse file ? 

 

 

 

 

# include "system.h"# include "io.h"# include "stdio.h"# include "altera_avalon_lcd_16207_regs.h"# include "altera_avalon_timer.h"# include "altera_avalon_timer_regs.h"# include "sys/alt_irq.h"# include "altera_avalon_uart_regs.h"# include "altera_avalon_uart.h"# include "alt_types.h"# include "stdlib.h"# include "unistd.h"# include "fcntl.h"# include "sys/alt_alarm.h"# include "string.h"# include "sys/ioctl.h"# include "fcntl.h"# include "string.h"# include "stddef.h"# include "priv/alt_file.h" 

int main() 

{  

FILE *fp ; 

 

fp=fopen("/dev/UART_PC_NAME","r+"); 

//UART_PC_NAME is my uart name 

if(fp) 

fprintf(fp,"close the uart.\n"); 

fclose(fp); 

 

 

 

 

this is the error message  

 

 

 

**** Incremental build of configuration Debug for project otl350a **** 

make -s all  

Compiling otl350a.c... 

../otl350a.c: In function `main': 

../otl350a.c:28: warning: unused variable `u_p' 

../otl350a.c:28: warning: unused variable `DATA_R_' 

../otl350a.c:30: warning: unused variable `fd0' 

../otl350a.c:76:3: warning: no newline at end of file 

Linking otl350a.elf... 

obj/otl350a.o(.text+0x28): In function `main': 

../otl350a.c:49: undefined reference to `fopen' 

obj/otl350a.o(.text+0x50):../otl350a.c:52: undefined reference to `fclose' 

collect2: ld returned 1 exit status 

make: *** [otl350a.elf] Error 1 

Build completed
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
567 Views

 

--- Quote Start ---  

originally posted by yangroot@Oct 7 2005, 09:23 PM 

#include "system.h"# include "stdio.h" 

--- Quote End ---  

 

Looking at your code, these should be the only include files you need. 

 

 

--- Quote Start ---  

originally posted by yangroot+oct 7 2005, 09:23 pm--><div class='quotetop'>quote (yangroot @ oct 7 2005, 09:23 pm)</div> 

--- quote start ---  

../otl350a.c: in function `main&#39;: 

../otl350a.c:28: warning: unused variable `u_p&#39; 

../otl350a.c:28: warning: unused variable `data_r_&#39; 

../otl350a.c:30: warning: unused variable `fd0&#39; 

../otl350a.c:76:3: warning: no newline at end of file[/b] 

--- quote end ---  

 

this looks like it&#39;s from something other than what you posted. 

 

<!--quotebegin-yangroot@Oct 7 2005, 09:23 PM 

linking otl350a.elf... 

obj/otl350a.o(.text+0x28): in function `main&#39;: 

../otl350a.c:49: undefined reference to `fopen&#39; 

obj/otl350a.o(.text+0x50):../otl350a.c:52: undefined reference to `fclose&#39; 

--- Quote End ---  

 

I think you&#39;re missing a system library. It should show up as "YourProjectName_syslib" in the project list, and it should be set as the system library in your project&#39;s properties.
0 Kudos
Altera_Forum
Honored Contributor II
567 Views

 

--- Quote Start ---  

originally posted by yangroot@Oct 7 2005, 09:23 PM 

why it give me this message "undefined reference to `fopen&#39;","undefined reference to `fclose&#39;" , when i use fopen and fclose to uart 

 

if i miss any incluse file ? 

--- Quote End ---  

 

 

Maybe# include <strings.h> 

 

These are all the headers I used: 

#include <stdio.h># include <string.h># include <alt_types.h># include <io.h> /* Design-specific headers */# include "system.h" 

 

system.h seems to know about all the peripherals in my design, but I didn&#39;t use interrupts.  

 

Also, weird stuff happens when I try to use the small C libraries. IO works differently, things like that. And another thing: I have had problems using // for comments. 

 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

#include "system.h"# include "io.h"# include "stdio.h"# include "altera_avalon_lcd_16207_regs.h"# include "altera_avalon_timer.h"# include "altera_avalon_timer_regs.h"# include "sys/alt_irq.h"# include "altera_avalon_uart_regs.h"# include "altera_avalon_uart.h"# include "alt_types.h"# include "stdlib.h"# include "unistd.h"# include "fcntl.h"# include "sys/alt_alarm.h"# include "string.h"# include "sys/ioctl.h"# include "fcntl.h"# include "string.h"# include "stddef.h"# include "priv/alt_file.h" 

int main() 

{  

FILE *fp ; 

 

fp=fopen("/dev/UART_PC_NAME","r+"); 

//UART_PC_NAME is my uart name 

if(fp) 

  { 

    fprintf(fp,"close the uart.\n"); 

    fclose(fp); 

      } 

}[/b] 

--- Quote End ---  

 

 

Looks very much like what&#39;s in the book. I don&#39;t think it&#39;s the code itself. 

 

 

--- Quote Start ---  

originally posted by tns1@Oct 12 2005, 04:53 PM 

i have some nios2 test code below that uses the jtag_uart. it should do non-blocking read & write of the jtag uart when fed from the nios2-terminal. the code behaves as expected when using uart0, but not when using the jtag uart.  

 

when using the jtag uart, the feof() and ferror calls() behave as though they have been swapped! feof() is never true. ferror() is set true (err=1) when no chars are read, and false when a char is read.  

 

this looks like a bug. 

--- Quote End ---  

 

 

I had a similar problem. I think it has something to do with the jtag uart&#39;s input buffer and how the HAL handles carriage returns or EOF. I&#39;d like to see a solution to this. Programs that work on the jtag_uart don&#39;t work when I change stdio to UART. 

 

Can the ferror be a data overrun?
0 Kudos
Altera_Forum
Honored Contributor II
567 Views

#include "system.h"# include "io.h"# include "stdio.h"# include "altera_avalon_lcd_16207_regs.h"# include "altera_avalon_timer.h"# include "altera_avalon_timer_regs.h"# include "sys/alt_irq.h"# include "altera_avalon_uart_regs.h"# include "altera_avalon_uart.h"# include "alt_types.h"# include "stdlib.h"# include "unistd.h"# include "fcntl.h"# include "sys/alt_alarm.h"# include "string.h"# include "sys/ioctl.h"# include "fcntl.h"# include "string.h"# include "stddef.h"# include "priv/alt_file.h" int main() {  FILE *fp;  fp=fopen("/dev/UART_PC_NAME","r+"); //UART_PC_NAME is my uart name  if(fp)    {      fprintf(fp,"close the uart.\n");      fclose(fp);      } }

0 Kudos
Reply