Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't compile example or link to chaiscript. #126

Closed
PhilCK opened this issue Aug 6, 2014 · 11 comments
Closed

Can't compile example or link to chaiscript. #126

PhilCK opened this issue Aug 6, 2014 · 11 comments

Comments

@PhilCK
Copy link

PhilCK commented Aug 6, 2014

Hi,

This might be more down to my ineptitude with the command line but I can't get the example given here working.

This was the exact command I used.

clang++ Main.cpp -I./ -ldl -std=c++11 -stdlib=libc++

Which produces the error.

chaiscript_engine.hpp:656:16: error: no matching member function for
call to 'add'

Also if I try to link to the lib with just an empty main().

clang++ Main.cpp -o foo -ldl -I./ -L./ -lchaiscript_stdlib-5.3.1 -std=c++11 -stdlib=libc++

I get the linker error

ld: can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB) file './/libchaiscript_stdlib-5.3.1.so' for architecture x86_64

Any ideas?

@lefticus
Copy link
Member

You should never try linking to the chaiscript stdlib, as the compiler is warning you about. ChaiScript is fundamentally a header-only toolkit. It also has the ability to use loadable modules, and it's possible to compile the standard library as one of those loadable modules.

I cannot give any input as to what might be going wrong without the exact code you were trying to compile (the thing you link to is a very old pull request with no example code in it). Also I need to know what version of ChaiScript you are attempting to use and what directory you are trying to compile from.

I suggest you start with making sure the official gist example compiles for you:

https://gist.github.com/lefticus/9190735#file-chaiscript_basic_example-cpp

@PhilCK
Copy link
Author

PhilCK commented Aug 13, 2014

I meant to link to this http://chaiscript.com/docs/5/index.html#compiling

Sorry I miss understood the doc, I thought I had to link to stdlib to speed up compiling.

@PhilCK PhilCK closed this as completed Aug 13, 2014
@lefticus
Copy link
Member

Just to clarify this ticket, now that it's closed:

The difference for compile time is to include the stdlib header or not to:

https://gist.github.com/lefticus/9190735#file-chaiscript_basic_example-cpp

vs

https://gist.github.com/lefticus/9456197

The first one compiles faster but requires that chaiscript be able to find the stdlib at runtime. The second one embeds the stdlib into the executable you are building.

Both use the exact same compilation options.

@PhilCK
Copy link
Author

PhilCK commented Aug 13, 2014

Yeah that was it, although in my little test (I wasn't timing) I didn't see much difference in compile time. Both instances showed a noticeable delay (nothing terrifying) from compiling the above example scripts with or without the stdlib header, I will do a more extensive test later this week.

This is the third language scripting language I've tested so far for a game project, and its been the easiest in almost every regard (other than my messup) :)

@lefticus
Copy link
Member

As the compiler grows and improve and CPU time improves, these little things do make less difference. With a project of any significant size, ChaiScript itself is likely to be only a tiny fraction of the compile time.

Just be aware of when and where you are including the ChaiScript headers and particularly try to avoid including the stdlib headers in very many places.

I have some ideas for how I might improve compile time overall, but have not yet had the chance to test those ideas.

@lefticus
Copy link
Member

I'm curious how slow is "extremely slow" in your project.

ChaiScript looks in its current directory and in a directory pointed to by the constructor for its standard lib:

https://github.com/ChaiScript/ChaiScript/blob/develop/include/chaiscript/language/chaiscript_engine.hpp#L465-L466

Which is documented here: http://chaiscript.com/docs/5/classchaiscript_1_1ChaiScript.html#a8e79e489433a52227f05206128e0e4a6 (available from the 'docs' page of http://chaiscript.com)

The problem with loading the standard library from a .dll is that it must be compiled with exactly the same settings as the rest of the application. This is a limitation of C++.

What I recommend, and use in my own projects, is a system where you have multiple files that each compile a different part of your ChaiScript usage. This leads to very fast (and parallelizable) builds that only rarely have to re-build.

See here: https://github.com/ChaiScript/Spiced

Look at the set of ChaiScript_* source files.

@lefticus
Copy link
Member

I believe you are mistaking ChaiScript's "stdlib" which is ChaiScript's core set of functions with the C++ standard library. The point is that you need to compile ChaiScript's standard library. it would be named something like chaiscript_stdlib-5.7.1.dll

If you are concerned about the longer term maintainability and compile time of a project using ChaiScript, please see the "Spiced" example I linked in the last answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@PhilCK @lefticus and others