Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

undefined reference to 'fopen' when build the count-binary template

I am new to Quartus and Nios. I just installed the quartus II web edition 9.1 and nios II 9.1, and followed every step in NIOS II hardware development tutorial. When I used the NIOS II software build tools for eclipse to create a new Nios II application and bsp from template (I chose the count-binary template), I could not build the project with the following errors. I checked the template files, which have the right .h file included. Does anybody know what could be wrong? ---thanks

---------------------------------------------

make all

Info: Building ../count_binary_bsp

make --no-print-directory -C ../count_binary_bsp

[BSP build complete]

Info: Compiling count_binary.c to obj/count_binary.o

nios2-elf-gcc -xc -MP -MMD -c -I../count_binary_bsp -I../count_binary_bsp/drivers/inc -I../count_binary_bsp/HAL/inc -DSYSTEM_BUS_WIDTH=32 -D__hal__ -pipe -DALT_NO_C_PLUS_PLUS -DALT_NO_INSTRUCTION_EMULATION -DALT_USE_SMALL_DRIVERS -DALT_SINGLE_THREADED -O0 -g -Wall -mno-hw-div -mhw-mul -mno-hw-mulx -o obj/count_binary.o count_binary.c

Info: Linking count_binary.elf

nios2-elf-g++ -T'../count_binary_bsp/linker.x' -msys-crt0='../count_binary_bsp/obj/HAL/src/crt0.o' -msys-lib=hal_bsp -L../count_binary_bsp -msmallc -Wl,-Map=count_binary.map -O0 -g -Wall -mno-hw-div -mhw-mul -mno-hw-mulx -o count_binary.elf obj/count_binary.o -lm

obj/count_binary.o(.text+0x454): In function `main':

/cygdrive/c/altera/91/nios2eds/examples/verilog/niosII_cycloneII_2c35/full_featured/software/count_binary/count_binary.c:352: undefined reference to `fopen'

collect2: ld returned 1 exit status

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

