Sign in to follow this  
Mizipzor

Compiler errors

Recommended Posts

I dont understand what I should do, I get these errors:
------ Build started: Project: Temp2, Configuration: Debug Win32 ------

Linking...
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 LIBCD.lib(typinfo.obj)
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 LIBCD.lib(typinfo.obj)
msvcrt.lib(MSVCR71.dll) : error LNK2005: _exit already defined in LIBCD.lib(crt0dat.obj)
msvcrt.lib(MSVCR71.dll) : error LNK2005: _strncpy already defined in LIBCD.lib(strncpy.obj)
msvcrt.lib(MSVCR71.dll) : error LNK2005: _fprintf already defined in LIBCD.lib(fprintf.obj)
msvcrt.lib(MSVCR71.dll) : error LNK2005: _fopen already defined in LIBCD.lib(fopen.obj)
msvcrt.lib(MSVCR71.dll) : error LNK2005: _fgetc already defined in LIBCD.lib(fgetc.obj)
msvcrt.lib(MSVCR71.dll) : error LNK2005: _fclose already defined in LIBCD.lib(fclose.obj)
msvcrt.lib(MSVCR71.dll) : error LNK2005: _setvbuf already defined in LIBCD.lib(setvbuf.obj)
msvcrt.lib(MSVCR71.dll) : error LNK2005: __isctype already defined in LIBCD.lib(isctype.obj)
LIBCD.lib(crt0init.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
Debug/Temp2.exe : fatal error LNK1169: one or more multiply defined symbols found

Build log was saved at "file://d:\Documents\Cpp\Temp2\Debug\BuildLog.htm"
Temp2 - 11 error(s), 1 warning(s)


---------------------- Done ----------------------

    Build: 0 succeeded, 1 failed, 0 skipped



Heres the source if its any help: main.cpp
#include "SdlWrapper.h"
#include "AsciiMap.h"


int main (int argc, char *argv[]) {	
	//SdlWrapper Sdl(640, 480, 32);	// resolution and bit depth
	//AsciiMap AsciiMap(&Sdl);		// adress to the graphics class

	return 1;
}

SdlWrapper.h
#ifndef _SDL_WRAPPER
#define _SDL_WRAPPER

#include <SDL.h>
#include <conio.h>
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <map>
#include <fstream>

#include "Log.h"

class SdlWrapper {
private:
	void	Slock(SDL_Surface *screen);	// lock and unlock
	void	Sunlock(SDL_Surface *screen);
	void	DrawPixel(SDL_Surface *screen, int x, int y, Uint8 R, Uint8 G, Uint8 B);	// draw a single pixel
	
	SDL_Surface*	GetBmp(std::string texture)		{return Bmp[texture];}	// returns a texture

	std::map	<std::string, SDL_Surface*> Bmp;	// holds all the texture

	SDL_Surface *screen;	// the visible screen

	int		ResX; 
	int		ResY;		// the screen resolution

public:
			SdlWrapper(int resolutionX, int resolutionY, int depth);

	// bmp handling functions
	bool	LoadBmp(std::string filename);		// adds a texture to the texture map, return false on failure		
	void	DrawImg(std::string img, int x, int y);		// draws the image at those coordinates on the screen
	
	void	Flip()		{SDL_Flip(screen);}				// flips and updates the entire screen	
};

#endif

SdlWrapper.cpp
#include "SdlWrapper.h"

SdlWrapper::SdlWrapper(int resolutionX, int resolutionY, int depth) {
	// set the screen properties
	screen = SDL_SetVideoMode(resolutionX, resolutionY, depth, SDL_HWSURFACE|SDL_DOUBLEBUF);

	ResX = resolutionX;		// store the resolution in the class variables
	ResY = resolutionY;
}

SdlWrapper::~SdlWrapper() {
	SDL_Quit();
}

void SdlWrapper::DrawImg(std::string img, int x, int y) {	// draws the image at those coordinates on the screen
	SDL_Rect dest;
	dest.x = x;
	dest.y = y;
	SDL_BlitSurface(Bmp[img], NULL, screen, &dest);
}

bool SdlWrapper::LoadBmp(std::string filename) {
	std::stringstream str;
	str << "Sdl: Loading file " << filename << ".bmp";

	Bmp[filename] = SDL_LoadBMP( ("Bmp\\" + filename + ".bmp").c_str() );	// attempt to load the texture

	if(Bmp[filename] == NULL) {	// NULL, no image is there
		str << " FAILED: unable to load bmp file";
		Log::Write(str.str().c_str());
		return false;
	} // the image was loaded successfully, go on

	// setting transparency
	SDL_SetColorKey(Bmp[filename], SDL_SRCCOLORKEY, SDL_MapRGB(Bmp[filename]->format, 255, 0, 255));

	return true;
}

void SdlWrapper::DrawPixel(SDL_Surface *screen, int x, int y, Uint8 R, Uint8 G, Uint8 B) {
	Uint32 color = SDL_MapRGB(screen->format, R, G, B);
	switch (screen->format->BytesPerPixel) {
		case 1: // Assuming 8-bpp 
		{
			Uint8 *bufp;
			bufp = (Uint8 *)screen->pixels + y*screen->pitch + x;
			*bufp = color;
		}
		break;
		case 2: // Probably 15-bpp or 16-bpp 
		{
			Uint16 *bufp;
			bufp = (Uint16 *)screen->pixels + y*screen->pitch/2 + x;
			*bufp = color;
		}
		break;
		case 3: // Slow 24-bpp mode, usually not used 
		{
			Uint8 *bufp;
			bufp = (Uint8 *)screen->pixels + y*screen->pitch + x * 3;
			if(SDL_BYTEORDER == SDL_LIL_ENDIAN)
			{
			bufp[0] = color;
			bufp[1] = color >> 8;
			bufp[2] = color >> 16;
			} else {
			bufp[2] = color;
			bufp[1] = color >> 8;
			bufp[0] = color >> 16;
			}
		}
		break;
		case 4: // Probably 32-bpp 
		{
			Uint32 *bufp;
			bufp = (Uint32 *)screen->pixels + y*screen->pitch/4 + x;
			*bufp = color;
		}
		break;
	}
}

void SdlWrapper::Slock(SDL_Surface *screen) {
	if ( SDL_MUSTLOCK(screen) ) {
		if ( SDL_LockSurface(screen) < 0 ) {
		return;
		}
	}
}

void SdlWrapper::Sunlock(SDL_Surface *screen) {
	if ( SDL_MUSTLOCK(screen) ) {
		SDL_UnlockSurface(screen);
	}
}

AsciiMap.h
#ifndef ASCII_MAP_INCLUDED
#define ASCII_MAP_INCLUDED

// The ascii map class is responsible for loading/storing the ascii sets used by the graphic
// to know which tile to draw where.

#include <vector>
#include <map>
#include <windows.h>
#include <fstream>
#include <sstream>
#include <iostream>

#include "Log.h"
#include "Tile.h"
#include "SdlWrapper.h"

class AsciiMap {

private:

	int		SizeX;	// how many chars on each axis
	int		SizeY;
	std::vector <int> MapData;	// the vector for all the tiles (chars)
	std::map <int, Tile> TileData;	// holds the information for all the tiles, the data is accessed by the tile ID number

	SdlWrapper*	Sdl;		// so we can access Sdl stuff
	HANDLE		hConsole;	// so we can use set cursor position, for debugging

	void	WriteTo(std::ostream& target, int SizeX, int SizeY);	// writes the MapData vector to a file
	void	Gotoxy(int x, int y);				// sets the Console cursor to the specified coordinates
	void	Resize(int NewSizeX, int NewSizeY);	// resizes the MapData vector
	Tile*	GetTileData(int TileID);			// returns the tile with that ID
	bool	LoadTiles();						// loads all the tile data

public:
			// constructor
			AsciiMap(SdlWrapper* pSdl);	// needs a pointer to be able to draw graphic

	// World handling stuff ---
	bool	LoadMap(std::string filename);	// load a map into MapData from the specified filename from "Maps\..."

	// Console window functions for debugging ---
	void	ConsoleRenderWorld();			// draws all the chars to the screen

	// Tile stuff ---
	void	SetTile(int TileID, int x, int y);		// draws a char at the specified coords	
	Tile*	GetTile(int x, int y);					// return the tile at the coords given
	void	DrawSquare(int tile, int startX, int startY, int stopX, int stopY);	// same as a above but loops for an area

	// Tile Data stuff ---	
	bool	Collision(int x, int y);	// returns true if the tile is occupied
	int		GetSizeX() {return SizeX;}
	int		GetSizeY() {return SizeY;}	// returns the size of the map
};

#endif // ASCII_MAP_INCLUDED



AsciiMap.cpp
#include "AsciiMap.h"

AsciiMap::AsciiMap(SdlWrapper* pSdl) {
	// store the adress to the graphics class
	Sdl = pSdl;

    LoadTiles();	// load all the tiles
	
	hConsole = GetStdHandle(STD_OUTPUT_HANDLE);	// setup Console handles

	// write what we did to the log
	Log::Write("AsciiMap: Instance created successfully");
}

void AsciiMap::Resize(int NewSizeX, int NewSizeY) {
	SizeX = NewSizeX;	// how many tiles on each axis
	SizeY = NewSizeY;

	MapData.resize(SizeX * SizeY, 0);			// resize the vector and fill it with ?'s

	// write what we did to the log
	std::stringstream str;
	str << "AsciiMap: Class created, size: " << SizeX << " x " << SizeY;
	Log::Write(str.str().c_str());
}

void AsciiMap::SetTile(int TileID, int x, int y) {
	MapData[ ( y * SizeX ) + x ] = TileID;	// draw it
}

Tile* AsciiMap::GetTileData(int TileID) {
	if( TileData.find(TileID) == TileData.end() ) {	// if the TileID doesnt exist...
		return &TileData[0];	// return the black one

		std::stringstream str;	// report error to log
		str << "AsciiMap: ERROR: TileID " << TileID << " does not exist";
		Log::Write(str.str().c_str());
	}

	return &TileData[TileID];	// otherwise return the specified tile
}

void AsciiMap::DrawSquare(int tile, int startX, int startY, int stopX, int stopY) {
	for (int y = startY; y < stopY; y++) {
		for (int x = startX; x < stopX; x++) {
			SetTile(tile, x, y);
		}
	}
}

// Here's how we'll output an AsciiMap to an output stream:
void AsciiMap::WriteTo(std::ostream &target, int SizeX, int SizeY) {
	for(int y = 0; y < SizeY; y++) {
		for(int x = 0; x < SizeX; x++) {
			target << MapData[(y * SizeX) + x] << '\n';
		}
	}
}

bool AsciiMap::LoadTiles() {
	std::ifstream file("Data\\TileData.txt");
	std::stringstream str;

	// NAME	ID	BLOCK
	Tile TempTile;
	int Block;

	while(1) {
		if(file.eof())				// have we read all the data yet?
			break;

		file >> TempTile.TileID;
		file >> TempTile.Name;		// read all the data
		file >> Block;

		if( Block == 1 )			// in the file its binary, we want a bool
			TempTile.Block = true;
		else
			TempTile.Block = false;

		TileData[TempTile.TileID] = TempTile;	// after we know all about the new tile, add it to the std::map

        // report to log an start over
		str << "Tile loaded:\t" << TempTile.TileID << "\t" << TempTile.Name << "\t" << TempTile.Block;
		Log::Write(str.str().c_str());

		str.str("");	
		str.clear();	// we want a new string for next tile
	}

	return true;	// Success!
}



// loads the map from a file
bool AsciiMap::LoadMap(std::string filename) {
	MapData.clear();	// make sure its empty before we start loading new data

	std::ostringstream mapname;
	mapname << "Maps\\" << filename << ".txt";
	std::ifstream file(mapname.str().c_str());

	if(file.bad() == true) {		// if file didnt load, abort
		return false;
	}

	int TempData = 0;	// temporary data holder
	int TilesRead = 0;	// how many tiles weve read

	// we know the size is stated first so we start by reading those
	file >> SizeX;
	file >> SizeY;

	while(1) {				// load the map into the vector
		file >> TempData;	// read which image it is

		if(file.eof()) 				// if its the end of the file, break
			break;

		MapData.push_back(TempData);	// Add it to the end of the Map
		TilesRead++;					// weve read another tile
	}

	file.close();

	// Log stuff, errorcheck, return
	std::stringstream str;

	if( SizeX * SizeY != TilesRead ) {
		str << "AsciiMap: ERROR: TilesRead ( " << TilesRead << " ) differs from expected size ( " << SizeX <<" * " << SizeY << " = " << SizeX * SizeY <<" )";
		Log::Write(str.str().c_str());
		return false;	// failed
	}

	str << "AsciiMap: Map " << filename << ".txt loaded, size changed to " << SizeX << " x " << SizeY;
	Log::Write(str.str().c_str());	

	return true;
}

Tile* AsciiMap::GetTile(int x, int y) {
	/*
	std::stringstream str;
	str << "Returning coords: " <<x<<" "<<y<< ", which is the " << (y*SizeX)+x << " element and a " << MapData[ (y*SizeX) + x ];
	Log::Write(str.str().c_str());
	*/
	int TileID = MapData[ (y*SizeX) + x ];	// calculate coords and find out what the tile ID means
	Tile* pTile = &TileData[ TileID ];
	return pTile;
}

void AsciiMap::ConsoleRenderWorld() {
	Gotoxy(0,0);

	for(int y = 0; y < SizeY; y++) {
		for(int x = 0; x < SizeX; x++) {
			std::cout << MapData[ (y * SizeX ) + x ];
		}
		std::cout << std::endl;
	}
}

void AsciiMap::Gotoxy(int x, int y) {
	COORD position;
	position.X = x;
	position.Y = y;

	SetConsoleCursorPosition( hConsole, position );
}

bool AsciiMap::Collision(int x, int y) {
	if ( TileData[ MapData[ (y * SizeX) + x ] ].Block == true )
		return true;
	else 
		return false;
}
	/*
	char tile = GetTile( x, y );	// which char are we talking about?

	for( unsigned int i = 0; i < SolidChars.size(); i++ ) {	// loop through the vector, is the char solid?
		if( SolidChars[i] == tile )
			return true;		// if so, return that the coord truly is unavaliable
	}

	return false;	// if the char was not found... the tile is free
} */

Share this post


Link to post
Share on other sites
With your project open, press alt-f7(options) then goto the link tab and add the the end of the textbox labeled link options "/NODEFAULTLIB:libcd.lib" without the quotes.

EDIT: It really shoult be /NODEFUALTLIB:"msvcrtd.lib" for debug and msvcrt.lib for release.

[Edited by - chad_420 on September 11, 2005 2:48:34 AM]

Share this post


Link to post
Share on other sites
Under Code generation in your project settings set Runtime Library to Multithreaded instead of the Singlethreaded.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this