Basic question about compiling Chaiscript with minGW g++


#1

I am trying to compile Chaiscript using g++ in the command line, but I am running into some issues that stem from my lack of understanding. I am trying to compile this simple test program:

#include <chaiscript/chaiscript.hpp>
#include <iostream>

int main()
{
	int x = 5;
	chaiscript::ChaiScript chai;
	chai.add(chaiscript::var(x), "x");
	chai.eval("print(x)");
	return 0;
}

However, I am met with this error having to do with the -ldl compiler flag:

C:\Users\Kai\Dropbox\progs>g++ -std=c++11 -o test test.cpp -I C:\chaiscript\incl
ude -ldl
c:/MinGW/bin/../lib/gcc/i686-w64-mingw32/5.3.0/../../../../i686-w64-mingw32/bin/
ld.exe: cannot find -ldl
collect2.exe: error: ld returned 1 exit status

What basic understanding of the library am I missing?


#2

-ldl is only needed on unix systems.

But you’ll also run into a problem that mingw is a bit buggy and you need to compile with at least -O1 to get it to build.