SFML community forums
Help => Audio => Topic started by: jeremyspk on February 08, 2010, 02:55:57 am
-
Hi
I'm not sure if it's a semantics error of my side or the SFML code as I can't seem to pass-in objects array into my function.
I tried changing the type from 'Music' to a primitive type: 'int' and it works. But when I use Music as the type, I cannot link.
error LNK2001: unresolved external symbol "public: virtual __thiscall sf::Music::~Music(void)" (??1Music@sf@@UAE@XZ)
error LNK2001: unresolved external symbol "public: __thiscall sf::Music::Music(unsigned int)" (??0Music@sf@@QAE@I@Z)
Here's the main:
#include "AudioLoader.h"
using namespace std;
int main()
{
cout << "Welcome to Mozark!\n";
AudioLoader rockAL; // AudioLoader object
Music rockTracks[MAX_TRACK_NUM];
rockAL.load(rockTracks); // Load all audio library files
//***FOR DEBUG
cout << "Press enter to exit...";
cin.get();
return EXIT_SUCCESS;
}
Here's the AudioLoader.h:
#ifndef AUDIOLOADER_H
#define AUDIOLOADER_H
#define MAX_TRACK_NUM 21
#define FILE_TYPE "*.ogg"
#include <iostream>
#include <string>
#include <windows.h>
#include <dirent.h>
#include <SFML\audio.hpp>
using sf::Music;
class AudioLoader
{
public:
AudioLoader(void);
void load(Music theTracks[]);
int getNum(void);
std::string getTrackName(int);
private:
int numOfTracks;
int trackPtr;
std::string tracks[MAX_TRACK_NUM];
};
#endif
Here's the AudioLoader class file:
#include "AudioLoader.h"
using namespace std;
AudioLoader::AudioLoader(void)
{
numOfTracks = 0;
trackPtr = 0;
}
void AudioLoader::load(Music theTracks[])
{
bool loaded = false;
// Setting tracks location
string tempTrack = "";
DIR *pdir = NULL;
pdir = opendir("ogg"); //folder called "OGG"
struct dirent *pEntry = NULL;
// Check for failure
if (pdir == NULL)
{
cout << "Error! Unable to find audio directory.\n";
exit(3);
}
// Begin loading of audio files
cout << "Begin loading of audio tracks...\n";
cout << "--------------------------------\n";
while (pEntry = readdir(pdir))
{
if (numOfTracks >= MAX_TRACK_NUM)
{
cout << "MAXIMUM LOADING OF TRACKS REACHED.\n";
cout << "Warning! Not all audio tracks are loaded.\n";
break;
}
else if (strlen(pEntry->d_name) <= 4)
continue;
else if (pEntry == NULL) // Pointing to nothing
{
cout << "Error! Unable to find any audio files.\n";
exit(3);
}
tracks[numOfTracks] = pEntry->d_name;
cout << "Loaded: " << pEntry->d_name << endl;
numOfTracks++;
}
//Summary of Audio Loading
cout << "----------------------------------\n";
cout << numOfTracks << " tracks have been successfully loaded!\n";
}
..
..
My code error or SFML bug?
Jeremy
-
To add on:
I was trying to work a get-around by
void AudioLoader::load()
{
...
Music *rockTracks;
rockTracks = new Music[MAX_TRACK_NUM];
...
}
=> rockTracks = new Music[MAX_TRACK_NUM]; <<== causing linking errors
I get LNK errors:
1>AudioLoader.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall sf::Music::~Music(void)" (??1Music@sf@@UAE@XZ) referenced in function "public: void __thiscall AudioLoader::load(void)" (?load@AudioLoader@@QAEXXZ)
1>AudioLoader.obj : error LNK2019: unresolved external symbol "public: __thiscall sf::Music::Music(unsigned int)" (??0Music@sf@@QAE@I@Z) referenced in function "public: void __thiscall sf::Music::`default constructor closure'(void)" (??_FMusic@sf@@QAEXXZ)
I don't want to make my audioloader in the main. :(
-
More updates:
int main()
{
...
Music rockTracks[MAX_TRACK_NUM];
...
}
This actually throws me the two lnk errors. :/
Why can't I create an array of Music objects? Illegal? :(
I need to use array.
-
:oops:
this is so embarrassing.
I think I may have found the problem, and it has something to do with project's settings regarding additional dependencies.
-
Yup, you probably forgot to lnk to the sfml-audio library ;)