I'm learning genetic algorithms and am having a linking error. The code compiles fine, but something is wrong with the linking part. I pruned out all the unneeded code. The problems somewhere in the function void init_population(ga_vector &population). I'm using Visual C++ 2008.
I've removed everything except the bare frame for SDL and am still get the linking error.
1>main.obj : error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: __thiscall std::_Vector_const_iterator<struct ga_struct,class std::allocator<struct ga_struct> >::_Vector_const_iterator<struct ga_struct,class std::allocator<struct ga_struct> >(struct ga_struct *,class std::_Container_base_secure const *)" (??0?$_Vector_const_iterator@Uga_struct@@V?$alloca tor@Uga_struct@@@std@@@std@@QAE@PAUga_struct@@PBV_ Container_base_secure@1@@Z)
fatal error LNK1120: 1 unresolved externals
I've googled LNK1120 and it is sometimes a problem with the prototypes. I've tried a lot of different combinations, but haven't had any luck.Code:
#include <SDL.h>
#include <string>
#include <vector>
#define GA_POPSIZE 2048 // ga population size
#define GA_MOVES 80 // movement points
struct ga_struct
{
std::string str;
unsigned int fitness;
float matingPossibility;
};
typedef std::vector<ga_struct> ga_vector;
void init_population(ga_vector &population)
{
int moves = GA_MOVES * 2;
int pSize = GA_POPSIZE;
for(int i = 0; i < pSize; i++)
{
ga_struct citizen;
citizen.fitness = 0;
citizen.matingPossibility = 0.0f;
citizen.str.erase();
for(int j = 0; j < moves; j++)
citizen.str += (rand()%2) + 48;
population.push_back(citizen);
}
}
int main( int argc, char* args[] )
{
//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
ga_vector pop_alpha;
init_population(pop_alpha);
//Quit SDL
SDL_Quit();
return 0;
}
Thanks for reading over it.