Forum Discussion
Altera_Forum
Honored Contributor
17 years agoNios II - mixed C and C++ project problem
Hi everybody,
I'm a newbie with Nios II IDE (Version: 9.0 Build: 132) and have following problem when building project with both C and C++ (.cpp) files. - project with source files (all .cpp) is built and can be run on HW (Cyclone II DSP development board) without problems - another project with all sources as .c files can be built and runs on HW Problem: when I want to add .cpp source file to project with .c files, all files are compiled, but linker can't find functions from .cpp file and I get "undefined reference to ..." error. So my question is, how do I setup IDE or where is the setting/flag in the project properties? Dusan1 Reply
- Altera_Forum
Honored Contributor
Use extern "C" when mixing C++ and C code
__cplusplus will be automatically defined if your compiler is a C++ compiler Use this in your header files ...
Have a look a this link http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html (http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html) Best regards#if defined(__cplusplus) extern "C" { // Make sure we have C-declarations in C++ programs # endif void yourCFunction(); # if defined(__cplusplus) }# endif