Skip to main content
GameDev.net gamedev.net
🔒 Locked

Using AngelScript namespace causes linker error (VC11)

Started by thewavelength Sep 21, 2012 at 3:14 PM 2 replies 1.7k views
Original Post
thewavelength
thewavelength
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
#include

using namespace AngelScript;

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

Compiles like a charm:
[source lang="cpp"]#include
#include

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:




Edit 2: Of course I'm compiling both scriptstdstring.cpp and scriptstdstring_utils.cpp.
TechRogue
TechRogue
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.
WitchLord
WitchLord
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 - <a href="http://www.angelcode.com/tower" rel
thewavelength
thewavelength
Wow. So obvious and I was blind, but now I see. Thanks!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.