1

I'm trying to use the std::string object but I always get LNK2019 error. The projects builds a DLL, this is the code:

st.h

#pragma once

#ifndef ST_
#define ST_

#ifdef _WIN32
#define STDLL __declspec(dllexport)   
#else
#define STDLL
#endif

extern "C" STDLL int test();

#endif

st.cpp

#pragma once

#include "st.h"

#include <stdio.h>
#include <string>

using namespace std;
int test() {
  string test = "test string";
  return 10;
}

And this is the build error I get:

1>st.obj : error LNK2019: unresolved external symbol "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) referenced in function "void * __cdecl std::_Allocate<struct std::_Default_allocate_traits<1> >(unsigned int,unsigned int,unsigned int)" (??$_Allocate@U?$_Default_allocate_traits@$00@std@@@std@@YAPAXIII@Z)
1>st.obj : error LNK2019: unresolved external symbol "void __cdecl operator delete(void *,unsigned int)" (??3@YAXPAXI@Z) referenced in function "void __cdecl std::_Deallocate(void *,unsigned int,unsigned int,unsigned int)" (?_Deallocate@std@@YAXPAXIII@Z)
1>st.obj : error LNK2001: unresolved external symbol ___std_terminate
1>st.obj : error LNK2019: unresolved external symbol __imp___invalid_parameter referenced in function "void * __cdecl std::_Allocate<struct std::_Default_allocate_traits<1> >(unsigned int,unsigned int,unsigned int)" (??$_Allocate@U?$_Default_allocate_traits@$00@std@@@std@@YAPAXIII@Z)
1>st.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Lockit::_Lockit(int)" (__imp_??0_Lockit@std@@QAE@H@Z) referenced in function "public: void __thiscall std::_Container_base12::_Orphan_all(void)" (?_Orphan_all@_Container_base12@std@@QAEXXZ)
1>st.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Lockit::~_Lockit(void)" (__imp_??1_Lockit@std@@QAE@XZ) referenced in function "public: void __thiscall std::_Container_base12::_Orphan_all(void)" (?_Orphan_all@_Container_base12@std@@QAEXXZ)
1>st.obj : error LNK2019: unresolved external symbol _memcpy referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Reallocate_for<class <lambda_9366063389c5f42a00a5088cf24e69de>,char const *>(unsigned int,class <lambda_9366063389c5f42a00a5088cf24e69de>,char const *)" (??$_Reallocate_for@V<lambda_9366063389c5f42a00a5088cf24e69de>@@PBD@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@IV<lambda_9366063389c5f42a00a5088cf24e69de>@@PBD@Z)
1>st.obj : error LNK2019: unresolved external symbol _memmove referenced in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::assign(char const * const,unsigned int)" (?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@QBDI@Z)
1>st.obj : error LNK2019: unresolved external symbol _strlen referenced in function "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const * const)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@QBD@Z)
1>st.obj : error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "void * __cdecl std::_Allocate<struct std::_Default_allocate_traits<1> >(unsigned int,unsigned int,unsigned int)" (??$_Allocate@U?$_Default_allocate_traits@$00@std@@@std@@YAPAXIII@Z)
1>st.obj : error LNK2019: unresolved external symbol "void __cdecl std::_Xbad_alloc(void)" (?_Xbad_alloc@std@@YAXXZ) referenced in function "public: static void __cdecl std::_Default_allocate_traits<1>::_Fail(void)" (?_Fail@?$_Default_allocate_traits@$00@std@@SAXXZ)
1>st.obj : error LNK2019: unresolved external symbol "void __cdecl std::_Xlength_error(char const *)" (?_Xlength_error@std@@YAXPBD@Z) referenced in function "public: static void __cdecl std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Xlen(void)" (?_Xlen@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@SAXXZ)
1>st.obj : error LNK2019: unresolved external symbol ___CxxFrameHandler3 referenced in function __ehhandler$_test
1>LINK : error LNK2001: unresolved external symbol __load_config_used

I have tried building the solution in release but nothing seems to work, I have no idea about where the problem can be

0 Answers0