Importing a C++ file
BlitzMax Forums/BlitzMax Programming/Importing a C++ file
| ||
I can't figure out why the Output shows this: Building Console Compiling:Console.cpp Build Error: failed to compile C:/Documents and Settings/David/Desktop/Blitz Max/Console.cpp Process complete with this Bmax code: and this being the Dev C++ file: Why am I getting this error? The C++ compiler does just fine in compiling it. Help please? |
| ||
You need to wrap any C++ function in an extern "C" block, and also use char* instead of string (blitzmax strings are not compatible with C++ strings). Next you have to add the functions to an extern block in blitzmax, and again not using String but either a Byte Ptr or $z (CString). example of extern block in bmx: Extern "C" Function ConsolePrint:Int( text$z) EndExtern |
| ||
And an example of the extern "C" that you will need to add to the .cpp :extern "C" { bool ConsolePrint (string text) { cout << text << endl; return true; } } Otherwise the method signature will be mangled. Ask Google or your favourite search engine about C++ name mangling for more information :-) |
| ||
Alright, looking at name mangling makes my head hurt. It was a challenge for me just to write that bit of C++ code you see I'm so bad at it. If it weren't for an extremely helpful book I've got it would've never been written. Anyway, here is my new code and yet I still get the same errors. I download MinGW already and followed Mark's installation instructions but no fix. Again, exact same output results. Bmax C++ |
| ||
Although mentioned above: It will not work with C++ string class You must use char* in the functions that interface with BM BM does not play nicely with C++ classes |
| ||
I'm afraid I don't understand. Where am I to use char* ? Will char* not cause the functions to return a single character rather than a string? I'm sorry, C++ is definately not my strong point, I was just hoping to enable some console commands in Bmax. |
| ||
char * means pointer to character(s) |
| ||
Alright, I'm confused. Please give me an example or something. I don't understand how I'm supposed to use char * for it to work. Also, do you mean literally "char*" or do you mean "*"? |
| ||
try this =)bool ConsolePrint (char *text) { cout << text << endl; return true; } |
| ||
Now the C++ compiler gives me the error [linker error] unidentified reference to 'WinMain@16' Same Bmax output. Same Bmax code. I suspect I may be missing an #include file? |
| ||
You're trying to compile it separately with a C++ compiler? Don't do that. BlitzMax will compile it automatically when you import it as you have in the BlitzMax code. |
| ||
No, I do that to make sure my code is right, the blitzmax output still says Building Console Compiling:Console.cpp Build Error: failed to compile C:/Documents and Settings/David/Desktop/Blitz Max/Console.cpp Process complete no matter what I fix |
| ||
Try to build the module blitzapp, if you can't, your C compiler is not properly installed, as part of this module is written in MinGW cpp, and proved to work and compile properly. |
| ||
Ehh... may I ask how I build blitzapp? |
| ||
open a console window and type this:cd Program Files\BlitzMax\bin bmk makemods brl.appstub Dunno what blitzapp is, he probably meant appstub ;) Or just do a "Rebuild All Modules" in the ide. |
| ||
What console widow? And does the fact that I have the demo make this not work or something? |
| ||
Demo does not allow that the windows demo is that outdated that it would not make any sense at all to try it (its 18+ months old) |
| ||
Bah! At least I'm going to be getting full version for Cristmas. |
| ||
What console widow? start > run > cmd |
| ||
All right, I had tried that but I needed to add C:\ to the beginning of the directory. I did that and it thought for a while but nothing seemed to happen. |