9 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You've got some code reduction options turned on. Only those examples which are tailored specifically for small code size will function with these options enabled. As you've discovered, count_binary is not one of these applications.

    Cheers,

    - slacker
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks for your quick response.

    Can you elaborate it a little more? How do you know I turned on "code reduction option" by looking at my errors? Where can I turn off this option?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    You've got some code reduction options turned on. Only those examples which are tailored specifically for small code size will function with these options enabled. As you've discovered, count_binary is not one of these applications.

    Cheers,

    - slacker

    --- Quote End ---

    Hi

    I have the same problems the guy above is having. My C code is quite small:

    #include <stdio.h>

    #include "system.h"

    #include <string.h>

    #include "altera_avalon_jtag_uart.h"

    #include "altera_avalon_jtag_uart_fd.h"

    #include "altera_avalon_jtag_uart_regs.h"

    int main()

    {

    char* msg = "Detected the character 't'.\n";

    FILE* fp;

    char prompt = 0;

    fp = fopen ("/mnt/host/test.txt", "r+"); //Open file for reading and writing

    if (fp)

    {

    while (prompt != 'v')

    { // Loop until we receive a 'v'.

    prompt = getc(fp); // Get a character from the JTAG UART.

    if (prompt == 't')

    { // Print a message if character is 't'.

    fwrite (msg, strlen (msg), 1, fp);

    }

    if (ferror(fp))// Check if an error occurred with the file pointer

    clearerr(fp);// If so, clear it.

    }

    fprintf(fp, "Closing the JTAG UART file handle.\n");

    fclose (fp);

    }

    return 0;

    }

    When I have "small_c_library" disabled I get these build error messages:

    nios2-elf-g++ -T'../epuisant_bsp/linker.x' -msys-crt0='../epuisant_bsp/obj/HAL/src/crt0.o' -msys-lib=hal_bsp -L../epuisant_bsp -Wl,-Map=epuisant.map -O0 -g -Wall -mno-hw-div -mhw-mul -mno-hw-mulx -o epuisant.elf obj/jtag.o -lm

    /cygdrive/c/altera/91/nios2eds/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.6/../../../../nios2-elf/bin/ld: region onchip_memory is full (epuisant.elf section .text). Region needs to be 1696 bytes larger.

    /cygdrive/c/altera/91/nios2eds/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.6/../../../../nios2-elf/bin/ld: section .rodata [02210020 -> 0221054b] overlaps section .exceptions [02210020 -> 022101c3]

    /cygdrive/c/altera/91/nios2eds/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.6/../../../../nios2-elf/bin/ld: section .rwdata [0221054c -> 02211fe7] overlaps section .text [022101c4 -> 0221c29f]

    /cygdrive/c/altera/91/nios2eds/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.6/../../../../nios2-elf/bin/ld: section .bss [02211fe8 -> 022120ef] overlaps section .text [022101c4 -> 0221c29f]

    collect2: ld returned 1 exit status

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

    But when I enable the "small_c_library" option I get these ones:

    obj/HAL/src/alt_uncached_free.o obj/HAL/src/alt_uncached_malloc.o obj/HAL/src/alt_unlink.o obj/HAL/src/alt_usleep.o obj/HAL/src/alt_wait.o obj/HAL/src/alt_write.o obj/HAL/src/altera_nios2_irq.o obj/HAL/src/crt0.o obj/alt_sys_init.o obj/drivers/src/altera_avalon_jtag_uart_fd.o obj/drivers/src/altera_avalon_jtag_uart_init.o obj/drivers/src/altera_avalon_jtag_uart_ioctl.o obj/drivers/src/altera_avalon_jtag_uart_read.o obj/drivers/src/altera_avalon_jtag_uart_write.o obj/drivers/src/altera_avalon_sysid.o obj/drivers/src/altera_hostfs.o

    [BSP build complete]

    Info: Compiling jtag.c to obj/jtag.o

    nios2-elf-gcc -xc -MP -MMD -c -I../epuisant_bsp -I../epuisant_bsp/drivers/inc -I../epuisant_bsp/HAL/inc -DSYSTEM_BUS_WIDTH=32 -D__hal__ -pipe -DALT_NO_C_PLUS_PLUS -DALT_NO_INSTRUCTION_EMULATION -DALT_SINGLE_THREADED -O0 -g -Wall -mno-hw-div -mhw-mul -mno-hw-mulx -o obj/jtag.o jtag.c

    Info: Linking epuisant.elf

    nios2-elf-g++ -T'../epuisant_bsp/linker.x' -msys-crt0='../epuisant_bsp/obj/HAL/src/crt0.o' -msys-lib=hal_bsp -L../epuisant_bsp -msmallc -Wl,-Map=epuisant.map -O0 -g -Wall -mno-hw-div -mhw-mul -mno-hw-mulx -o epuisant.elf obj/jtag.o -lm

    obj/jtag.o(.text+0x30): In function `main':

    /cygdrive/e/epuisant/software/epuisant/jtag.c:20: undefined reference to `fopen'

    obj/jtag.o(.text+0x54):/cygdrive/e/epuisant/software/epuisant/jtag.c:25: undefined reference to `getc'

    obj/jtag.o(.text+0x80):/cygdrive/e/epuisant/software/epuisant/jtag.c:28: undefined reference to `fwrite'

    obj/jtag.o(.text+0xc8):/cygdrive/e/epuisant/software/epuisant/jtag.c:34: undefined reference to `fclose'

    collect2: ld returned 1 exit status

    Could it be because of a small RAM memory? Should I just use a larger memory? I've followed all the instructions to create a file based system but nothing works....

    Please help

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Region needs to be 1696 bytes larger.

    --- Quote End ---

    Yes, making the memory larger is one option.

    The other is to use alternate (smaller) stdio routines. There are examples (at least one) that show you how to do this.

    Cheers,

    slacker
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Although your code is small, it uses a lot of the C runtime library ...

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Yes, making the memory larger is one option.

    The other is to use alternate (smaller) stdio routines. There are examples (at least one) that show you how to do this.

    Cheers,

    slacker

    --- Quote End ---

    Thanks for the quich reply, I'm grateful.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Although your code is small, it uses a lot of the C runtime library ...

    --- Quote End ---

    Thanks for the quick reply. I'm grateful.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    Hi

    I have the same problems the guy above is having. My C code is quite small:

    #include

    <stdio.h>

    #include

    "system.h"

    #include

    <string.h>

    #include

    "altera_avalon_jtag_uart.h"

    #include

    "altera_avalon_jtag_uart_fd.h"

    #include

    "altera_avalon_jtag_uart_regs.h"

    int

    main()

    {

    char

    * msg = "Detected the character 't'.\n";

    FILE

    * fp;

    char

    prompt = 0;

    fp = fopen ("/mnt/host/test.txt", "r+"); //Open file for reading and writing

    --- Quote End ---

    Hi,

    I wanted to ask you? where is the test.txt file in reference to your Nios II EDS build for Eclipse software?

    I am tryuing to read from a textfile, but I don't know where to put my text file? In the Project worskspace? or where?

    could someone help me please?

    Thank you