Help compiling chaiscript_stdlib DLL with MinGW 5.1.0 and Qt


#1

Hi!
I am using Qt Creator with Qt 5.5.0 and MinGW with GCC 5.1.0 on Windows 10 x64. The ChaiScript version is 5.7.1.
I have tried compiling the examples of chaiscript; although the compilation process goes fine with both the basic and the ChaiScript Compiled in Stdlib example, the compiled executable will always fail loading the chaiscript_stdlib dll. most of times it will fail with:

Starting D:\Documents\Qt\Builds\ChaiScript_Test-x32\debug\ChaiScript_Test.exe...
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
D:\Documents\Qt\Builds\ChaiScript_Test-x32\debug\ChaiScript_Test.exe exited with code 255

The debugger adds this info:

terminate called after throwing an instance of 'chaiscript::exception::load_module_error'
what():  Unable to find module: chaiscript_stdlib-5.7.1 Errors: Impossibile trovare il modulo specificato.

Can someone please give me some instructions on how to compile the chaiscript_stdlib dll? or some other advice that would make chaiscript work with MinGW?
BTW I have both MinGW32 and MinGW64, and I would like it to work on both


#2

Let’s start with making sure that you can get the compiled-in version working.

That should absolutely work out-of-the-box with no special configuration needed or .dll files. Can you verify what the compiled-in project source code you are compiling looks like?

-Jason


#3

first of all, an update on the compilation process. For some reason, when I #include chaiscript/chaiscript_stdlib.hpp it will now refuse to compile and give the error “Too many sections (37703)”. I tried passing the arguments -Wa -mbig-obj to the compiler (in qmake you can pass them in the QMAKE_CXXFLAGS) like some people suggested on the web, but -mbig-obj is not recognized (also, gcc --help does not list any -mbig-obj flag). Before today I somehow could get rid of this error by simply recompiling a few times (don’t ask me why it worked - I have no idea), but now the trick does not work anymore.

Anyway, are you asking me to check/post the C++ code? Or the disassembled code? The C++ code though is exactly the one 2nd one posted in the chaiscript examples.

BTW I have also installed CMake (3.0.1) and set it up in Qt Creator’s settings, if that’s of any help.


#4

UPDATE

I have managed to get it started, both inside and outside of Qt Creator.
I have manually compiled chaiscript_stdlib like this:

g++ "D:/DevTools/ChaiScript-5.7.1/src/chaiscript_stdlib.cpp" -o "D:/cstest/chaiscript_stdlib.dll" -shared -v -std=c++0x -Wp,-I"D:/DevTools/ChaiScript-5.7.1/include" -Wa,-mbig-obj

When compiling the 1st example in Qt Creator, copying the chaiscript_stdlib-5.7.1.dll file to the exe directory, and running it, it will show the message “Hello Bob”. But then it will crash with a segmentation fault error on line 1915 of file hashtable.h.

When compiling the 1st example from command line like this:

g++ "D:/cstest/main.cpp" -o "D:/cstest/cstest.exe" -v -std=c++0x -Wp,-I"D:/DevTools/ChaiScript-5.7.1/include" -Wa,-mbig-obj -static

the exe will start, but it will fail to load chaiscript_stdlib-5.7.1.dll with the same “Unable to find module” error message that I posted in my first post.

So I am making progress, but still, not enough. I will now try to compile the second example (stdlib compiled in) and hope it will do something. However, I wanted to have that stdlib separated from my main exe…

EDIT
The compiled in example works just fine when compiled from command line. So the only thing now is to find out what crashes the application when running with external stdlib… any idea?

Re-EDIT
The above only seems to work for mingw32 (32 bit). The mingw64 (64-bit) compilation hangs on collect2.exe. It might be a bad compiler installation, but I’m quite sure the issue is somewhere else.


#5

In my experience you are seeing 2 diffferent bugs in the MinGW compiler.

  1. I’ve always had to compile with at least -O1 optimizations turned on to get the too many sections error to go away.
  2. It seems there is a bug in the implementation of thread_local in MinGW which is causing the crash on exit. To work around this you may have to compile with -DCHAISCRIPT_NO_THREADS, which disables support for using the same ChaiScript instance from multiple threads. (it also increases performance by ~20%)

I feel confident blaming MinGW for these issues because I don’t see either of them with any version of GCC on Linux, nor with Clang on MacOS/Linux nor on MSVC.

See also: https://github.com/ChaiScript/ChaiScript/issues/225#issuecomment-153414660


#6

I have tried compiling with -O1, -O2 and -O3, but still nothing. Disabling chaiscript thread safety didn’t help either. Actually I noticed something strange… the first 2 or 3 times that I start the compiled exes (when compiling the examples manually) Windows won’t report any crash. After a few attempts it will.

I am now installing VS2013 and hopefully I will get chaiscript working with no issues.


#7

That is extremely strange. I know several users are using some version of MinGW, but there are so many different versions to keep track of, and they all have bugs with threading issues.