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

When mruby 1.3 is released, Should I switch C99 to C++ subsets for writing a gem? #3470

Closed
bggd opened this Issue Feb 27, 2017 · 9 comments

Comments

Projects
None yet
2 participants
@bggd
Contributor

bggd commented Feb 27, 2017

Hi all.

The latest mruby with a c++ gem that is built by C++ (reference :=> #3267).

A gem author must write a gem with C++ subsets when they use a third-party c++ gem because a pedantic C++ compiler hasn't support "compound literals" and "designated initializers" (see more example :=> https://en.wikipedia.org/wiki/Compatibility_of_C_and_C%2B%2B ).

@matz

This comment has been minimized.

Show comment
Hide comment
@matz

matz Feb 27, 2017

Member

I'd rather modify #3267 patch to allow both C and C++.

Member

matz commented Feb 27, 2017

I'd rather modify #3267 patch to allow both C and C++.

@bggd

This comment has been minimized.

Show comment
Hide comment
@bggd

bggd Feb 28, 2017

Contributor

OK.
I will write C++ subsets for gem.

Contributor

bggd commented Feb 28, 2017

OK.
I will write C++ subsets for gem.

@bggd bggd closed this Feb 28, 2017

matz added a commit that referenced this issue Feb 28, 2017

Compile C files by C compiler when C++ files mixed.
ref #3267 #3470

By this commit, mruby do not use C++ ABI mode unless
you specify explicitly. It compiles C files by C
compilers, with C++ exception enabled when it sees
C++ files in your configured mrbgems.

I haven't tried visualcpp, so please submit an issue
if you see any problem with C++ gems on Windows.
@matz

This comment has been minimized.

Show comment
Hide comment
@matz

matz Feb 28, 2017

Member

I think 1a1f834 allow C files to be compiled by C compiler.
@bggd Does this work OK for you?

Member

matz commented Feb 28, 2017

I think 1a1f834 allow C files to be compiled by C compiler.
@bggd Does this work OK for you?

@bggd

This comment has been minimized.

Show comment
Hide comment
@bggd

bggd Mar 1, 2017

Contributor

I think 1a1f834 allow C files to be compiled by C compiler.

Awesome!

Does this work OK for you?

It doesn't work with conf.enable_cxx_exception.
I use this build_config (https://github.com/bggd/mrb-with-cpp ).

MRuby::Build.new do |conf|

  toolchain :visualcpp

  conf.enable_test

  conf.enable_cxx_exception

end

Then, I got error from AppVeyor (https://ci.appveyor.com/project/bggd/mrb-with-cpp/build/job/ktkhoa9ah50kqfam ).

mruby\include\mruby/throw.h(11): fatal error C1189: #error:  Trying to use C++ exception handling in C
Contributor

bggd commented Mar 1, 2017

I think 1a1f834 allow C files to be compiled by C compiler.

Awesome!

Does this work OK for you?

It doesn't work with conf.enable_cxx_exception.
I use this build_config (https://github.com/bggd/mrb-with-cpp ).

MRuby::Build.new do |conf|

  toolchain :visualcpp

  conf.enable_test

  conf.enable_cxx_exception

end

Then, I got error from AppVeyor (https://ci.appveyor.com/project/bggd/mrb-with-cpp/build/job/ktkhoa9ah50kqfam ).

mruby\include\mruby/throw.h(11): fatal error C1189: #error:  Trying to use C++ exception handling in C

@bggd bggd reopened this Mar 1, 2017

matz added a commit that referenced this issue Mar 2, 2017

Reorganize C++ exceptions; ref #3470
There are 3 levels of C++ exception handling:
* default - no C++ exception (use setjmp/longjmp)
* enable_cxx_exception (use C++ exceptions with C ABI)
* enable_cxx_abi (use C++ ABI including exceptions)
@matz

This comment has been minimized.

Show comment
Hide comment
@matz

matz Mar 2, 2017

Member

I tried to improve enable_cxx_exception.
@bggd please close the issue if you see it working.

Member

matz commented Mar 2, 2017

I tried to improve enable_cxx_exception.
@bggd please close the issue if you see it working.

@bggd

This comment has been minimized.

Show comment
Hide comment
@bggd

bggd Mar 2, 2017

Contributor

I created a minimal C gem and C++ gem for testing build. https://github.com/bggd/dummy-c99gem https://github.com/bggd/dummy-cxxgem
I used this build_config.

MRuby::Build.new do |conf|

  if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
    toolchain :visualcpp
  else
    toolchain :gcc
    #conf.cxx.flags += %w(-pedantic-errors)
  end

  conf.gembox 'full-core'
  conf.gem :github => 'bggd/dummy-c99gem'
  conf.gem :github => 'bggd/dummy-cxxgem'

  conf.enable_debug

  conf.enable_test

  conf.enable_cxx_exception

end

I got error from Appveyor( https://ci.appveyor.com/project/bggd/mrb-with-cpp/build/1.0.8 ) and Travis CI ( https://travis-ci.org/bggd/mrb-with-cpp/builds/206944425 ).

the visualcpp(AppVeyor) can build with 'full-core'. But it doesn't build with c++ gem.
the gcc(Travis CI) doesn't build with 'full-core'.

An error from Travis CI:

In file included from /home/travis/build/bggd/mrb-with-cpp/mruby/build/host/src/vm.cxx:7:0:

/home/travis/build/bggd/mrb-with-cpp/mruby/include/mruby/throw.h:50:18: error: previous declaration of ‘mrb_int mrb_jmpbuf::jmpbuf_id’ with ‘C++’ linkage

/home/travis/build/bggd/mrb-with-cpp/mruby/src/vm.c:2582:21: error: conflicts with new declaration with ‘C’ linkage

g++ -g -O3 -Wall -Werror-implicit-function-declaration -fexceptions -g3 -O0 -DMRB_ENABLE_CXX_EXCEPTION -DMRB_DEBUG -I"/home/travis/build/bggd/mrb-with-cpp/mruby/include" -I"/home/travis/build/bggd/mrb-with-cpp/mruby/src" -MMD -o "/home/travis/build/bggd/mrb-with-cpp/mruby/build/host/src/vm.cxx.o" -c "/home/travis/build/bggd/mrb-with-cpp/mruby/build/host/src/vm.cxx"

In file included from /home/travis/build/bggd/mrb-with-cpp/mruby/build/host/src/vm.cxx:7:0:

/home/travis/build/bggd/mrb-with-cpp/mruby/include/mruby/throw.h:50:18: error: previous declaration of ‘mrb_int mrb_jmpbuf::jmpbuf_id’ with ‘C++’ linkage

/home/travis/build/bggd/mrb-with-cpp/mruby/src/vm.c:2582:21: error: conflicts with new declaration with ‘C’ linkage

An error from AppVeyor:

"link.exe" /NOLOGO /DEBUG /INCREMENTAL:NO /OPT:ICF /OPT:REF /OUT:"C:\projects\mrb-with-cpp\mruby\build\host\bin\mrbtest.exe" "C:\projects\mrb-with-cpp\mruby\build\host\mrbgems\mruby-test\driver.obj" "C:\projects\mrb-with-cpp\mruby\build\host\mrbgems\mruby-test\mrbtest.obj" "C:\projects\mrb-with-cpp\mruby\build\host\mrbgems\mruby-test\mrbtest.lib" "C:\projects\mrb-with-cpp\mruby\build\host\lib\libmruby_core.lib" "C:\projects\mrb-with-cpp\mruby\build\host\lib\libmruby.lib"   libmruby.lib(cxxgem.obj) : error LNK2019: unresolved external symbol "struct RClass * __cdecl mrb_class_get(struct mrb_state *,char const *)" (?mrb_class_get@@YAPEAURClass@@PEAUmrb_state@@PEBD@Z) referenced in function mrb_dummy_cxxgem_gem_init
libmruby.lib(cxxgem.obj) : error LNK2019: unresolved external symbol "struct mrb_value __cdecl mrb_funcall(struct mrb_state *,struct mrb_value,char const *,int,...)" (?mrb_funcall@@YA?AUmrb_value@@PEAUmrb_state@@U1@PEBDHZZ) referenced in function mrb_dummy_cxxgem_gem_init
libmruby.lib(cxxgem.obj) : error LNK2019: unresolved external symbol "struct mrb_value __cdecl mrb_ary_new_capa(struct mrb_state *,int)" (?mrb_ary_new_capa@@YA?AUmrb_value@@PEAUmrb_state@@H@Z) referenced in function mrb_dummy_cxxgem_gem_init
C:\projects\mrb-with-cpp\mruby\build\host\bin\mrbtest.exe : fatal error LNK1120: 3 unresolved externals
libmruby.lib(cxxgem.obj) : error LNK2019: unresolved external symbol "struct RClass * __cdecl mrb_class_get(struct mrb_state *,char const *)" (?mrb_class_get@@YAPEAURClass@@PEAUmrb_state@@PEBD@Z) referenced in function mrb_dummy_cxxgem_gem_init
libmruby.lib(cxxgem.obj) : error LNK2019: unresolved external symbol "struct mrb_value __cdecl mrb_funcall(struct mrb_state *,struct mrb_value,char const *,int,...)" (?mrb_funcall@@YA?AUmrb_value@@PEAUmrb_state@@U1@PEBDHZZ) referenced in function mrb_dummy_cxxgem_gem_init
libmruby.lib(cxxgem.obj) : error LNK2019: unresolved external symbol "struct mrb_value __cdecl mrb_ary_new_capa(struct mrb_state *,int)" (?mrb_ary_new_capa@@YA?AUmrb_value@@PEAUmrb_state@@H@Z) referenced in function mrb_dummy_cxxgem_gem_init
C:\projects\mrb-with-cpp\mruby\build\host\bin\mrbtest.exe : fatal error LNK1120: 3 unresolved externals
Contributor

bggd commented Mar 2, 2017

I created a minimal C gem and C++ gem for testing build. https://github.com/bggd/dummy-c99gem https://github.com/bggd/dummy-cxxgem
I used this build_config.

MRuby::Build.new do |conf|

  if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
    toolchain :visualcpp
  else
    toolchain :gcc
    #conf.cxx.flags += %w(-pedantic-errors)
  end

  conf.gembox 'full-core'
  conf.gem :github => 'bggd/dummy-c99gem'
  conf.gem :github => 'bggd/dummy-cxxgem'

  conf.enable_debug

  conf.enable_test

  conf.enable_cxx_exception

end

I got error from Appveyor( https://ci.appveyor.com/project/bggd/mrb-with-cpp/build/1.0.8 ) and Travis CI ( https://travis-ci.org/bggd/mrb-with-cpp/builds/206944425 ).

the visualcpp(AppVeyor) can build with 'full-core'. But it doesn't build with c++ gem.
the gcc(Travis CI) doesn't build with 'full-core'.

An error from Travis CI:

In file included from /home/travis/build/bggd/mrb-with-cpp/mruby/build/host/src/vm.cxx:7:0:

/home/travis/build/bggd/mrb-with-cpp/mruby/include/mruby/throw.h:50:18: error: previous declaration of ‘mrb_int mrb_jmpbuf::jmpbuf_id’ with ‘C++’ linkage

/home/travis/build/bggd/mrb-with-cpp/mruby/src/vm.c:2582:21: error: conflicts with new declaration with ‘C’ linkage

g++ -g -O3 -Wall -Werror-implicit-function-declaration -fexceptions -g3 -O0 -DMRB_ENABLE_CXX_EXCEPTION -DMRB_DEBUG -I"/home/travis/build/bggd/mrb-with-cpp/mruby/include" -I"/home/travis/build/bggd/mrb-with-cpp/mruby/src" -MMD -o "/home/travis/build/bggd/mrb-with-cpp/mruby/build/host/src/vm.cxx.o" -c "/home/travis/build/bggd/mrb-with-cpp/mruby/build/host/src/vm.cxx"

In file included from /home/travis/build/bggd/mrb-with-cpp/mruby/build/host/src/vm.cxx:7:0:

/home/travis/build/bggd/mrb-with-cpp/mruby/include/mruby/throw.h:50:18: error: previous declaration of ‘mrb_int mrb_jmpbuf::jmpbuf_id’ with ‘C++’ linkage

/home/travis/build/bggd/mrb-with-cpp/mruby/src/vm.c:2582:21: error: conflicts with new declaration with ‘C’ linkage

An error from AppVeyor:

"link.exe" /NOLOGO /DEBUG /INCREMENTAL:NO /OPT:ICF /OPT:REF /OUT:"C:\projects\mrb-with-cpp\mruby\build\host\bin\mrbtest.exe" "C:\projects\mrb-with-cpp\mruby\build\host\mrbgems\mruby-test\driver.obj" "C:\projects\mrb-with-cpp\mruby\build\host\mrbgems\mruby-test\mrbtest.obj" "C:\projects\mrb-with-cpp\mruby\build\host\mrbgems\mruby-test\mrbtest.lib" "C:\projects\mrb-with-cpp\mruby\build\host\lib\libmruby_core.lib" "C:\projects\mrb-with-cpp\mruby\build\host\lib\libmruby.lib"   libmruby.lib(cxxgem.obj) : error LNK2019: unresolved external symbol "struct RClass * __cdecl mrb_class_get(struct mrb_state *,char const *)" (?mrb_class_get@@YAPEAURClass@@PEAUmrb_state@@PEBD@Z) referenced in function mrb_dummy_cxxgem_gem_init
libmruby.lib(cxxgem.obj) : error LNK2019: unresolved external symbol "struct mrb_value __cdecl mrb_funcall(struct mrb_state *,struct mrb_value,char const *,int,...)" (?mrb_funcall@@YA?AUmrb_value@@PEAUmrb_state@@U1@PEBDHZZ) referenced in function mrb_dummy_cxxgem_gem_init
libmruby.lib(cxxgem.obj) : error LNK2019: unresolved external symbol "struct mrb_value __cdecl mrb_ary_new_capa(struct mrb_state *,int)" (?mrb_ary_new_capa@@YA?AUmrb_value@@PEAUmrb_state@@H@Z) referenced in function mrb_dummy_cxxgem_gem_init
C:\projects\mrb-with-cpp\mruby\build\host\bin\mrbtest.exe : fatal error LNK1120: 3 unresolved externals
libmruby.lib(cxxgem.obj) : error LNK2019: unresolved external symbol "struct RClass * __cdecl mrb_class_get(struct mrb_state *,char const *)" (?mrb_class_get@@YAPEAURClass@@PEAUmrb_state@@PEBD@Z) referenced in function mrb_dummy_cxxgem_gem_init
libmruby.lib(cxxgem.obj) : error LNK2019: unresolved external symbol "struct mrb_value __cdecl mrb_funcall(struct mrb_state *,struct mrb_value,char const *,int,...)" (?mrb_funcall@@YA?AUmrb_value@@PEAUmrb_state@@U1@PEBDHZZ) referenced in function mrb_dummy_cxxgem_gem_init
libmruby.lib(cxxgem.obj) : error LNK2019: unresolved external symbol "struct mrb_value __cdecl mrb_ary_new_capa(struct mrb_state *,int)" (?mrb_ary_new_capa@@YA?AUmrb_value@@PEAUmrb_state@@H@Z) referenced in function mrb_dummy_cxxgem_gem_init
C:\projects\mrb-with-cpp\mruby\build\host\bin\mrbtest.exe : fatal error LNK1120: 3 unresolved externals

matz added a commit that referenced this issue Mar 2, 2017

@matz

This comment has been minimized.

Show comment
Hide comment
@matz

matz Mar 2, 2017

Member

@bggd thank you for the report. The recent commits (2d858ca and ffdf7be) should improve the situation.
Thanks again for your cooperation.

Member

matz commented Mar 2, 2017

@bggd thank you for the report. The recent commits (2d858ca and ffdf7be) should improve the situation.
Thanks again for your cooperation.

@bggd

This comment has been minimized.

Show comment
Hide comment
@bggd

bggd Mar 2, 2017

Contributor

@matz Thank you for the many improvements.
The build is successful on the Travis-CI and AppVeyor.

Contributor

bggd commented Mar 2, 2017

@matz Thank you for the many improvements.
The build is successful on the Travis-CI and AppVeyor.

@bggd bggd closed this Mar 2, 2017

@matz

This comment has been minimized.

Show comment
Hide comment
@matz

matz Mar 2, 2017

Member

@bggd Sorry for the troubles. I'm glad we have solved the problem finally.

Member

matz commented Mar 2, 2017

@bggd Sorry for the troubles. I'm glad we have solved the problem finally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment