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
DJGPP problem
Re:DJGPP problem
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
try removing the inline keyword on things
-- Stu --
-
whyme_t
Re:DJGPP problem
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.
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
}-
2100-OS
Re:DJGPP problem
There aren't any inline keywords, thereby, I didn't define -fno-rtti not for nothing...
But I will look for another parameter missing
But I will look for another parameter missing
-
2100-OS
Re:DJGPP problem
[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
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
the easier way to do it, in your header files
(which is what i do)
(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
-- Stu --
