2

Im getting an error every time I try to debug this with Visual C++ 2008

#include <iostream>
#include <vector>
#include <string>
#include <fstream>

using namespace std;

void load(const char* filename) {
    vector <string*> vec;
    ifstream in(filename);
    char buffer[256];
    while(!in.eof()) {
        in.getline(buffer, 256);
        vec.push_back(new std::string(buffer));
    }
}

int main(int argc, char* args[]) {
    cin.get();
    return 0;
}

get this error

Compiling...
main.cpp
Linking...
main.obj : error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: __thiscall std::_Vector_const_iterator,class std::allocator > *,class std::allocator,class std::allocator > *> >::_Vector_const_iterator,class std::allocator > *,class std::allocator,class std::allocator > *> >(class std::basic_string,class std::allocator > * *,class std::_Container_base_secure const *)" (??0?$_Vector_const_iterator@PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@PAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@QAE@PAPAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@PBV_Container_base_secure@1@@Z)
E:\blabla\Debug\test2.exe : fatal error LNK1120: 1 unresolved externals

what am I doing wrong?

techbech
  • 3,754
  • 5
  • 20
  • 28

1 Answers1

4

It looks as though you're building a debug version of your project but you're linking against the non-debug version of the C-Runtime DLL. You can check this in:

[Project] -> Properties -> C/C++ --> Code Generation --> Runtime Library

The runtime library should be listed as: "Multi-threaded Debug DLL (/MDd)" for a debug build.

You should actually find that the project builds just fine as "Release" since CrtDbgReportW is not called by std::vector in release builds and hence doesn't need to find that symbol at link time.

Benj
  • 31,668
  • 17
  • 78
  • 127
  • It did work fine with release! Thanks! Can you tell me the different og link me some stuff with the different between debug and release? Becuase I've never run with release before. – techbech Sep 27 '12 at 19:33
  • 1
    @PeterBechP I don't have a link to hand, but the main difference is that debug binaries are not optimized meaning that they run more slowly but are easier to run through in the debugger. The compiler performs a whole array of optimizations on release binaries that make them tricky to debug (for example preventing you from setting break points in certain places or see certain values) – Benj Sep 27 '12 at 19:40
  • Okay. That made sense for me. But can i just use release for my projects then? :-) – techbech Sep 27 '12 at 20:38
  • @PeterBechP I strongly suggest that you do use a release build once you've finished development. Debug is however handy while you're making fixes, I regularly switch between the two. – Benj Sep 27 '12 at 21:01