User forums > Using Code::Blocks
C naming convention and underscores
Game_Ender:
Ok, then. But I have a question: I am trying to make an interface for a simple render I made with Ogre and Matlab. Matlab can load any library with C linkage. So I am trying compile the render (written in C++) with some simple C functions as an interface and give them C linkage (there declartions to be specific) in the shared library with "extern C". This will provide a nice bridge between Ogre and Matlab.
Is this possilbe?
mandrav:
--- Quote from: Game_Ender on March 04, 2006, 01:30:14 am ---Ok, then. But I have a question: I am trying to make an interface for a simple render I made with Ogre and Matlab. Matlab can load any library with C linkage. So I am trying compile the render (written in C++) with some simple C functions as an interface and give them C linkage (there declartions to be specific) in the shared library with "extern C". This will provide a nice bridge between Ogre and Matlab.
Is this possilbe?
--- End quote ---
I don't quite understand. I thought your example project did just that. The only problem it had was with the test program, not the library...
If I understand correctly, you 're writing a library for MatLab so you want it to have C linkage. Is that correct?
Game_Ender:
--- Quote from: mandrav on March 04, 2006, 08:41:04 am ---I don't quite understand. I thought your example project did just that. The only problem it had was with the test program, not the library...
If I understand correctly, you 're writing a library for MatLab so you want it to have C linkage. Is that correct?
--- End quote ---
Yes. The testCpp target is supposed be a C program linked to a library compiled in C++ but with C linkage for "add" function. The testC target is just the same program but linked against a C library with the "add" function. Of course if I compile testCpp as C++ it will work, but the whole idea is to produce as C++ library that has some functions exported with C name mangling so Matlab can load it, because matlab only understands C name mangling. If the testCpp target works (a C program linking to the C++ library) then I have succeeded. As it stands right now the C++ library with the externed "C" function, does not load properly in Matlab and the C one does.
So to say it shortly: I was trying to a test to make sure the G++ did not mangle the function name I labeled with "extern "C"", and this test was the only way I could do this until I found the unix tool "nm" a few minutes ago. I am going to keep plugging away and see if I can get G++ to not mangle the externed function.
Game_Ender:
I have succeeded I have to wrap the both the implementation and declaration of the functions I use for the matlab interface with extern "C", in order to G++ to not mangle the names. That was not really stated in anywhere, but I dug it out an only HP related mailing list posting. Thanks for the IDE and the help mandrav.
Navigation
[0] Message Index
[*] Previous page
Go to full version