How do I get ChaiScript to run under Linux and Windows with CMake?

350 Views Asked by At

I am working on a Student Project and we want to use ChaiSript (6.1) as scripting Language. We are using CLion and CMake on Linux and Windows. Also we are using SFML, so the whole thing has to be compiled with minGW 7.3.0 on Windows.

I created a Test-Project under Linux (gcc 9.2.0 and c++ 17) and got the following Linker errors:

/usr/bin/ld: CMakeFiles/ChaiScriptTest.dir/main.cpp.o: in function `chaiscript::detail::Loadable_Module::DLModule::DLModule(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/felix/Workspaces/CLion/ChaiScriptTest/ChaiScript-6.1.0/include/chaiscript/language/chaiscript_posix.hpp:19: undefined reference to `dlopen'
/usr/bin/ld: /home/felix/Workspaces/CLion/ChaiScriptTest/ChaiScript-6.1.0/include/chaiscript/language/chaiscript_posix.hpp:23: undefined reference to `dlerror'
/usr/bin/ld: CMakeFiles/ChaiScriptTest.dir/main.cpp.o: in function `chaiscript::detail::Loadable_Module::DLModule::~DLModule()':
/home/felix/Workspaces/CLion/ChaiScriptTest/ChaiScript-6.1.0/include/chaiscript/language/chaiscript_posix.hpp:34: undefined reference to `dlclose'
/usr/bin/ld: CMakeFiles/ChaiScriptTest.dir/main.cpp.o: in function `chaiscript::ChaiScript_Basic::ChaiScript_Basic(std::shared_ptr<chaiscript::Module> const&, std::unique_ptr<chaiscript::parser::ChaiScript_Parser_Base, std::default_delete<chaiscript::parser::ChaiScript_Parser_Base> >&&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::vector<chaiscript::Options, std::allocator<chaiscript::Options> > const&)':
/home/felix/Workspaces/CLion/ChaiScriptTest/ChaiScript-6.1.0/include/chaiscript/language/chaiscript_engine.hpp:293: undefined reference to `dladdr'
/usr/bin/ld: CMakeFiles/ChaiScriptTest.dir/main.cpp.o: in function `chaiscript::detail::Loadable_Module::DLSym<std::shared_ptr<chaiscript::Module> (*)()>::DLSym(chaiscript::detail::Loadable_Module::DLModule&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
/home/felix/Workspaces/CLion/ChaiScriptTest/ChaiScript-6.1.0/include/chaiscript/language/chaiscript_posix.hpp:44: undefined reference to `dlsym'
/usr/bin/ld: /home/felix/Workspaces/CLion/ChaiScriptTest/ChaiScript-6.1.0/include/chaiscript/language/chaiscript_posix.hpp:48: undefined reference to `dlerror'
/usr/bin/ld: CMakeFiles/ChaiScriptTest.dir/main.cpp.o: in function `std::thread::thread<std::__future_base::_Async_state_impl<std::thread::_Invoker<std::tuple<std::function<chaiscript::Boxed_Value ()> > >, chaiscript::Boxed_Value>::_Async_state_impl(std::thread::_Invoker<std::tuple<std::function<chaiscript::Boxed_Value ()> > >&&)::{lambda()#1}, , void>(std::__future_base::_Async_state_impl<std::thread::_Invoker<std::tuple<std::function<chaiscript::Boxed_Value ()> > >, chaiscript::Boxed_Value>::_Async_state_impl(std::thread::_Invoker<std::tuple<std::function<chaiscript::Boxed_Value ()> > >&&)::{lambda()#1}&&)':
/usr/include/c++/9.2.0/thread:126: undefined reference to `pthread_create'
collect2: Error: ld returned with value 1
make[3]: *** [CMakeFiles/ChaiScriptTest.dir/build.make:84: ChaiScriptTest] Error 1
make[2]: *** [CMakeFiles/Makefile2:76: CMakeFiles/ChaiScriptTest.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:88: CMakeFiles/ChaiScriptTest.dir/rule] Error 2
make: *** [Makefile:140: ChaiScriptTest] Error 2

All Errors are due to missing function References in chaisript_posix.hpp and chaiscript_engine.hpp to functions located in dlfcn.h. Except for the last one which has a problem in the thread class.

So, how do I fix this? Compiler on Linux is inrelevant but is has to work with MinGW 7.3.0.

What I have allready tried:

  • Using c++14 instead of c++17
  • Using Chaiscript Version 6.0 and 5.8.3 wtih and without c++14
  • Using clang
  • compiled without CMake on 6.1 and 5.8.3 with -ld- option set (also with and without c++17)

Here is my CMakeLists.txt:

cmake_minimum_required(VERSION 3.15)
project(ChaiScriptTest)

set(CMAKE_CXX_STANDARD 17)

include_directories(ChaiScript-6.1.0/include)


add_executable(ChaiScriptTest main.cpp)

and my main.cpp File:

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

int main() {
    chaiscript::ChaiScript chaiScript_;

    chaiScript_.eval("print(\"Hi\");");

    std::cout << "Hello ChaiScript" << std::endl;

    return 0;
}

Thanks in advance.

1

There are 1 best solutions below

0
On

Nevermind, I fixed the problem myself...

I looked into the documentation and found that Jason Turner already thoungt of this.

chai.add(chaiscript::fun(std::bind(&MacroEngine::setIgnoredMod, me, std::placeholders::_1)), "setIgnoredMods");

if you change the same line to

chai.add(chaiscript::fun(&MacroEngine::setIgnoredMod, &me), "setIgnoredMod");