std::string::npos LNK2001 in VS2010 when inheriting a dll class from std::string

Posted on Jan 11, 2011

The following two posts are discussing how to deal with a link error you see when you try to export a string class inherited from std::string. In the second post, some workarounds are also suggested.

  1. http://social.msdn.microsoft.com/Forums/en/vcpluslanguage/thread/4238e162-21d2-46f6-a8f1-e1191cf1b200 → This page suddenly disappeared. I attached here its cache from Google.
  2. https://connect.microsoft.com/VisualStudio/feedback/details/562448/std-string-npos-lnk2001-when-inheriting-a-dll-class-from-std-string?wa=wsignin1.0

If those workarounds do not work for you, you can try to link your binary to old libraries. Open the General Property Page of the project and set Platform Toolset to v90, instead of v100. → This works only if you installed Visual Studio 2008 as well.

I did some more experiments and found that the order of header files in the include statements do something with this. Sometimes the error disappears by just rearranging the order of headers. If it doesn’t work, try turning off the precompiled header option in the library exporting the string class.