0

I'm getting these errors:

1>test.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall     std::basic_ofstream<char,struct std::char_traits<char> >::`vbase destructor'(void)" (__imp_??_D?  $basic_ofstream@DU?$char_traits@D@std@@@std@@QAEXXZ) referenced in function _main
1>test.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall    std::basic_ofstream<char,struct std::char_traits<char> >::basic_ofstream<char,struct std::char_traits<char>>(void)" (__imp_??0?$basic_ofstream@DU?$char_traits@D@std@@@std@@QAE@XZ) referenced in function _main

This test code works fine:

int main(int argc, char **argv)
{
    std::ofstream game_record_output;
}

until I include a .h from an older project that was converted from VS 2003 .NET

Firstly I thought it could have some problem related with this:

http://msdn.microsoft.com/en-us/library/8h8eh904(v=vs.90).aspx

But then, I've already checked that just MSVCRT.LIB and MSVCPRT.LIB are being linked, so the old iostream is not being linked...

I'm not sure why this happen, I'm supposing that in include chain some wrong file is being included, but I've already search the include chain for the old iostream .h's files (i.e: (fstream.h, iomanip.h, ios.h, iostream.h, istream.h, ostream.h, streamb.h, and strstrea.h) )

So, is there anything else that I should check?

The project use MFC.

ildjarn
  • 62,044
  • 9
  • 127
  • 211
Vando
  • 179
  • 3
  • 9
  • 1
    The test code looks incomplete, by the way. Missing headers. – mloskot May 11 '12 at 11:01
  • Sorry about the headers, if I use this: #include it works as expected But then when I add one of mine dependencies that I'll need later, it starts to giving the linked erorrs – Vando May 11 '12 at 11:23

2 Answers2

0

Change your Visual Studio project Properties setting in C/C++ -> Code Generation -> Runtime Library according to this:

  • Multi-threaded Debug DLL (/MDd) for Debug configuration
  • Multi-threaded DLL (/MD) for Release configuration
mloskot
  • 37,086
  • 11
  • 109
  • 136
  • 1
    Check if the .h files you include do not set any pragma and do not import any C/C++ run-time libs. Rebuild. – mloskot May 11 '12 at 11:01
  • There are some like: #pragma comment(lib, "Msacm32.lib") and other libs that I've the source, should I look for some .lib in special? or any lib imported in this way, is a problem? Thank you! – Vando May 11 '12 at 11:13
  • 1
    I'm fairly sure there is problem with your settings in your solution/projects. Likely, your are linking against both static and DLL version of C/C++ run-time (libcpmt[d].lib vs msvcprt[d].lib), mixing /MT vs /MD or similar. I'd carefully inspect the projects first or even recreate project from scratch. – mloskot May 11 '12 at 11:25
  • I've found this warning "LINK : warning LNK4098: defaultlib 'MSVCRTD.LIB' conflicts with use of other libs;" How can I find the lib where the conflict occurs? – Vando May 11 '12 at 13:51
0

This page contains some causes for LNK2019: https://msdn.microsoft.com/en-us/library/799kze2z.aspx . Particularly, upgrade from VS 2003 could trigger this problem:

A build dependency is only defined as a project dependency in the solution. In earlier versions of Visual Studio, this level of dependency was sufficient. However, starting with Visual Studio 2010, Visual Studio requires a project-to-project reference. If your project does not have a project-to-project reference, you may receive this linker error. Add a project-to-project reference to fix it.

or this

You mix code that uses native wchar_t with code that doesn't. C++ language conformance work that was done in Visual C++ 2005 made wchar_t a native type by default. You must use the /Zc:wchar_t- compiler option to generate code compatible with modules compiled by using earlier versions of Visual C++. If not all modules have been compiled by using the same /Zc:wchar_t settings, type references may not resolve to compatible types. Verify that wchar_t types in all modules are compatible, either by updating the types that are used, or by using consistent /Zc:wchar_t settings when you compile.

Serge Rogatch
  • 13,865
  • 7
  • 86
  • 158