DJGPP problem

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
2100-OS

DJGPP problem

Post 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
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:DJGPP problem

Post 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
-- Stu --
whyme_t

Re:DJGPP problem

Post 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
   }
2100-OS

Re:DJGPP problem

Post 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
2100-OS

Re:DJGPP problem

Post 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 :)
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:DJGPP problem

Post 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
-- Stu --
Post Reply