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

C++ driver: executable with static ruby + static python #4

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

jmarrec
Copy link
Owner

@jmarrec jmarrec commented May 11, 2021

I doubt this is the end of the trouble at all, but I have a working executable that is self contained with ruby and python, and more complex bindings than originally

I create a model from the C++ side, add a ModelObject to it. Then run a ruby measure that renames that model, and creates another one. Then a python measure that renames the one created from ruby, and adds a third one.

I can move the executable on my disk, and it still works (the path to the measure.py/ measure.rb are harcoded, but that's the only thing it "loads" dynamically)

$ ./Test 
Hello from Ruby
Hello from PythonEngine::exec
Hello From Python
Ruby measure name: RubyTestMeasure
Hello from PythonEngine::exec
['/home/julien/.pyenv/versions/3.9.1/lib/python39.zip', '/home/julien/.pyenv/versions/3.9.1/lib/python3.9', '/home/julien/.pyenv/versions/3.9.1/lib/python3.9/lib-dynload', '/home/julien/.pyenv/versions/3.9.1/lib/python3.9/site-packages', '/home/julien/Software/Cpp_Swig_Ruby_Python_MCVE/python/']
Hello from PythonEngine::exec
Today is Tue May 11 21:52:06 2021
Hello from PythonEngine::eval
Created Object (Python __init__)
Python measure name: Python Test Measure
Starting out with a Model in C++ called: C++ Model
C++: starting with 1 objects
 * 0 = C++ object
========== START RUBY ==========
Ruby Model named: C++ Model
Ruby: Model has: 1 spaces
* 0 = C++ object
* 1 = Ruby Space
========== FINISHED RUBY ==========
C++: 2 objects
 * 0 = MODIFIED FROM RUBY
 * 1 = Ruby Space
========== START PYTHON ==========
Python Model named: Ruby Model
Python: 2 objects
 * 0 = MODIFIED FROM RUBY
 * 1 = Ruby Space
 * 2 = Python Space
========== FINISHED PYTHON ==========
After Running Ruby and Python: model is named Python Model
Op 'run' from script: A Ruby Op
Op 'run' from script: Op from Python
C++: 3 objects
 * 0 = MODIFIED FROM RUBY
 * 1 = MODIFIED FROM PYTHON
 * 2 = Python Space

lefticus and others added 16 commits March 22, 2021 20:20
…. evcentually I switched to gcc 7.5 since 10 wouldn't build)
… we don't have SwigDirector_Measure name clashing
… Add embedded files. Look for static python lib too. Add ability to turn off ruby

Ruby will currently fail to undefined reference to rb_hasFile and rb_require_embedded
…(swig generated) and initialized _mylib (the statically linked _mylib.a) and eval this embedded mylib.py

```bash
cmake -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON -DCMAKE_BUILD_TYPE:String=Debug -DBUILD_RUBY_BINDINGS:BOOL=OFF ..
```
Init_mylib doesn't work. it segfaults 
```
* thread #1, name = 'Test', stop reason = signal SIGSEGV: invalid address (fault address: 0x38)
    frame #0: 0x00005555558bdd17 Test`rb_usascii_encoding at encoding.c:1342:45
   1339	rb_encoding *
   1340	rb_usascii_encoding(void)
   1341	{
-> 1342	    return enc_table.list[ENCINDEX_US_ASCII].enc;
   1343	}
   1344	
   1345	int
```

So I'm trying to initialize all encodings etc, but I'm not getting anywhere. Trying to include GC_VALUE.hpp results in a multiple definition such as `[100%][2/2] Linking CXX executable Products/Test
FAILED: Products/Test 
: && /usr/bin/c++ -g  CMakeFiles/mylib_ruby.dir/ruby_wrapper/MeasureRUBY_wrap.cxx.o CMakeFiles/Test.dir/main.cpp.o CMakeFiles/Test.dir/PythonEngine.cpp.o CMakeFiles/Test.dir/RubyEngine.cpp.o CMakeFiles/Test.dir/embedded_scripting_wrap.cxx.o CMakeFiles/Test.dir/embedded_files.cxx.o -o Products/Test  Products/libmylib.a  Products/libruby_libs.a  /home/julien/.pyenv/versions/3.9.1/lib/python3.9/config-3.9-x86_64-linux-gnu/libpython3.9.a  Products/python/_mylib.a  -licui18n  -licuuc  -lgmp  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/libruby-static.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/enc/libenc.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/enc/libtrans.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/rmd160.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/generator.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/pty.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/coverage.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/objspace.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/fcntl.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/etc.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/bigdecimal.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/ripper.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/fiddle.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/md5.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/fiber.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/sha1.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/stringio.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/zlib.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/strscan.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/escape.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/bubblebabble.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/nonblock.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/cparse.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/console.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/dbm.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/openssl.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/wait.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/gdbm.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/date_core.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/sizeof.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/syslog.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/monitor.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/sdbm.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/nkf.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/digest.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/sha2.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/readline.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/continuation.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/pathname.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/socket.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/parser.a  /home/julien/.conan/data/openstudio_ruby/2.7.2/nrel/testing/package/8c98c8e7c8941d8bf2c5b65aa3303761e4c9336c/lib/ext/psych.a  /home/julien/.conan/data/openssl/1.1.0l/_/_/package/75e99b627c196b65c439728670655ec3c366b334/lib/libssl.a  /home/julien/.conan/data/openssl/1.1.0l/_/_/package/75e99b627c196b65c439728670655ec3c366b334/lib/libcrypto.a  -ldl  -lpthread  /home/julien/.conan/data/zlib/1.2.11/_/_/package/24a116b2ab4212d508978c9d35c6a171a9b73fee/lib/libminizip.a  /home/julien/.conan/data/zlib/1.2.11/_/_/package/24a116b2ab4212d508978c9d35c6a171a9b73fee/lib/libz.a  /home/julien/.conan/data/libyaml/0.2.5/_/_/package/75e99b627c196b65c439728670655ec3c366b334/lib/libyaml.a  /home/julien/.conan/data/libffi/3.3/_/_/package/75e99b627c196b65c439728670655ec3c366b334/lib/libffi.a  /home/julien/.conan/data/gdbm/1.18.1/_/_/package/000d6b046920d22f02cec11ec895b1b45927eb08/lib/libgdbm_compat.a  /home/julien/.conan/data/gdbm/1.18.1/_/_/package/000d6b046920d22f02cec11ec895b1b45927eb08/lib/libgdbm.a  /home/julien/.conan/data/readline/8.0/_/_/package/adcbf8ecbce351b257a7edb13a6afc81d2e5c6dd/lib/libhistory.a  /home/julien/.conan/data/readline/8.0/_/_/package/adcbf8ecbce351b257a7edb13a6afc81d2e5c6dd/lib/libreadline.a  /home/julien/.conan/data/termcap/1.3.1/_/_/package/75e99b627c196b65c439728670655ec3c366b334/lib/libtermcap.a  /home/julien/.conan/data/gmp/6.2.0/_/_/package/f18760887692af6dc18ffcc3bf0a48e1c02322ca/lib/libgmpxx.a  /home/julien/.conan/data/gmp/6.2.0/_/_/package/f18760887692af6dc18ffcc3bf0a48e1c02322ca/lib/libgmp.a  Products/libadditional_ruby_libs.a  -lanl  -lrt  -lcrypt  -lpthread  -ldl  -lutil  -lm  Products/libmylib.a && :
CMakeFiles/Test.dir/RubyEngine.cpp.o:(.bss+0x0): multiple definition of `swig::GC_VALUE::hash_id'
CMakeFiles/mylib_ruby.dir/ruby_wrapper/MeasureRUBY_wrap.cxx.o:(.bss+0x0): first defined here
CMakeFiles/Test.dir/RubyEngine.cpp.o:(.bss+0x8): multiple definition of `swig::GC_VALUE::lt_id'
CMakeFiles/mylib_ruby.dir/ruby_wrapper/MeasureRUBY_wrap.cxx.o:(.bss+0x8): first defined here
CMakeFiles/Test.dir/RubyEngine.cpp.o:(.bss+0x10): multiple definition of `swig::GC_VALUE::gt_id'
CMakeFiles/mylib_ruby.dir/ruby_wrapper/MeasureRUBY_wrap.cxx.o:(.bss+0x10): first defined here
CMakeFiles/Test.dir/RubyEngine.cpp.o:(.bss+0x18): multiple definition of `swig::GC_VALUE::eq_id'
CMakeFiles/mylib_ruby.dir/ruby_wrapper/MeasureRUBY_wrap.cxx.o:(.bss+0x18): first defined here
CMakeFiles/Test.dir/RubyEngine.cpp.o:(.bss+0x20): multiple definition of `swig::GC_VALUE::le_id'
CMakeFiles/mylib_ruby.dir/ruby_wrapper/MeasureRUBY_wrap.cxx.o:(.bss+0x20): first defined here
CMakeFiles/Test.dir/RubyEngine.cpp.o:(.bss+0x28): multiple definition of `swig::GC_VALUE::ge_id'
CMakeFiles/mylib_ruby.dir/ruby_wrapper/MeasureRUBY_wrap.cxx.o:(.bss+0x28): first defined here
CMakeFiles/Test.dir/RubyEngine.cpp.o:(.bss+0x30): multiple definition of `swig::GC_VALUE::pos_id'
CMakeFiles/mylib_ruby.dir/ruby_wrapper/MeasureRUBY_wrap.cxx.o:(.bss+0x30): first defined here
CMakeFiles/Test.dir/RubyEngine.cpp.o:(.bss+0x38): multiple definition of `swig::GC_VALUE::neg_id'
CMakeFiles/mylib_ruby.dir/ruby_wrapper/MeasureRUBY_wrap.cxx.o:(.bss+0x38): first defined here
CMakeFiles/Test.dir/RubyEngine.cpp.o:(.bss+0x40): multiple definition of `swig::GC_VALUE::inv_id'
CMakeFiles/mylib_ruby.dir/ruby_wrapper/MeasureRUBY_wrap.cxx.o:(.bss+0x40): first defined here
CMakeFiles/Test.dir/RubyEngine.cpp.o:(.bss+0x48): multiple definition of `swig::GC_VALUE::add_id'
CMakeFiles/mylib_ruby.dir/ruby_wrapper/MeasureRUBY_wrap.cxx.o:(.bss+0x48): first defined here
CMakeFiles/Test.dir/RubyEngine.cpp.o:(.bss+0x50): multiple definition of `swig::GC_VALUE::sub_id'
CMakeFiles/mylib_ruby.dir/ruby_wrapper/MeasureRUBY_wrap.cxx.o:(.bss+0x50): first defined here
CMakeFiles/Test.dir/RubyEngine.cpp.o:(.bss+0x58): multiple definition of `swig::GC_VALUE::mul_id'
CMakeFiles/mylib_ruby.dir/ruby_wrapper/MeasureRUBY_wrap.cxx.o:(.bss+0x58): first defined here
CMakeFiles/Test.dir/RubyEngine.cpp.o:(.bss+0x60): multiple definition of `swig::GC_VALUE::div_id'
CMakeFiles/mylib_ruby.dir/ruby_wrapper/MeasureRUBY_wrap.cxx.o:(.bss+0x60): first defined here
CMakeFiles/Test.dir/RubyEngine.cpp.o:(.bss+0x68): multiple definition of `swig::GC_VALUE::mod_id'
CMakeFiles/mylib_ruby.dir/ruby_wrapper/MeasureRUBY_wrap.cxx.o:(.bss+0x68): first defined here
CMakeFiles/Test.dir/RubyEngine.cpp.o:(.bss+0x70): multiple definition of `swig::GC_VALUE::and_id'
CMakeFiles/mylib_ruby.dir/ruby_wrapper/MeasureRUBY_wrap.cxx.o:(.bss+0x70): first defined here
CMakeFiles/Test.dir/RubyEngine.cpp.o:(.bss+0x78): multiple definition of `swig::GC_VALUE::or_id'
CMakeFiles/mylib_ruby.dir/ruby_wrapper/MeasureRUBY_wrap.cxx.o:(.bss+0x78): first defined here
CMakeFiles/Test.dir/RubyEngine.cpp.o:(.bss+0x80): multiple definition of `swig::GC_VALUE::xor_id'
CMakeFiles/mylib_ruby.dir/ruby_wrapper/MeasureRUBY_wrap.cxx.o:(.bss+0x80): first defined here
CMakeFiles/Test.dir/RubyEngine.cpp.o:(.bss+0x88): multiple definition of `swig::GC_VALUE::lshift_id'
CMakeFiles/mylib_ruby.dir/ruby_wrapper/MeasureRUBY_wrap.cxx.o:(.bss+0x88): first defined here
CMakeFiles/Test.dir/RubyEngine.cpp.o:(.bss+0x90): multiple definition of `swig::GC_VALUE::rshift_id'
CMakeFiles/mylib_ruby.dir/ruby_wrapper/MeasureRUBY_wrap.cxx.o:(.bss+0x90): first defined here
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.`
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

Successfully merging this pull request may close these issues.

2 participants