I'm having more linker errors...
We're now using vectors, and the instructions (for VS2008) say to set the libraries to MultiThreaded (MT) on the Debug configuration.
My code is below... we tried it out on a VS2008 computer and it worked:
#include "DarkGDK.h"
class Sprite
{
private:
std::vector<int> images;
int imageX, imageY;
static int counter;
public:
Sprite(int, char []);
Sprite(int, char [], int, int);
int display(int, int, int);
int displayToTarget(int, int, int);
int getImageNumber(int) const;
void setImageNumber(int, int);
int addImage(int, char []);
bool caught(Sprite);
static int count();
static void setCounter(int);
};
// boy.setImageNumber((x/20)%5+1);
int Sprite::counter = 0;
// The constructor
Sprite::Sprite(int image, char filename[])
{
images.push_back(image);
dbLoadImage(filename, image);
imageX = 0;
imageY = 0;
}
// The constructor overload
Sprite::Sprite(int image, char filename[], int x, int y)
{
images.push_back(image);
dbLoadImage(filename, image);
imageX = x;
imageY = y;
}
// add image
int Sprite::addImage(int image, char filename[])
{
images.push_back(image);
dbLoadImage(filename, image);
return images.size();
}
// This displays member function which displays the sprite
int Sprite::display(int x, int y, int index)
{
dbPasteImage( images[index], x, y );
imageX = x;
imageY = y;
return index;
}
int Sprite::displayToTarget(int x, int y, int index)
{
if (x > imageX)
{
imageX++;
}
else if (imageX > x)
{
imageX--;
}
if (y > imageY)
{
imageY++;
}
else if (imageY > y)
{
imageY--;
}
dbPasteImage( images[index], imageX, imageY);
return index;
}
// Accessor functions
int Sprite::getImageNumber(int index) const
{
return images[index];
}
// Mutator function
void Sprite::setImageNumber(int imageNum, int index)
{
images[index] = imageNum;
}
int Sprite::count()
{
return ++counter;
}
bool Sprite::caught(Sprite S2)
{
if ((imageX == S2.imageX) && (imageY == S2.imageY))
{
return true;
}
else return false;
}
void Sprite::setCounter(int newCount)
{
counter = newCount;
}
// The DarkGDK function
void DarkGDK()
{
DWORD white = dbRGB(255, 255, 255);
// create a sprite object
Sprite boy(1, "boy1.jpg");
boy.addImage(2, "boy2.jpg");
boy.addImage(3, "boy3.jpg");
boy.addImage(4, "boy4.jpg");
boy.addImage(5, "boy5.jpg");
Sprite car(6, "car.jpg", 500, 300);
Sprite boyInCar(7, "boyInCar.jpg");
dbSyncOn();
dbSyncRate(60);
int x = 0, y = 0;
while ( LoopGDK() ) // gameloop
{
dbCLS(white);
if (boy.caught(car))
{
boyInCar.display(dbMouseX(), dbMouseY(), 0);
}
else
{
x = Sprite::count();
car.display(dbMouseX(), dbMouseY(), 0);
boy.displayToTarget(dbMouseX(), dbMouseY(), ((x/20)%5));
}
dbSync();
}
}
However I get the following linker errors (on the troublesome LIBCMTD and MSVCRT... very frustrating!
)
1>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __heap_alloc already defined in LIBCMT.lib(malloc.obj)
1>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __recalloc already defined in LIBCMT.lib(recalloc.obj)
1>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __msize already defined in LIBCMT.lib(msize.obj)
1>LIBCMTD.lib(dbghook.obj) : error LNK2005: __crt_debugger_hook already defined in LIBCMT.lib(dbghook.obj)
1>LIBCMTD.lib(isctype.obj) : error LNK2005: __isctype_l already defined in LIBCMT.lib(isctype.obj)
1>LIBCMTD.lib(isctype.obj) : error LNK2005: __isctype already defined in LIBCMT.lib(isctype.obj)
1>MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
1>MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
1>LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>C:\Users\Steve\Documents\!SCHOOL\C++\UseThisTemplate\Debug\DarkGDK_TEST.exe : fatal error LNK1169: one or more multiply defined symbols found
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.51
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Can anyone please help me with this? These two libs have been causing issues for me for a while...