Page 1 of 1
DJGPP problem
Posted: Mon Feb 03, 2003 11:44 am
by 2100-OS
I'm now having a C objectfile and a C++ objectfile. But it seems that I've got a problem. The C++ compiler (again DJGPP) prepends some weird tokens instead of _ before the function, so I can never make an extern to a C function. How can I solve this. I use the well known arguments for C++:
-ffreestanding -nostdlib -fno-builtin -fno-rtti -fno-exceptions
Do I need to write stubs for this? Or is there a way I can tell C++ to use _ instead of something else
Re:DJGPP problem
Posted: Mon Feb 03, 2003 1:21 pm
by df
sounds like its building the rtti info and other bits, i found removing inline to normal functions fixed it when i was playing around..
try removing the inline keyword on things
Re:DJGPP problem
Posted: Mon Feb 03, 2003 1:38 pm
by whyme_t
hey,
This is easy to fix my friend
First, an explanation. When your C source is compiled, each function / variable is turned into a symbol. This involves 'name mangling'. The standard for C symbol mangling is to append a leading _ to the front, as you were expecting.
In C++ however, there is NO default method for name mangling. In DJGPP, The mangled symbol normally will have a __ZNUM type prefix then the Class Name, then your function name, and lastly the type of parameters that the function takes. This is needed for C++ member functions, but not good for C style functions. But fear not, there is a solution...
The solution.
Just add this to your function, extern "C".
e.g.
Code: Select all
extern "C" void someFunc(int i)
{
//some code
}
Re:DJGPP problem
Posted: Mon Feb 03, 2003 1:39 pm
by 2100-OS
There aren't any inline keywords, thereby, I didn't define -fno-rtti not for nothing...
But I will look for another parameter missing
Re:DJGPP problem
Posted: Mon Feb 03, 2003 1:43 pm
by 2100-OS
[glow=red,2,300]
extern "C" void someFunc(int i)
{
//some code
}
[/glow]
I can beat myself, it was the first C++ lesson I ever got... who has a shotgun to commit suicide

Re:DJGPP problem
Posted: Mon Feb 03, 2003 4:51 pm
by df
the easier way to do it, in your header files
(which is what i do)
Code: Select all
#ifndef _MYHEADER_BLAH_H
#define _MYHEADER_BLAH_H
#ifdef __cplusplus
extern "C"{
#endif
extern func1.......
extern func2.........
#ifdef __cplusplus
};
#endif
#endif