Abort trap with SWIG for C++ and Lua -


i've been working first time swig in order create new lua modules c++. i'm working under mac os (el capitan). let me explain step step:

1) create .cpp file

int myaddition(int x, int y) {   return (x+y); }  int mysubtraction(int x, int y) {   return (x-y); } 

2) create interface file (.i):

%module test %{    extern int myaddition(int x, int y);    extern int mysubtraction(int x, int y); %}  extern int myaddition(int x, int y);  extern int mysubtraction(int x, int y); 

3) create wrapper , shared library following commands:

 swig -c++ -lua test.i  g++ -i/usr/local/include -c test_wrap.cxx -o test_wrap.o   g++ -c test.cpp -o test.o  g++ -bundle -l/usr/local/lib/ -llua test_wrap.o test.o -o test.so 

4) create .lua file test new module:

require("test") print(test.myaddition(10,40)) print(test.mysubtraction(20,40)) 

the output of script following:

50.0 -20.0 lua(21360,0x7fff7b739000) malloc: * error object 0x10d86b998: pointer being freed not allocated * set breakpoint in malloc_error_break debug abort trap: 6

if change script following:

require("test") print(test.myaddition(10,40)) print(test.mysubtraction(20,40)) os.exit() 

, seems fine:

[output] 50.0 -20.0

do spot problem, or necessary call os.exit() once script done?

edit: lua version 5.3.2. output of g++ -wl --verbose -bundle -i/usr/local/include/ -l/usr/local/lib/ -llua test_wrap.o test.o -o test.so following:

apple llvm version 7.0.2 (clang-700.1.81) target: x86_64-apple-darwin15.3.0 thread model: posix "/applications/xcode.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -bundle -macosx_version_min 10.11.0 -syslibroot /applications/xcode.app/contents/developer/platforms/macosx.platform/developer/sdks/macosx10.11.sdk -o test.so -l/usr/local/lib/ -llua test_wrap.o test.o -lc++ -lsystem /applications/xcode.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/../lib/clang/7.0.2/lib/darwin/libclang_rt.osx.a


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -