I hope that this isn't an elementary question to you more experienced people, but I am having some trouble with my .DLL file. I haven't ever had a problem with compiling and linking it with my main project before, but it appears now some sort of problem has started. The message that appears is :
I'm not sure how to fix this error, nor have I ever received it before. Google searches weren't fruitful, and I couldn't find an answer through searching this forum's database. I finally resorted to posting my problem here, even though I didn't want to. I don't want to post my main project code because it's for a state game/simulation programming competition. I have no qualms with posting my .DLL source, as it is not particularly long or complex. It seems the problem functions are the last two I've added ( load_sound( ) and play_sound( ) ).
Here is what I'm linking it with :
Code:
-------------- Build: Debug in game (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -shared -Wl,--output-def=bin\Debug\libgame.def -Wl,--out-implib=bin\Debug\libgame.a -Wl,--dll -L"F:\FBLA\Random game\game.dll.source\game" obj\Debug\conversion.o obj\Debug\projectile.o obj\Debug\SDL_utility_functions.o obj\Debug\time.o -o bin\Debug\libgame.dll -lSDL -lSDL_mixer
Creating library file: bin\Debug\libgame.a
Output size is 49.10 KB
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings (0 minutes, 0 seconds)
projectile.c :
Code:
#include "game.h"
#include <stdio.h>
#include <stdlib.h>
/* ******************************************************** */
/* ********* create( ) ********* */
/* ******************************************************** */
/* - Allocates one node of type projectile on the heap, */
/* and returns its' address */
/* ******************************************************** */
static projectile * create( )
{
projectile * temp = NULL;
if ( !( temp = malloc( sizeof( projectile ) ) ) )
{
perror("Malloc");
exit( 1 );
}
return temp;
}
/* ******************************************************** */
/* ***** add( projectile *, int, int, int, int, int ) ***** */
/* ******************************************************** */
/* - Adds a node to the linked list of projectile nodes. */
/* ******************************************************** */
extern projectile * add( projectile * head, int h, int w, int x, int y, int speed )
{
projectile * temp = NULL;
if ( !head )
{
head = create( );
head->shape.h = h;
head->shape.w = w;
head->shape.x = x;
head->shape.y = y;
head->speed = speed;
head->next = NULL;
} else
{
temp = create( );
temp->next = head;
head = temp;
head->shape.h = h;
head->shape.w = w;
head->shape.x = x;
head->shape.y = y;
head->speed = speed;
}
return head;
}
/* ******************************************************** */
/* ********* free_list( projectile * ) ********* */
/* ******************************************************** */
/* - Frees the linked list of type projectile */
/* ******************************************************** */
extern void free_list( projectile * head )
{
projectile * p1 = head;
projectile * p2 = NULL;
while ( p1 )
{
p2 = p1;
p1 = p1->next;
free( p2 );
}
return;
}
/* ******************************************************** */
/* ********* print_list( projectile * ) ********* */
/* ******************************************************** */
/* - Prints the data in the linked list of projectile type */
/* ******************************************************** */
extern void print_list( projectile * head )
{
projectile * p1 = NULL;
for ( p1 = head; p1; p1 = p1->next )
{
printf(
"node.shape.x = %d, node.shape.y = %d\n"
"node.shape.h = %d, node.shape.w = %d\n"
"node.speed = %d, node.next = %s\n",
p1->shape.x, p1->shape.y,
p1->shape.h, p1->shape.w,
p1->speed, p1->next ? "(node address)\n\t\t--\tNext node :\t--\n" : "NULL"
);
}
}
/* ******************************************************** */
/* ********* delete( projectile *, projectile * ) ********* */
/* ******************************************************** */
/* - Deletes a node in any position of the linked list */
/* of projectile type. */
/* ******************************************************** */
extern projectile * delete( projectile * head, projectile * node )
{
projectile * p1 = head;
projectile * p2 = NULL;
if ( !p1 )
return NULL;
else if ( p1 == node )
{
if ( !p1->next )
free( p1 );
else
{
p2 = head->next;
free( p1 );
return p2;
}
return NULL;
}
for ( ; p1 && p1 != node; p2 = p1, p1 = p1->next );
if ( !p1 )
return NULL;
else
{
p2->next = p1->next;
free( p1 );
}
return head;
}
/* ******************************************************** */
/* End Source File ** */
conversion.c :
Code:
#include "game.h"
/* ******************************************************** */
/* ********* character_to_digit( char ) ********* */
/* ******************************************************** */
/* - Converts a character digit to its' numeric value. */
/* ******************************************************** */
extern int character_to_digit( char value )
{
if ( !isdigit( value ) )
return -1;
switch ( value )
{
case '0' :
return 0;
case '1' :
return 1;
case '2' :
return 2;
case '3' :
return 3;
case '4' :
return 4;
case '5' :
return 5;
case '6' :
return 6;
case '7' :
return 7;
case '8' :
return 8;
case '9' :
return 9;
default : break;
}
return -1;
}
/* ******************************************************** */
/* ********* number_of_value_places( char ) ********* */
/* ******************************************************** */
/* - Returns the number of digits in any given number */
/* ******************************************************** */
extern int number_of_value_places( int value )
{
int x;
int digit_amount;
for ( x = 10, digit_amount = 1; x <= value; x *= 10, digit_amount++ );
return digit_amount;
}
/* ******************************************************** */
/* ********* convert_number_to_string( int, int ) ********* */
/* ******************************************************** */
/* - Dynamically allocates space on the heap for a number */
/* and returns a pointer to the starting address of the */
/* string */
/* ******************************************************** */
extern char * convert_number_to_string( int value, int * value_places )
{
*value_places = number_of_value_places( value );
char * number = NULL;
if ( !( number = malloc( ( ( *value_places + 1 ) * sizeof( char ) ) ) ) )
{
perror( "malloc" );
exit( -1 );
}
if ( sprintf( number, "%d", value ) < 0 )
{
perror( "sprintf" );
exit( -2 );
}
return number;
}
/* ******************************************************** */
/* End Source File ** */
time.c :
Code:
#include "game.h"
/* ******************************************************** */
/* ********* wait( int, const int ) ********* */
/* ******************************************************** */
/* - Delays the program until the maximum frame rate is */
/* reached */
/* ******************************************************** */
extern void wait( int ms, const int FRAMES_PER_SECOND )
{
if ( ms < 1000 / FRAMES_PER_SECOND )
SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - ms );
}
/* ******************************************************** */
/* ********* timer( int, t_timer ) ********* */
/* ******************************************************** */
/* - Handles updating a timer object and getting a */
/* millisecond difference between stopping and starting */
/* values */
/* ******************************************************** */
extern clock_t timer( int command, t_timer * timer1 )
{
switch ( command )
{
case TIMER_START :
timer1->start_time = clock( );
break;
case TIMER_STOP :
timer1->end_time = clock( );
break;
case TIMER_GETDIFF :
return ( ( timer1->end_time - timer1->start_time ) / ( CLOCKS_PER_SEC / 1000 ));
break;
default : break;
}
return -1;
}
/* ******************************************************** */
/* End Source File ** */
SDL_utility_functions.c :
Code:
#include "game.h"
/* ******************************************************** */
/* ********* SDL_errorexit( const char * ) ********* */
/* ******************************************************** */
/* - Exits the program after printing an error message to */
/* the file SDL redirects the error stream to. Exits the */
/* current process with status one when finished printing */
/* the message */
/* ******************************************************** */
extern void SDL_errorexit( const char * error_message )
{
char buffer[BUFSIZ];
sprintf( buffer, "%s : %s", error_message, SDL_GetError( ) );
fprintf( stderr, "%s", buffer );
exit( 1 );
}
/* ******************************************************** */
/* ********* load_image( char *, unsigned int ) ********* */
/* ******************************************************** */
/* - Loads a image transparently or non - transparently in */
/* the program's current bit format. If the image can't be */
/* found or an error occurs, the program will exit. */
/* */
/* - ** NOTE : Loading 32-bit bitmaps causes undefined */
/* behavior ** - */
/* ******************************************************** */
extern SDL_Surface * load_image( char * image_path, unsigned int transparent )
{
SDL_Surface * image = NULL;
SDL_Surface * temp_image = SDL_LoadBMP(image_path);
if ( !temp_image )
SDL_errorexit( "SDL_LoadBMP" );
if ( transparent )
SDL_SetColorKey( temp_image, SDL_SRCCOLORKEY, SDL_MapRGB( temp_image->format, 255, 255, 255 ) );
image = SDL_DisplayFormat( temp_image );
SDL_FreeSurface( temp_image );
return image;
}
/* ******************************************************** */
/* ********* load_music( const char * ) ********* */
/* ******************************************************** */
/* - Loads a file for the in-game music */
/* ******************************************************** */
extern Mix_Music * load_music( const char * file_name )
{
Mix_Music * game_music = NULL;
game_music = Mix_LoadMUS( file_name );
if ( !game_music )
{
fprintf( stderr, "Unable to load file: %s\n", Mix_GetError( ) );
exit( 5 );
}
return game_music;
}
/* ******************************************************** */
/* ********* play_music( Mix_music *, int ) ********* */
/* ******************************************************** */
/* - Plays the music previously loaded by the load_music */
/* function */
/* ******************************************************** */
extern void play_music( Mix_Music * game_music, int loops )
{
if ( Mix_PlayMusic( game_music, loops ) == -1 )
{
fprintf( stderr, "Unable to play file: %s\n", Mix_GetError( ) );
exit( 6 );
}
return;
}
/* ******************************************************** */
/* ********* start_music( const char *, int ) ********* */
/* ******************************************************** */
/* - Basically an optional wrapper for the play_music and */
/* load_music( ) function. Requires minimal user input, but */
/* reduces more precise control over how to handle the */
/* music files that you load. */
/* ******************************************************** */
extern Mix_Music * start_music( const char * file_name, int loops )
{
Mix_Music * game_music = NULL;
game_music = load_music( file_name );
play_music( game_music, loops );
return game_music;
}
/* ******************************************************** */
/* ********* load_sound( const char * ) ********* */
/* ******************************************************** */
/* - Loads a .WAV file. Not meant to be used with */
/* full-fledged music, but it is capable of it. */
/* ******************************************************** */
extern Mix_Chunk * load_sound( const char * file_name )
{
Mix_Chunk * game_music = NULL;
game_music = Mix_LoadWAV( file_name );
if ( !game_music )
{
fprintf( stderr, "Unable to load file: %s\n", Mix_GetError( ) );
exit( 5 );
}
return game_music;
}
/* ******************************************************** */
/* ********* play_sound( int, game_music, int ) ********* */
/* ******************************************************** */
/* - Plays the .WAV file loaded by load_sound() */
/* ******************************************************** */
extern void play_sound( int channel, Mix_Chunk * game_music, int loops )
{
if ( Mix_PlayChannel( channel, game_music, loops ) == -1 )
{
fprintf( stderr, "Unable to play file: %s\n", Mix_GetError( ) );
exit( 6 );
}
return;
}
/* ******************************************************** */
/* End Source File ** */
game.h :
Code:
#ifndef GAME_H
#define GAME_H
/* Preprocessor directives */
#include "SDL/SDL.h"
#include "SDL/SDL_mixer.h"
#include <time.h>
/* Integer constants */
enum
{
TIMER_START,
TIMER_STOP,
TIMER_GETDIFF
};
/* Global types */
typedef struct t_timer
{
clock_t start_time;
clock_t end_time;
} t_timer;
typedef struct projectile
{
SDL_Rect shape;
int speed;
struct projectile * next;
} projectile;
#endif
I hope I didn't waste your time.