Results 1 to 3 of 3
Hi All,
I am trying to add some function to the c++ project (calling function) and the called function are in C. And i am getting error "undefined reference to ...
- 05-27-2010 #1Just Joined!
- Join Date
- Jun 2009
- Posts
- 12
g++ linking problem: undefined reference to Function
Hi All,
I am trying to add some function to the c++ project (calling function) and the called function are in C. And i am getting error "undefined reference to "Hello(int,int)" " while linking. It is compling correctly. It is linking to header file mention in the calling function. This header file has definition to the c - called function.
Do you thinking having c files into C++ project will be a problem ?
Should I remove <stdio.h> in c files ?
Please let me know your suggestions.
Thanks
fido
- 05-28-2010 #2Linux Newbie
- Join Date
- Apr 2007
- Posts
- 119
Calling c functions from a c++ program is no problem at all. Post the code and we might be able to spot what is wrong.
- 05-30-2010 #3Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
In your C++ code, you need to indicate to the compiler that the external function uses C-linkage. That is the purpose of the compiler directive 'extern "C"'. Example:
Code:// C++ source file, xyz.cpp extern "C" void cfunc(void); void xyz::somefunc(int) { // Do some stuff . . . cfunc(intval); }Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote