This message was edited by luhnth at 2007-3-24 8:29:16
: : :
This message was edited by luhnth at 2007-3-21 15:44:49
: : : I fixed the linker errors with the "ttf" I just created a new .h file (Been a long time) and I'm getting errors like:
: : :
: : : multiple definition of `InitVideo(unsigned int)'
: : :
: : : Here's my code:
: : :
: : : main.cpp
: : :
: : :
#include <cstdlib> // For some useful functions such as atexit :)
: : : #include <SDL/SDL.h> // main SDL header
: : : #include <SDL/SDL_mixer.h> //For sound mixing
: : : #include <SDL/SDL_ttf.h> //For fonts and text
: : : #include <SDL/SDL_net.h> //For network
: : : #include <iostream>
: : :
: : : #include "initSDL.h"
: : :
: : : #define SCREEN_WIDTH 640
: : : #define SCREEN_HEIGHT 480
: : :
: : : SDL_Surface *screen; //This pointer will reference the backbuffer#include <cstdlib>
: : :
: : : using namespace std;
: : :
: : :
: : :
: : : int main(int argc, char *argv[])
: : : {
: : : if (!InitVideo(SDL_DOUBLEBUF | SDL_FULLSCREEN)) {
: : : return EXIT_FAILURE;
: : : }
: : : printf("Going good");
: : : system("PAUSE");
: : : return EXIT_SUCCESS;
: : : }
: : :
: : :
: : : initSDL.h
: : :
: : :
#ifndef _INITSDL_H_
: : : #define _INITSDL_H_
: : :
: : : #include <SDL/SDL.h> // main SDL header
: : :
: : : int InitVideo(Uint32 flags); //Init video
: : : int InitAudio(); //Init audio
: : : int InitTTF(); //Init fonts
: : : int InitNet(); //Init networking
: : : SDL_Surface* getScreen(); //Get screen
: : :
: : : #endif
: : :
: : :
: : : initSDL.cpp
: : :
: : :
#include <cstdlib> // For some useful functions such as atexit :)
: : : #include <SDL/SDL.h> // main SDL header
: : : #include <SDL/SDL_mixer.h> //For sound mixing
: : : #include <SDL/SDL_ttf.h> //For fonts and text
: : : #include <SDL/SDL_net.h> //For network
: : :
: : : #include "initSDL.h"
: : :
: : : #define SCREEN_WIDTH 640
: : : #define SCREEN_HEIGHT 480
: : :
: : : using namespace std;
: : :
: : : SDL_Surface *screen; //This pointer will reference the backbuffer#include <cstdlib>
: : :
: : : int InitVideo(Uint32 flags) { //Initialize video
: : : // Load SDL
: : : if (SDL_Init(SDL_INIT_VIDEO) != 0) {
: : : fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
: : : return false;
: : : }
: : : atexit(SDL_Quit); // Clean it up nicely :)
: : :
: : : // fullscreen can be toggled at run time :) any you might want to change the flags with params?
: : : //set the main screen to SCREEN_WIDTHxSCREEN_HEIGHT with a colour depth of 16:
: : : screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, flags);
: : : if (screen == NULL) {
: : : fprintf(stderr, "Unable to set video mode: %s\n", SDL_GetError());
: : : return false;
: : : }
: : : return true;
: : : }
: : :
: : : int InitAudio() { //Initialize audio
: : : //Load Audio Support
: : : if(SDL_Init(SDL_INIT_AUDIO) != 0) {
: : : fprintf(stderr, "Warning: unable to initialize audio: %s\n", SDL_GetError());
: : : return false;
: : : }
: : :
: : : if (Mix_OpenAudio(11025, AUDIO_S16, 2, 512) < 0) {
: : : fprintf(stderr, "Warning: Audio could not be setup for 11025 Hz 16-bit stereo.\nReason: %s\n", SDL_GetError());
: : : return false;
: : : }
: : : return true;
: : : }
: : :
: : : int InitTTF() { //Initialize Text and Fonts
: : : if(TTF_Init()==-1) {
: : : fprintf(stderr, "Error: unable to initialize TTF_SDL, %s\n", TTF_GetError());
: : : return false;
: : : }
: : : atexit(TTF_Quit);
: : : return true;
: : : }
: : :
: : : int InitNet() { //Initialize networking
: : : if(SDLNet_Init()==-1) {
: : : fprintf(stderr, "Error: unable to initialize SDL networking, %s\n", SDLNet_GetError());
: : : return false;
: : : }
: : : atexit(SDLNet_Quit);
: : : return true;
: : : }
: : :
: : : SDL_Surface* getScreen()
: : : {
: : : return screen;
: : : }
: : :
: : : Best Regards,
: : : CodeKing
: : :
: : Can you please post all of your errors?
: :
:
: multiple definition of `function(vars)'
: first defined here
:
: for every function in initSDL.h and initSDL.cpp
:
:
: Best Regards,
: CodeKing
:
:
I didn't look at my errors close enough. It turns out that the errors are only for the functions with no parameters. I put void inside the (), but that didn't help. I put SDL_Surface *screen into them and it compiled fine. Is there any way to not have to pass a useless parameter.
Best Regards,
CodeKing