SFML community forums

Help => Audio => Topic started by: 51423benam on May 14, 2018, 06:43:35 pm

Title: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
Post by: 51423benam on May 14, 2018, 06:43:35 pm
Hello,

I am facing that error when implementing a custom soundstream inherited class.
Here is the code where it is complaining:
#ifndef AUDIOMANAGER_H_INCLUDED
#define AUDIOMANAGER_H_INCLUDED

#include <memory>
#include <vector>

#include <SFML/Audio.hpp>

#include "../nodes/outputNode.h"

class AudioManager;

class customAudioStream : sf::SoundStream{       // HERE IT IS THROWING THE ERROR!

public:

private:
    virtual bool onGetData(Chunk& data);
    virtual void onSeek(sf::Time timeOffset);
    void registerAudioManager(AudioManager* audioManager);

    AudioManager* manager;
};

class AudioManager{
public:

    AudioManager();
    ~AudioManager();
    void registerOutputNode(std::unique_ptr<outputNode> newOutNode);
    std::vector<sf::Int16> getOutputAudio();

private:
    std::unique_ptr<outputNode> outNode;
    customAudioStream stream;
};


#endif // AUDIOMANAGER_H_INCLUDED

There is some code for outputNode and so on that is missing, since the error seems to be unrelated to that parts.
Do you have any idea what that could be?

Title: Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
Post by: eXpl0it3r on May 14, 2018, 07:20:41 pm
You aren't linking sfml-audio or not in the correct order.

When posting code please use [code=cpp][/code]. :)
Title: Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
Post by: 51423benam on May 14, 2018, 10:07:34 pm
Can that also happen when I am including it multiple times? For example: file A includes audio.hpp, file B includes audio.hpp, file B includes A. Could that also be a reason?
Title: Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
Post by: eXpl0it3r on May 14, 2018, 10:11:32 pm
If you have circular dependencies, then you can get errors, but I'm not sure if it would be linker errors like this.

Did you ensure you're linking correctly in the right order etc?
Title: Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
Post by: 51423benam on May 16, 2018, 03:13:54 pm
I just noticed that the sfml version I downloaded doesn't match up exactly (I have gcc 6.3.0, the sfml version is for 6.3.0). But in general, I have a problem. The latest sfml version is only available for gcc version 7.3.0. The problem is, I don't have admin rights I would need to install the latest mingw. The mingw I have was included in the codeblocks mingw nonadmin setup. Is there a workaround for this?
Title: Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
Post by: eXpl0it3r on May 16, 2018, 04:17:01 pm
The download page links directly to the compiler used to build the binaries and it's just a 7z package, so you can extract that anywhere you want and use it as a compiler.

The mingw I have was included in the codeblocks mingw nonadmin setup. Is there a workaround for this?
I don't think so, because Code::Blocks has never shipped such a compiler version.
Instead I'm pretty sure you downloaded the linked MinGW 6.3.0 build from the SFML 2.4.2 download page. ;)
Title: Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
Post by: Flaze07 on May 16, 2018, 07:00:04 pm
I think building it yourself will fix this problem...since it did for me
Title: Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
Post by: 51423benam on May 16, 2018, 08:36:31 pm
http://www.codeblocks.org/downloads/binaries
That's the link where you can find the mingw nosetup.zip. But thanks, I will look into that links.
Title: Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
Post by: eXpl0it3r on May 16, 2018, 10:18:02 pm
I know and under that link you just posted yourself and the nosetup.zip, you'll find the TDM MinGW GCC 5.1.0 compiler for which we provide binaries. ;)
Since you said, you're using MinGW GCC 6.3.0 it doesn't come from that archive and I forgot, but we also only provided a link to MinGW GCC 6.1.0.

You have two options, build from source (will always work regardless of your compiler) or use a matching compiler. :)
Title: Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
Post by: 51423benam on May 17, 2018, 07:33:37 am
So if I understand you right, I don't have to compile with the compiler I use then for my sfml project and it work anyway?
Title: Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
Post by: eXpl0it3r on May 17, 2018, 09:01:58 am
The compiler needs to match 100% the one that was used to build SFML.

Either change your compiler or build from source.
Title: Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
Post by: 51423benam on May 18, 2018, 04:37:25 pm
I downloaded sfml for gcc 7.3.0 and installed mingw 7.3.0.
However, I still have errors, here they are:

