Trouble whit the command REQUIRE

Previous topic - Next topic

mentalthink

Well yesterday, I start whit the command Inline, thanks a lot , for the book of Glbasic, is simple to read, and I learn a great amount of things, what I don´t know to this date.

Well I make this. In Glbasic I put in the main source this:


//GLBASIC

REQUIRE "test_02.cpp"
IMPORT int Moo()
Moo()


//THIS IS A C++ CODE
#include "glb.h"
int Moo()
{
   STDOUT("Moo\n");
}

and I´ve got always this error when Glbasic compile. (You can note is the same example, on the Glbasic Help)

linking:
gpc_temp0.o:gpc_temp0.cpp:(.text+0x1c): undefined reference to `__GLBASIC__::Moo()'
*** FATAL ERROR - Please post this output in the forum
_______________________________________
*** Finished ***
Elapsed: 1.6 sec. Time: 19:26
Build: 0 succeeded.
*** 1 FAILED ***

Thanks in advance for your Help.

Kinds Regards,
Iván J.







MrTAToad

You need to use :

Code (glbasic) Select
#include "glb.h"
extern "C" int Moo()
{
   STDOUT("Moo\n");
}



mentalthink

Hi MrTatoad, thanks for your reply, (excuseme for the late response, I saty very stressed whit my last 3d model for sell).

Well I tried a couple of days your solution, but not works. I have the same error on the compiler.

I don´t know what I maed wrong.

Thanks again for your reply.

Kinds Regards,
Iván J.

MrTAToad

You need to put the C stuff into a source file and not the main program file.

If you've tried that, let me know.

backslider

The code should look like this:
Code (glbasic) Select

//extern.cpp file
#include "glb.h"

#ifdef __cplusplus
extern "C" {
#endif

int muh(){
    return 69;
}

#ifdef __cplusplus
}
#endif


Code (glbasic) Select

//GLBasic File
REQUIRE "extern.cpp"

IMPORT "C" int muh() //You forgot the "C" after IMPORT


Try it, please. :)

cheers

mentalthink

Hi backSlider, thanks for your reply, works perfectlly, thanks because I don´t found nobody can help me in this little trouble.

1.000.000 thanks.

Kinds Regards,
Iván J.

MrTAToad

Thats odd, because mine also worked :)

mentalthink

HI Mr.Tatoad, well I don´t kwow what´s happens, but when I put this lines in the C++ code, the code can execute on Glbasic

Concretly, this lines
#ifdef __cplusplus

I thank your help, too, but how my C++ kwnoledeges are minimun , or nothing, I had to give up.

Equal thanks , to both for your great helps.

Kind Regards,
Iván J.