.c works but .cpp doesnt??

BlitzMax Forums/BlitzMax Programming/.c works but .cpp doesnt??

slenkar(Posted 2010) [#1]
i tried to do a hello world in C++ which worked when the file was called keefy.c but didnt work when it was called keefy.cpp

it said 'undefined reference to Say'

here are the sources:
keefy.cpp
#include <stdio.h>

void Say(char *str)
{
printf(str);
}


keefy.c
#include <stdio.h>



void Say(char *str)
{
printf(str);
}


testc.bmx
Import "keefy.cpp"

Extern
Function Say(str:Byte Ptr)
EndExtern

Say ("hello".toCstring())



bruZard(Posted 2010) [#2]
"void Say(char *str)"

try

"void Say(const char* str)"


dawlane(Posted 2010) [#3]
Try this
#include <stdio.h>

extern "C" void Say(char *str); // It says this somewhere in the BlitzMAX Docs about using the extern keyword with c++
void Say(char *str)
{
printf(str);
}



slenkar(Posted 2010) [#4]
oh yeah it was extern "C" thanks


how do you do it 'the other way around'?

I want to call a blitz function in a .cpp file

it works in C but not in CPP


GW(Posted 2010) [#5]
Look in the bmax generated assembly file for the properly named function.


slenkar(Posted 2010) [#6]
i got it to work now thanks


Czar Flavius(Posted 2010) [#7]
Don't mix C++ and Blitz on your own if you can avoid it. It will give you a headache.


Brucey(Posted 2010) [#8]
Don't mix C++ and Blitz on your own if you can avoid it. It will give you a headache.

How so?


Czar Flavius(Posted 2010) [#9]
I'm not talking about wrapping useful C++ code to be used in Blitz :P