Using AngelScript namespace causes linker error (VC11)

Started by
2 comments, last by thewavelength 11 years, 7 months ago
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.
Advertisement
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.
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.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Wow. So obvious and I was blind, but now I see. Thanks!

This topic is closed to new replies.

Advertisement