|
Prev: ACPP Exercise 4-2
Next: Extract directory from filename
From: Jonathan Campbell on 2 Jul 2008 11:34 I know I'm pushing my luck asking a question about a specific compiler and an API, but I've had a lot of help from this n.g. in the past and moreover, from what is written elsewhere, there is no obvious solution. The problem is that it does not appear to be able to link code that uses Simple DirectMedia Layer (SDL) with code that mentions std::vector; AFAIK, the same is true of std::list. Here is a minimal example. #include "SDL/SDL.h" #include <vector> #include <iostream> using namespace std; int main( int argc, char* args[] ) { vector<int> v; v.push_back(1); v.push_back(2); cout<< v[0]<< ' ' << v[1]<< endl; SDL_Init( SDL_INIT_EVERYTHING ); SDL_Quit(); return 0; } 1>start.obj : error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: int & __thiscall std::vector<int,class std::allocator<int> >::operator[](unsigned int)" (??A?$vector(a)HV?$allocator@H(a)std@@@std@@QAEAAHI@Z) 1>c:\lect\sdl\start\start\Debug\start.exe : fatal error LNK1120: 1 unresolved externals If I use copy(v.begin(), v.end(), ostream_iterator<int>(cout, " ")); then I get a similar complaint about _Vector_const_iterator. AFAIK, in the past, I have had complaints about vector::push_back (and this is mentioned in some of the questions on other websites). One solution, which is almost totally unacceptable, but which works, is to use my own versions of std::vector and std:: list. Incidentally, I primarily use Linux and GNU C++ (4.2 now) and here there are no problems. However, I teach on a Windows environment. If I cannot solve the problem, I'm going to have to consider specifying a different compiler (e.g. DevC++) for Windows. I have had students run experiment of VS 2005 (Prof. version) and the problem exists there too. Can anyone suggest a solution or an experiment which would shed further light? Best regards, Jon C.
From: Jim Langston on 2 Jul 2008 13:10 "Jonathan Campbell" <jg.campbell.ng(a)gmail.com> wrote in message news:hdNak.99$jB5.72(a)newsfe05.ams2... >I know I'm pushing my luck asking a question about a specific compiler and >an API, but I've had a lot of help from this n.g. in the past and moreover, >from what is written elsewhere, there is no obvious solution. > > The problem is that it does not appear to be able to link code that uses > Simple DirectMedia Layer (SDL) with code that mentions std::vector; AFAIK, > the same is true of std::list. > > Here is a minimal example. > > #include "SDL/SDL.h" > #include <vector> > #include <iostream> > > using namespace std; Hard to say, but it is likely that the above line might be causing conflicts between SDL.h and either <vector> or <iostream>. Easy enough to test. Comment out the above line and make the changes as below and see if it works. > int main( int argc, char* args[] ) { > vector<int> v; std::vector<int> v; > v.push_back(1); > v.push_back(2); > > cout<< v[0]<< ' ' << v[1]<< endl; std::cout << v[0] << ' ' << v[1] << std::endl; > SDL_Init( SDL_INIT_EVERYTHING ); > SDL_Quit(); > return 0; > } If the above works, you may consider leaving is is, or changing the using namespace std; to: using std::vector; using std::cout; using std::endl; > 1>start.obj : error LNK2019: unresolved external symbol > __imp___CrtDbgReportW referenced in function "public: int & __thiscall > std::vector<int,class std::allocator<int> >::operator[](unsigned int)" > (??A?$vector(a)HV?$allocator@H(a)std@@@std@@QAEAAHI@Z) > > 1>c:\lect\sdl\start\start\Debug\start.exe : fatal error LNK1120: 1 > unresolved externals > > If I use > > copy(v.begin(), v.end(), ostream_iterator<int>(cout, " ")); > > then I get a similar complaint about _Vector_const_iterator. > > AFAIK, in the past, I have had complaints about vector::push_back (and > this is mentioned in some of the questions on other websites). > > One solution, which is almost totally unacceptable, but which works, is to > use my own versions of std::vector and std:: list. > > Incidentally, I primarily use Linux and GNU C++ (4.2 now) and here there > are no problems. However, I teach on a Windows environment. If I cannot > solve the problem, I'm going to have to consider specifying a different > compiler (e.g. DevC++) for Windows. I have had students run experiment of > VS 2005 (Prof. version) and the problem exists there too. > > Can anyone suggest a solution or an experiment which would shed further > light? > > Best regards, > > Jon C.
From: Jonathan Campbell on 2 Jul 2008 13:24 Jim Langston wrote: > "Jonathan Campbell" <jg.campbell.ng(a)gmail.com> wrote in message > news:hdNak.99$jB5.72(a)newsfe05.ams2... >> I know I'm pushing my luck asking a question about a specific compiler and >> an API, but I've had a lot of help from this n.g. in the past and moreover, >>from what is written elsewhere, there is no obvious solution. >> The problem is that it does not appear to be able to link code that uses >> Simple DirectMedia Layer (SDL) with code that mentions std::vector; AFAIK, >> the same is true of std::list. >> >> Here is a minimal example. >> >> #include "SDL/SDL.h" >> #include <vector> >> #include <iostream> >> >> using namespace std; > > Hard to say, but it is likely that the above line might be causing conflicts > between SDL.h and either <vector> or <iostream>. Easy enough to test. > Comment out the above line and make the changes as below and see if it > works. > Thanks. Tried that. Same error. Best regards, Jon C.
From: Jim Langston on 2 Jul 2008 14:22 "Jonathan Campbell" <jg.campbell.ng(a)gmail.com> wrote in message news:hdNak.99$jB5.72(a)newsfe05.ams2... >I know I'm pushing my luck asking a question about a specific compiler and >an API, but I've had a lot of help from this n.g. in the past and moreover, >from what is written elsewhere, there is no obvious solution. > > The problem is that it does not appear to be able to link code that uses > Simple DirectMedia Layer (SDL) with code that mentions std::vector; AFAIK, > the same is true of std::list. > > Here is a minimal example. > > #include "SDL/SDL.h" > #include <vector> > #include <iostream> Next try changing the above to: #include <vector> #include <iostream> #include "SDL/SDL.h" I.E.. Putting the include for SDL/SDL. last Did that fix the problem? The reason being because maybe... [SNIP] > 1>start.obj : error LNK2019: unresolved external symbol > __imp___CrtDbgReportW referenced in function "public: int & __thiscall > std::vector<int,class std::allocator<int> >::operator[](unsigned int)" > (??A?$vector(a)HV?$allocator@H(a)std@@@std@@QAEAAHI@Z) > > 1>c:\lect\sdl\start\start\Debug\start.exe : fatal error LNK1120: 1 > unresolved externals Maybe this CrtDbgReportW is defined or not defined by some flag that is being set in SDL/SDL.h. Who knows. Give it a try.
From: Jonathan Campbell on 2 Jul 2008 15:17
Jim Langston wrote: > "Jonathan Campbell" <jg.campbell.ng(a)gmail.com> wrote in message > news:hdNak.99$jB5.72(a)newsfe05.ams2... [...] > Next try changing the above to: > > #include <vector> > #include <iostream> > #include "SDL/SDL.h" > > I.E.. Putting the include for SDL/SDL. last Did that fix the problem? > > The reason being because maybe... > > [SNIP] >> 1>start.obj : error LNK2019: unresolved external symbol >> __imp___CrtDbgReportW referenced in function "public: int & __thiscall >> std::vector<int,class std::allocator<int> >::operator[](unsigned int)" >> (??A?$vector(a)HV?$allocator@H(a)std@@@std@@QAEAAHI@Z) >> >> 1>c:\lect\sdl\start\start\Debug\start.exe : fatal error LNK1120: 1 >> unresolved externals > > Maybe this CrtDbgReportW is defined or not defined by some flag that is > being set in SDL/SDL.h. Who knows. Give it a try. > > Thanks again, but nope, same error. Best regards, Jon C. |