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

Author Topic: Undefined Reference to `sf::SoundBuffer::loadFromSamples`  (Read 3348 times)

0 Members and 1 Guest are viewing this topic.

Jaylight

  • Newbie
  • *
  • Posts: 3
    • View Profile
Undefined Reference to `sf::SoundBuffer::loadFromSamples`
« on: March 15, 2016, 01:45:35 am »
Hi. I am trying to create a small audio based application that uses a class that inherits from SoundRecorder, and overrides the onProcessSamples function.

I am getting an error that says:

"In function `NoiseCancellor::onProcessSamples(short const*, unsigned long)': NoiseCancellor.cpp: (.text+0xef): undefined reference to `sf::SoundBuffer::loadFromSamples(short const*, unsigned long long, unsigned int, unsigned int)'
colled2: error: ld return 1 exit status

First of all I AM linking all of the sfml libraries, including -lsfml-audio.

I am using Linux Mint 17.1 (Rebecca) (Ubuntu 14) 64 bit on a 64 bit machine.

My NoiseCancellor.cpp file looks like this:

#include "NoiseCancellor.hpp"

bool NoiseCancellor::onProcessSamples(const sf::Int16* samples, std::size_t sampleCount)
{
    sf::Int16* cancelSamples = new sf::Int16[sampleCount];

    for (size_t i = 0; i < sampleCount; ++i) {
        cancelSamples[i] = -samples[i];
    }

    sf::SoundBuffer cancelBuffer;
    cancelBuffer.loadFromSamples(cancelSamples, sizeof(cancelSamples) * sampleCount, 1, getSampleRate());

    sf::Sound cancelSound(cancelBuffer);
    cancelSound.play();

    return true;
}
 

~   

And my NoiseCancellor.hpp looks like this:

#ifndef NOISE_CANCELLOR_HPP
#define NOISE_CANCELLOR_HPP

#include <SFML/Audio.hpp>

class NoiseCancellor : public sf::SoundRecorder {
        bool onProcessSamples(const sf::Int16* samples, std::size_t sampleCount);
};

#endif
 

I tried to fix it by forcing the parameters to be handled as the types `const Int16 *samples, std::size_t sampleCount, unsigned int channelCount, unsigned int sampleRate`, to exactly coincide with the documentation on the function, by static_casting all the variables as I was passing them into the function, but the error message didn't go away. Then I even tried const_casting the first parameter (since it const), and static casting all the rest. The error still didn't go away. I've been trying to search the internet to see if I could find a solution to this problem, but I didn't. Any help with this would be much appreciated. Thank you.
« Last Edit: March 16, 2016, 08:40:43 pm by Jaylight »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Undefined Reference to `sf::SoundBuffer::loadFromSamples`
« Reply #1 on: March 15, 2016, 07:44:42 am »
Can you provide the full build command?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jaylight

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Undefined Reference to `sf::SoundBuffer::loadFromSamples`
« Reply #2 on: March 16, 2016, 06:26:00 pm »
Thanks, but I fixed it.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: Undefined Reference to `sf::SoundBuffer::loadFromSamples`
« Reply #3 on: March 16, 2016, 07:52:12 pm »
What was the problem?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jaylight

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Undefined Reference to `sf::SoundBuffer::loadFromSamples`
« Reply #4 on: March 16, 2016, 08:40:20 pm »
It seems it was a typo in my link command. I had -L/path_to_include_files instead of -L/path_to_lib_files. It was such a silly mistake. I should not have bothered posting the problem.