||=== Build: Debug in SFML_CodeBlocks_TEST (compiler: GNU GCC Compiler) ===|
obj\Debug\src\AudioManager.o||In function `ZN17customAudioStreamC1Ev':|
D:\SFML_CodeBlocks_TEST\SFML_CodeBlocks_TEST\include\AudioManager.h|14|undefined reference to `_imp___ZN2sf11SoundStreamC2Ev'|
obj\Debug\src\AudioManager.o||In function `ZNKSt14default_deleteI10outputNodeEclEPS0_':|
d:\mingw\7.3.0\lib\gcc\mingw32\6.3.0\include\c++\bits\unique_ptr.h|76|undefined reference to `outputNode::~outputNode()'|
obj\Debug\src\AudioManager.o:AudioManager.cpp:(.rdata$_ZTV17customAudioStream[__ZTV17customAudioStream]+0x10)||undefined reference to `sf::SoundStream::play()'|
obj\Debug\src\AudioManager.o:AudioManager.cpp:(.rdata$_ZTV17customAudioStream[__ZTV17customAudioStream]+0x14)||undefined reference to `sf::SoundStream::pause()'|
obj\Debug\src\AudioManager.o:AudioManager.cpp:(.rdata$_ZTV17customAudioStream[__ZTV17customAudioStream]+0x18)||undefined reference to `sf::SoundStream::stop()'|
obj\Debug\src\AudioManager.o:AudioManager.cpp:(.rdata$_ZTV17customAudioStream[__ZTV17customAudioStream]+0x1c)||undefined reference to `sf::SoundStream::getStatus() const'|
obj\Debug\src\AudioManager.o:AudioManager.cpp:(.rdata$_ZTV17customAudioStream[__ZTV17customAudioStream]+0x28)||undefined reference to `sf::SoundStream::onLoop()'|
obj\Debug\src\AudioManager.o||In function `ZN17customAudioStreamD1Ev':|
D:\SFML_CodeBlocks_TEST\SFML_CodeBlocks_TEST\include\AudioManager.h|14|undefined reference to `_imp___ZN2sf11SoundStreamD2Ev'|
||error: ld returned 1 exit status|
||=== Build failed: 9 error(s), 2 warning(s) (0 minute(s), 35 second(s)) ===|

I don't know what's wrong. Maybe I have the wrong sfml subversion (you know, that dw2, sjlj stuff). Is there a way to check for which subversion my sfml version is?
Title: Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
Post by: eXpl0it3r on May 18, 2018, 04:44:49 pm
Did you download the compiler that is linked on the download page?

Please provide your verbose build command (https://www.sfml-dev.org/faq.php#tr-grl-verbose-ide).
Title: Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
Post by: 51423benam on May 18, 2018, 05:52:34 pm
It is set to full command line. No, I didn't download the compiler with the links, but it matches, both with the version number and the compiler type (it's dw2). Also, I just copied the example from the tutorial page into a .h file and it didn't throw errors in that file, so it has to be something related to my code.
Title: Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
Post by: 51423benam on May 18, 2018, 05:54:54 pm
My full code in this class is:
AudioManager.h:
#ifndef AUDIOMANAGER_H_INCLUDED
#define AUDIOMANAGER_H_INCLUDED

#include <memory>
#include <vector>

#include <SFML/Audio.hpp>

#include "utils.h"
#include "../nodes/outputNode.h"

class AudioManager;

class customAudioStream : public sf::SoundStream{

public:

private:
    virtual bool onGetData(Chunk& data);
    virtual void onSeek(sf::Time timeOffset);
    void registerAudioManager(AudioManager* audioManager);

    AudioManager* manager;
};

class AudioManager{
public:

    AudioManager();
    ~AudioManager();
    void registerOutputNode(std::unique_ptr<outputNode> newOutNode);
    std::vector<sf::Int16>* getOutputAudio();

private:
    std::unique_ptr<outputNode> outNode;
    customAudioStream stream;
};


#endif // AUDIOMANAGER_H_INCLUDED
 

AudioManager.cpp:
#include "AudioManager.h"

bool customAudioStream::onGetData(Chunk& data){
    return true;
}

void customAudioStream::onSeek(sf::Time timeOffset){

}


void customAudioStream::registerAudioManager(AudioManager* audioManager){
    manager = audioManager;
}

AudioManager::AudioManager(){

}

AudioManager::~AudioManager(){

}

void AudioManager::registerOutputNode(std::unique_ptr<outputNode> newOutputNode){
    outNode = std::move(newOutputNode);
}

std::vector<sf::Int16>* AudioManager::getOutputAudio(){
    std::vector<sf::Int16>* output;
    output->reserve(size);
    DataBlock* data;
    data = outNode->getAudioData();
    std::vector<boost::variant<sf::Int16, int>>* rawData = data->getData();
    for(int counter = 0; counter < rawData->size(); counter++){
        (*output)[counter] = boost::get<sf::Int16>((*rawData)[counter]);
    }
    return output;
}
 
Title: Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
Post by: eXpl0it3r on May 18, 2018, 05:56:30 pm
So what did you exactly download? There are many builders of MinGW and each build isn't necessarily compatible between the other.

The idea of the FAQ link was that your do a full rebuild and provide the build command. :D
Title: Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
Post by: 51423benam on May 18, 2018, 08:02:43 pm
I downloaded the latest mingw-get-installer.exe from the official website and installed the base mingw, the c++ compiler and msys basis.
But since the example soundstream code worked, it has to be my code that is false somehow, right?
Title: Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
Post by: 51423benam on May 19, 2018, 12:27:14 am
Oh, I think, I had some missing steps to link sfml correctly, it seems like I didn't read the getting started article well enough, I will check that again.