Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED] Cannot pass in objects (Music) array  (Read 4062 times)

0 Members and 2 Guests are viewing this topic.

jeremyspk

  • Newbie
  • *
  • Posts: 26
    • View Profile
[SOLVED] Cannot pass in objects (Music) array
« 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:
Code: [Select]

#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:
Code: [Select]

#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:
Code: [Select]

#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

jeremyspk

  • Newbie
  • *
  • Posts: 26
    • View Profile
[SOLVED] Cannot pass in objects (Music) array
« Reply #1 on: February 08, 2010, 04:11:19 am »
To add on:
I was trying to work a get-around by
Code: [Select]

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. :(

jeremyspk

  • Newbie
  • *
  • Posts: 26
    • View Profile
[SOLVED] Cannot pass in objects (Music) array
« Reply #2 on: February 08, 2010, 04:38:58 am »
More updates:
Code: [Select]

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.

jeremyspk

  • Newbie
  • *
  • Posts: 26
    • View Profile
[SOLVED] Cannot pass in objects (Music) array
« Reply #3 on: February 08, 2010, 07:03:03 am »
: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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[SOLVED] Cannot pass in objects (Music) array
« Reply #4 on: February 08, 2010, 08:21:05 am »
Yup, you probably forgot to lnk to the sfml-audio library ;)
Laurent Gomila - SFML developer