Forum Discussion

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

Linking error. Problem on "undefined reference to...." in NIOS II IDE 11sp1

hello!

I am new in quartus 11 and NIOS II IDE 11sp1 for development. The project concludes four source files. the main() function is in

my_file_for_blank_project_0.cpp

the other three source files all have their corsponding H files included in my_file_for_blank_project_0.cpp.

But when I build project, the console shows :

**** Build of configuration Debug for project my_blank_project_0 ****

make -s all includes

Compiling file_sys.c...

Compiling hal.c...

Compiling host.c...

Compiling my_file_for_blank_project_0.cpp...

Linking my_blank_project_0.elf...

obj/my_file_for_blank_project_0.o(.text+0x1c4): In function `main':

../my_file_for_blank_project_0.cpp:46: undefined reference to `host()'

collect2: ld returned 1 exit status

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

the host() function is in host.c and also declared in host.h. the corresponding four *.o files can also be produced.

I do not know how to solve it.

Can anyone with kindness help me?

1 Reply

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

    I think this happens because your are mixing C and C++ source files.

    For example, If you want to call C++ code from a C source file you need the following definition in .cpp file:

    extern "C" int test_cpp_call (int n);

    int test_cpp_call (int n)

    {

    ....

    }