Sign in to follow this  
ChaosEngine

std::string already declared...

Recommended Posts

arrrghh...I must be losing it. Having a really stupid problem, that's annoying the hell out of me. I have a class in a library that depends on std::string, so the lib author has included <string> in the class header. Problem is when I try to link the library in, I'm getting tonnes of std::string already declared linker errors. This is what comes of taking 3 months off from coding. I know it's something really simple...put me out of my misery

Share this post


Link to post
Share on other sites
Isn't this what #pragma once commands do? Something like forcing everything to be defined only one time?

I'm really a complete newb with stuff like this, but if you're linking with the lib and still including <string>, you could try removing your #include first, and see if that helps.

Share this post


Link to post
Share on other sites
Yeah, actually Boku San's suggestion seems to me like a good place to start. Can we see the header at all? What library is it? Alternatively, and though I very much doubt this would have an effect, you might look through your project headers to make sure you #pragma once'd or #ifndef HEADER_NAME...'d everything.

Share this post


Link to post
Share on other sites
Quote:
I have a class in a library that depends on std::string, so the lib author has included <string> in the class header. Problem is when I try to link the library in, I'm getting tonnes of std::string already declared linker errors.
Not sure I understand what's going on. Is the linker giving you duplicate symbol errors? How was the library distributed (source, shared, static)?

Share this post


Link to post
Share on other sites
Generally it can cause problems having templated classes such as std::string in the public interface of libraries.

The library writer should either wrap the string class in its own class for use with the public interface or use const char*.

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