Compilation issues GCC on linux


#1

Hi everyone!

I am trying to compile the first example with the following configuration:

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc-multilib/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib --disable-werror --enable-checking=release
Thread model: posix
gcc version 6.2.1 20160830 (GCC) 

(using gcc version 5.4.0 (GCC) yields the same result)

Using this command:
gcc main.cpp -I/path/to/chaiscript -std=c++14 -ldl

I am getting this error:

In file included from /path/to/chaiscript/chaiscript.hpp:828:0, from main.cpp:1:
/path/to/chaiscript/language/chaiscript_engine.hpp: In instantiation of ‘chaiscript::ChaiScript& chaiscript::ChaiScript::add(const T&, const string&) [with T = double (*)(int, double); std::__cxx11::string = std::__cxx11::basic_string<char>]’:
    main.cpp:9:33:   required from here
/path/to/chaiscript/language/chaiscript_engine.hpp:764:7: error: no matching function for call to ‘chaiscript::detail::Dispatch_Engine::add(double (* const&)(int, double), const string&)’
    m_engine.add(t_t, t_name);
    ^~~~~~~~

It happens on the develop branch as well as on the master.

I have no insight into the ChaiScript codebase, therefore I don’t dare to claim the error to be caused by ChaiScript or GCC. I hope however, that some of you, chaiscripters, will be able to uncover the root of this evil.


#2

It seems that the problem is in the example. Obviously, the function reference absolutely must be wrapped in chaiscript::fun().

Changing chai.add(&function, "function"); to chai.add(chaiscript::fun(&function), "function"); fixed the issue.