Static Library and C ++ Platform Compatibility

I recently created an old C ++ library in Visual Studio 2008. In this project, I used some class methods std::string. Now I want to use this library in a Visual Studio 2013 project.

The problem is this:
Both versions of Visual Studio use different platform tools, and the project will not compile due to linker errors, such as:

Error 4 LNK2001 errors: unresolved external character "__declspec (dllimport) public: __thiscall std :: basic_string, class std :: allocator> :: basic_string, class std :: allocator> (void)" (__imp _ ?? 0? $ Basic_string @DU? $ Char_traits @D @ stand @@ V? $ Distributor @D @ 2 @@ stand @@ QAE @XZ)

Is there a way to make the library compatible with all platform tools and use some standard classes, for example std::string?

FYI: VS2008 uses the v90 platform toolkit, and VS2013 uses the v120 platform toolkit.

Thank.

Edit:

If I use some standard methods in the library, for example std::vector, I can no longer implement the library.

It works:

unsigned int TestClass::TestMethod()
{   
    return 2;
}

It does not mean:

unsigned int TestClass::TestMethod()
{
    std::vector<unsigned char> vtest;
    vtest.push_back(0xff);

    return 2;
}

Error:

1 LNK2019: "public: static void __cdecl std:: _ String_base:: _ Xran (void)" (? _Xran @_String_base @std @@SAXXZ), "public: class :: basic_string, std:: allocator > __thiscall std:: basic_string, class std:: allocator > :: assign ( :: basic_string, std:: allocator > const &, unsigned int, unsigned int)" (? @? $Basic_string @DU? $Char_traits @D @ @@V? $ @D @2 @@ @@QAEAAV12 @ABV12 @II @Z)

RT lib /MT, whloe (/GL).

?

.

+4
3

:

dll .

, (/GL) /MT/MD.

dll, "Dynamic Linked Library (.dll)" __declspec(dllexport) , :

#define TEST_EXPORT
#ifdef TEST_EXPORT
#define TEST __declspec(dllexport) 
#else
#define TEST __declspec(dllimport) 
#endif


class TestClass
{
public:
    std::string TEST TestMethod(); 
};
0

, , :

  • (/MT /MD options)

  • /GL (.. )

+3

, , , :

std () . . .

, , , .

std:: ( ) , .

:

  • , :

    unsigned int TestClass::TestMethod()
    {
        std::vector<unsigned char> vtest;
        vtest.push_back(0xff);
    
        return 2;
    }
    
  • , + :

    unsigned int TestClass::Test2(std::vector<unsigned char> const& vparam)
    {
        vparam.push_back(0xff);
    
        return 2;
    }
    
  • :

    class TestClass {
      std::vector<int> m_buffer;
      ...
    };
    

, DLL, , , , ( dllexport - .)

Note that the technical problem itself is exactly the same for a DLL as it is for a static LIB. Ie, you cannot use any types stdin the interface of your DLL / LIB, which includes at least:

  • class members (even private)
  • (whether you pass by value, by reference or by pointer)
  • returns function values
+1
source

All Articles