Sign in to follow this  
thewavelength

Using AngelScript namespace causes linker error (VC11)

Recommended Posts

thewavelength    109
Hello,

I'm using Visual Studio 2012 and MSVC11 and get linker errors when using RegisterStdString function from the string addon when I enable namespaces.
I don't know if this is also the case for older compiler versions.

Fails with two linker errors (RegisterStdString and RegisterStdStringUtils):
[source lang="cpp"]#define AS_USE_NAMESPACE

#include <angelscript.h>
#include <add_on/scriptstdstring/scriptstdstring.h>

using namespace AngelScript;

void test()
{
asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
RegisterStdString(engine);
RegisterStdStringUtils(engine);
}[/source]

Compiles like a charm:
[source lang="cpp"]#include <angelscript.h>
#include <add_on/scriptstdstring/scriptstdstring.h>

void test()
{
asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
RegisterStdString(engine);
RegisterStdStringUtils(engine);
}[/source]
Is this a bug or am I doing something wrong?
Thanks in advance!

Edit: The forum removes include paths for some reason.
These are the files included:

<angelscript.h>
<add_on/scriptstdstring/scriptstdstring.h>

Edit 2: Of course I'm compiling both scriptstdstring.cpp and scriptstdstring_utils.cpp. Edited by thewavelength

Share this post


Link to post
Share on other sites
TechRogue    722
I've never had to use the Angelscript namespace. The tutorials in the documentation use the same form as your second example, so you should be fine if you do it that way.

Share this post


Link to post
Share on other sites
WitchLord    4678
It's better to define AS_USE_NAMESPACE on the project settings, rather than in the code. Otherwise it is very easy to forget it in some places which makes part of the code refer to AngelScript functions without the namespace, and others with it, which is sure to cause linker errors.

In your case the namespace got declared when you included the scriptstdstring.h, thus the code sees the RegisterStdString() as part of the namespace. On the other hand, when the scriptstdstring.cpp was compiled the namespace was not declared, so RegisterStdString() was implemented outside the namespace.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this