Jump to content
  • Advertisement
Sign in to follow this  
thewavelength

Using AngelScript namespace causes linker error (VC11)

This topic is 2215 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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.

Share this post


Link to post
Share on other sites
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!