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

Author Topic: undefined reference to _imp___ZN2sf11SoundStreamC2Ev  (Read 11452 times)

0 Members and 1 Guest are viewing this topic.

51423benam

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
undefined reference to _imp___ZN2sf11SoundStreamC2Ev
« 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?

« Last Edit: May 14, 2018, 07:17:53 pm by eXpl0it3r »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11018
    • View Profile
    • development blog
    • Email
Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
« Reply #1 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]. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

51423benam

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
« Reply #2 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11018
    • View Profile
    • development blog
    • Email
Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
« Reply #3 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?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

51423benam

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
« Reply #4 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11018
    • View Profile
    • development blog
    • Email
Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
« Reply #5 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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Flaze07

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
    • Email
Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
« Reply #6 on: May 16, 2018, 07:00:04 pm »
I think building it yourself will fix this problem...since it did for me

51423benam

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
« Reply #7 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.
« Last Edit: May 16, 2018, 08:39:19 pm by 51423benam »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11018
    • View Profile
    • development blog
    • Email
Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
« Reply #8 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. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

51423benam

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
« Reply #9 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11018
    • View Profile
    • development blog
    • Email
Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
« Reply #10 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

51423benam

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
« Reply #11 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11018
    • View Profile
    • development blog
    • Email
Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
« Reply #12 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

51423benam

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
« Reply #13 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.

51423benam

  • Newbie
  • *
  • Posts: 26
    • View Profile
    • Email
Re: undefined reference to _imp___ZN2sf11SoundStreamC2Ev
« Reply #14 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;
}
 

 

anything