Author Topic: Trouble whit the command REQUIRE  (Read 2537 times)

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3372
  • Integrated Brain
    • View Profile
Trouble whit the command REQUIRE
« on: 2011-Feb-27 »
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

  • Guest
Re: Trouble whit the command REQUIRE
« Reply #1 on: 2011-Feb-27 »
You need to use :

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


Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3372
  • Integrated Brain
    • View Profile
Re: Trouble whit the command REQUIRE
« Reply #2 on: 2011-Mar-03 »
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

  • Guest
Re: Trouble whit the command REQUIRE
« Reply #3 on: 2011-Mar-17 »
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.

Offline backslider

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 892
    • View Profile
Re: Trouble whit the command REQUIRE
« Reply #4 on: 2011-Mar-17 »
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

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3372
  • Integrated Brain
    • View Profile
Re: Trouble whit the command REQUIRE
« Reply #5 on: 2011-Mar-17 »
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

  • Guest
Re: Trouble whit the command REQUIRE
« Reply #6 on: 2011-Mar-17 »
Thats odd, because mine also worked :)

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3372
  • Integrated Brain
    • View Profile
Re: Trouble whit the command REQUIRE
« Reply #7 on: 2011-Mar-17 »
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.