Importing C++

BlitzMax Forums/BlitzMax Programming/Importing C++

Czar Flavius(Posted 2007) [#1]
I've been trying to import a C++ source file but I've not had any luck. I tried to follow the tutorial but all I get is

Build Error: failed to compile C:/test/func.cpp

Any help?


Gabriel(Posted 2007) [#2]
It's kinda hard to guess without seeing either the BMX or the CPP code. You do have MinGW installed though, right?


H&K(Posted 2007) [#3]
I assumed he ment this
//----- file: c_funcs.c -----
int Doubler( int x ){
	return x+x;
}

'----- file: app.bmx -----
Import "c_funcs.c"

Extern
	Function Doubler( x )
End Extern

Print Doubler(10)


But yep, posting the code you are using might be of help.

(ps. Ive never gotten it to work either, and all the threads about it are way over my head)


Gabriel(Posted 2007) [#4]
The code you posted above ( is this from some kind of tutorial? ) works just fine for me.


Brucey(Posted 2007) [#5]
Build Error: failed to compile C:/test/func.cpp

...usually means there is a compile error inside the C++ file itself.
Don't you get a better error message than just that?

For example, if I break my .cpp file, at the end of the compile I get this :
Build Error: failed to compile C:/Program Files/BlitzMax/mod/bah.mod/qtmaxgui.mod/qtglue.cpp

However, before that, I get a reason from the compiler why it wouldn't compile:
C:/Program Files/BlitzMax/mod/bah.mod/qtmaxgui.mod/qtglue.cpp:88: 'QDesktospWidget' was not declared in this scope


Also remember, that if you want to use any C++ functions in your Max code, you will need to "extern" them like so:
extern "C" {
...
... your functions in here ...
...
}

I believe it is because C++ mangles the names of the functions, which prevents the Max code from finding it. Using extern "C" exposes function names that Max understands.

HTH
:o)


Czar Flavius(Posted 2007) [#6]
I am trying to do the tutorial used by H&K. I've copied and pasted it exactly and tried variations. I just get this:

Building test
Compiling:c_funcs.c
Build Error: failed to compile C:/test/c_funcs.c
Process complete


I tried Brucey's suggestions but that didn't make any difference. I can't see what I'm doing wrong :S


Gabriel(Posted 2007) [#7]
I repeat, you do have MinGW installed, right?

Yes, Extern "C" seems to be optional, as it works for me either way.


Czar Flavius(Posted 2007) [#8]
Thanks Gabriel. I don't think so as I've never heard of it before. Being as importing C++ code is in the default tutorials I assumed that I didn't need to install any extras!? I shall look for that now.


Czar Flavius(Posted 2007) [#9]
OK I've installed MinGW and it's put a bunch of files and stuff on my computer, but no idea what to do next.


Gabriel(Posted 2007) [#10]
All you need to do is follow Mark's instructions in the top message here :

http://www.blitzbasic.com/Community/posts.php?topic=53442


Czar Flavius(Posted 2007) [#11]
THANKS!!! :D

But... why wouldn't these instructions be included in the help system?


Chris C(Posted 2007) [#12]
I think Mark assumed that not many people would be recompiling modules, as it is, I know quite a few people who are using both C and Max in the same project regularly...

This is probably due to the lack of structures and operator overloading... the first of which can make the easiest library a pain to use.


Czar Flavius(Posted 2007) [#13]
Well because I prefere the C style syntax, and need to become more competant with C++. I was planning on writing most of my code in C++ but using BlitzMax as the graphical engine and uh "user-input-receiver". Would people say this is a good/easy idea?


Czar Flavius(Posted 2010) [#14]
I was bored and so looked for my first post! I'd have to say it was a rubbish idea.


slenkar(Posted 2010) [#15]
lol, you live you learn,