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

Comments

Projects
None yet
3 participants
@PhilCK

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

This comment has been minimized.

Member

lefticus commented Aug 12, 2014

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

This comment has been minimized.

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 Aug 13, 2014

@lefticus

This comment has been minimized.

Member

lefticus commented Aug 13, 2014

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

This comment has been minimized.

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

This comment has been minimized.

Member

lefticus commented Aug 13, 2014

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.

@AndrewDavis

This comment has been minimized.

AndrewDavis commented Jul 21, 2015

"but requires that chaiscript be able to find the stdlib at runtime"
How do we ensure that? I would very much like to get rid of this extremely slow compilation. I'm using Visual Studio 2013 Community Edition. None of your examples, documentation, or other help provide any such information on how this works. Thanks.

@lefticus

This comment has been minimized.

Member

lefticus commented Jul 21, 2015

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.

@AndrewDavis

This comment has been minimized.

AndrewDavis commented Jul 21, 2015

Somewhere around a minute for a project that consists of only ChaiScript, on a decently fast computer where normally compilation takes at most a few seconds for an empty project. What's really killer about it though is that this happens every time I compile, whether I've changed anything or not.

I'll look into this and get back to you if I can't get it working, thanks.

@AndrewDavis

This comment has been minimized.

AndrewDavis commented Jul 22, 2015

I can't get it working. I tried chai(vector({ "C:\Windows\System32" })) (in an initializer list), which is where the standard library DLL is located. Why can't ChaiScript just use stdlib.h? I feel like something like this would be far less murderous of a solution. Also, why does ChaiScript and/or the stdlibrary with it have to recompile every time I run my program in Visual Studio?

@lefticus

This comment has been minimized.

Member

lefticus commented Jul 22, 2015

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.

@AndrewDavis

This comment has been minimized.

AndrewDavis commented Jul 25, 2015

Okay, finally got it much faster, thank you. It only takes about 26 seconds now, if I change the code. I placed the DLL in the same directory, and it worked right away without the StdLib. I would really like to be able to link the DLL statically though, as I would like for this to be one portable executable file. Is this possible, and how would I do so? Erm wait, I guess that's what the StdLib header file will do for me... Nevermind...

It was actually originally taking about 85 seconds to compile, by the way, and it didn't seem to change whether I used the DLL or StdLib.

For those who are in my shoes, here's the code I used for Visual Studio Community 2013:

ChaiScriptCreate.h:

#ifndef CHAISCRIPTCREATE
#define CHAISCRIPTCREATE

#include <memory>

using namespace std;

namespace chaiscript
{
    class ChaiScript;
}

unique_ptr<chaiscript::ChaiScript> CreateChaiScript();

#endif

ChaiScriptCreate.cpp:

#include "ChaiScriptCreate.h"
#include "chaiscript\chaiscript.hpp"

using namespace chaiscript;

unique_ptr<ChaiScript> CreateChaiScript()
{
    unique_ptr<ChaiScript> chai = make_unique<ChaiScript>();

    return chai;
}

"Wherever you use it".h:

#include "chaiscript\chaiscript.hpp"
#include "ChaiScriptCreate.h"

using namespace chaiscript;

unique_ptr<ChaiScript> chai;

"Wherever you use it".cpp:

chai = CreateChaiScript();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment