Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
12435 Discussions

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

Altera_Forum
Honored Contributor II
1,484 Views

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?
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
368 Views

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) 

.... 

}
Reply