Forum Discussion
Altera_Forum
Honored Contributor
20 years agohow to set char by uart use fopen and fclose ?
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 completed3 Replies
- Altera_Forum
Honored Contributor
--- 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':
../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[/b]
--- quote end ---
this looks like it'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':
../otl350a.c:49: undefined reference to `fopen'
obj/otl350a.o(.text+0x50):../otl350a.c:52: undefined reference to `fclose' --- Quote End --- I think you'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's properties.
- Altera_Forum
Honored Contributor
--- Quote Start --- originally posted by yangroot@Oct 7 2005, 09:23 PM why it give me this message "undefined reference to `fopen'","undefined reference to `fclose'" , when i use fopen and fclose to uartif i miss any incluse file ? --- Quote End --- Maybe# include <strings.h> These are all the headers I used:
system.h seems to know about all the peripherals in my design, but I didn'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's in the book. I don't think it'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.#include <stdio.h># include <string.h># include <alt_types.h># include <io.h> /* Design-specific headers */# include "system.h"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's input buffer and how the HAL handles carriage returns or EOF. I'd like to see a solution to this. Programs that work on the jtag_uart don't work when I change stdio to UART. Can the ferror be a data overrun?
- Altera_Forum
Honored Contributor
#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); } }