Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MRB_BEGIN_DECL trouble mruby 3.1.0 #6157

Open
bialystok opened this issue Jan 25, 2024 · 1 comment
Open

MRB_BEGIN_DECL trouble mruby 3.1.0 #6157

bialystok opened this issue Jan 25, 2024 · 1 comment

Comments

@bialystok
Copy link

bialystok commented Jan 25, 2024

I embeded mruby in cpp program (Linux fedora)
my main program is : g++ -W -Wall -pedantic -O0 -I . -I ~/mruby/include/ -I ~/mruby/include/mruby -c main.cpp -lm -o main.o

----main.cpp----

#include <iostream>
#include "tfunkcje.h"

int main()
{
m_start();
std::cout << "suma 1+8 = " << m_suma(1,8) << "\n";
m_stop();

return 0;
}

--- tfunkcje.h

extern "C" {

#include <mruby.h>
#include <mruby/irep.h>

int  m_start();
int  m_suma(int a,int b);
void m_stop();

}

I get error. Probably declaration are using in mruby but mruby not including it.
deleting MRB_END_DECL on endian delete errors


In file included from /usr/include/sys/types.h:176,
from /usr/include/stdlib.h:395,
from /usr/include/c++/12/cstdlib:75,
from /usr/include/c++/12/ext/string_conversions.h:41,
from /usr/include/c++/12/bits/basic_string.h:3968,
from /usr/include/c++/12/string:53,
from /usr/include/c++/12/bits/locale_classes.h:40,
from /usr/include/c++/12/bits/ios_base.h:41,
from /usr/include/c++/12/ios:42,
from /usr/include/c++/12/ostream:38,
from /usr/include/c++/12/iostream:39,
from main.cpp:1:
/home/user/mruby/include/mruby/endian.h:12:1: error: ‘MRB_BEGIN_DECL’ does not name a type
12 | MRB_BEGIN_DECL
| ^~~~~~~~~~~~~~
/home/user/mruby/include/mruby/endian.h:12:1: note: the macro ‘MRB_BEGIN_DECL’ had not yet been defined
In file included from /home/user/mruby/include/mruby.h:116,
from tfunkcje.h:3,
from main.cpp:2:
/home/user/mruby/include/mruby/common.h:21: note: it was later defined here
21 | # define MRB_BEGIN_DECL extern "C" {
|
In file included from /home/user/mruby/include/mruby.h:118:
/home/user/mruby/include/mruby/gc.h:51:9: warning: ISO C++ forbids flexible array member ‘objects’ [-Wpedantic]
51 | void *objects[];
| ^~~~~~~
make: *** [Makefile:68: main.o] Błąd 1

-------tfunkcje.cpp-----this compiled corectly----

#include <tfunkcje.h>

 mrb_state *mrb;

int m_start()
{
char kod[] = "def suma(a,b) (a+b).to_i end";
 mrb = mrb_open();

 if (!mrb) { return 1; }
 mrb_load_string(mrb, kod);

return 0;
}

void m_stop()
{
 mrb_close(mrb);
}

int m_suma(int a, int b)
{
mrb_value c;

   c = mrb_funcall(mrb, mrb_top_self(mrb), "suma",
                        2,mrb_fixnum_value(a),mrb_fixnum_value(b));

return mrb_int(mrb, c);
}
@bialystok bialystok changed the title MRB_BEGIN_DECL trouble MRB_BEGIN_DECL trouble mruby 3.1.0 Jan 25, 2024
@dearblue
Copy link
Contributor

  1. It is not desirable to add mruby/include/mruby as an include directory.

    Because the file mruby/include/mruby/endian.h may hide /usr/include/endian.h on your system.

    -g++ -W -Wall -pedantic -O0 -I . -I ~/mruby/include/ -I ~/mruby/include/mruby -c main.cpp -lm -o main.o
    +g++ -W -Wall -pedantic -O0 -I . -I ~/mruby/include/ -c main.cpp -lm -o main.o
  2. May need #include <mruby.h> before the standard library header files.

    Although mruby requires the C standard definition, it may not be defined if the C++ standard header file appears first.

    +#include "tfunkcje.h"
     #include <iostream>
    -#include "tfunkcje.h"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants