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

Author Topic: Linking sfml on Mac OSX  (Read 3093 times)

0 Members and 1 Guest are viewing this topic.

cheeseboy

  • Newbie
  • *
  • Posts: 36
    • View Profile
Linking sfml on Mac OSX
« on: August 17, 2013, 09:02:11 pm »
clang++  -o "/Users/greg/enigma-dev/./MacOS/build/Release/EnigmaXcode.app/Contents/MacOS/EnigmaXcode" .eobjs/MacOSX/MacOSX/Run/SHELLmain.o .eobjs/MacOSX/MacOSX/Run/libEGMstd.o .eobjs/MacOSX/MacOSX/Run/Platforms/Cocoa/CocoaDialog.o .eobjs/MacOSX/MacOSX/Run/Platforms/Cocoa/CocoaFunctions.o .eobjs/MacOSX/MacOSX/Run/Platforms/Cocoa/CocoaMain.o .eobjs/MacOSX/MacOSX/Run/Platforms/Cocoa/CocoaWindow.o .eobjs/MacOSX/MacOSX/Run/Platforms/Cocoa/XLIBthreads.o .eobjs/MacOSX/MacOSX/Run/Platforms/Cocoa/file_manip.o .eobjs/MacOSX/MacOSX/Run/Platforms/Cocoa/EnigmaView.o .eobjs/MacOSX/MacOSX/Run/Platforms/Cocoa/EnigmaXcodeAppDelegate.o .eobjs/MacOSX/MacOSX/Run/Platforms/Cocoa/WindowFunctions.o .eobjs/MacOSX/MacOSX/Run/Platforms/Cocoa/main.o .eobjs/MacOSX/MacOSX/Run/Graphics_Systems/OpenGL1/GLbackground.o .eobjs/MacOSX/MacOSX/Run/Graphics_Systems/OpenGL1/GLblend.o .eobjs/MacOSX/MacOSX/Run/Graphics_Systems/OpenGL1/GLcolors.o .eobjs/MacOSX/MacOSX/Run/Graphics_Systems/OpenGL1/GLcurves.o .eobjs/MacOSX/MacOSX/Run/Graphics_Systems/OpenGL1/GLd3d.o .eobjs/MacOSX/MacOSX/Run/Graphics_Systems/OpenGL1/GLenable.o .eobjs/MacOSX/MacOSX/Run/Graphics_Systems/OpenGL1/GLfont.o .eobjs/MacOSX/MacOSX/Run/Graphics_Systems/OpenGL1/GLmodel.o .eobjs/MacOSX/MacOSX/Run/Graphics_Systems/OpenGL1/GLprimitives.o .eobjs/MacOSX/MacOSX/Run/Graphics_Systems/OpenGL1/GLprofiler.o .eobjs/MacOSX/MacOSX/Run/Graphics_Systems/OpenGL1/GLscreen.o .eobjs/MacOSX/MacOSX/Run/Graphics_Systems/OpenGL1/GLshapes.o .eobjs/MacOSX/MacOSX/Run/Graphics_Systems/OpenGL1/GLsprite.o .eobjs/MacOSX/MacOSX/Run/Graphics_Systems/OpenGL1/GLstdraw.o .eobjs/MacOSX/MacOSX/Run/Graphics_Systems/OpenGL1/GLsurface.o .eobjs/MacOSX/MacOSX/Run/Graphics_Systems/OpenGL1/GLtextures.o .eobjs/MacOSX/MacOSX/Run/Graphics_Systems/OpenGL1/GLtiles.o .eobjs/MacOSX/MacOSX/Run/Graphics_Systems/OpenGL1/OPENGLStd.o .eobjs/MacOSX/MacOSX/Run/Graphics_Systems/OpenGL1/glew.o .eobjs/MacOSX/MacOSX/Run/Audio_Systems/SFML/SFMLadvanced.o .eobjs/MacOSX/MacOSX/Run/Audio_Systems/SFML/SFMLbasic.o .eobjs/MacOSX/MacOSX/Run/Collision_Systems/Precise/coll_funcs.o .eobjs/MacOSX/MacOSX/Run/Collision_Systems/Precise/coll_impl.o .eobjs/MacOSX/MacOSX/Run/Collision_Systems/Precise/placeholderlinks.o .eobjs/MacOSX/MacOSX/Run/Widget_Systems/None/nowidget_impl.o .eobjs/MacOSX/MacOSX/Run/Universal_System/CallbackArrays.o .eobjs/MacOSX/MacOSX/Run/Universal_System/ENIGMA_GLOBALS.o .eobjs/MacOSX/MacOSX/Run/Universal_System/IMGloading.o .eobjs/MacOSX/MacOSX/Run/Universal_System/backgroundinit.o .eobjs/MacOSX/MacOSX/Run/Universal_System/backgroundstruct.o .eobjs/MacOSX/MacOSX/Run/Universal_System/callbacks_events.o .eobjs/MacOSX/MacOSX/Run/Universal_System/collisions_object.o .eobjs/MacOSX/MacOSX/Run/Universal_System/darray.o .eobjs/MacOSX/MacOSX/Run/Universal_System/depth_draw.o .eobjs/MacOSX/MacOSX/Run/Universal_System/dynamic_args.o .eobjs/MacOSX/MacOSX/Run/Universal_System/estring.o .eobjs/MacOSX/MacOSX/Run/Universal_System/fileio.o .eobjs/MacOSX/MacOSX/Run/Universal_System/fontinit.o .eobjs/MacOSX/MacOSX/Run/Universal_System/fontstruct.o .eobjs/MacOSX/MacOSX/Run/Universal_System/globalupdate.o .eobjs/MacOSX/MacOSX/Run/Universal_System/graphics_object.o .eobjs/MacOSX/MacOSX/Run/Universal_System/highscore_functions.o .eobjs/MacOSX/MacOSX/Run/Universal_System/instance.o .eobjs/MacOSX/MacOSX/Run/Universal_System/instance_planar.o .eobjs/MacOSX/MacOSX/Run/Universal_System/instance_system.o .eobjs/MacOSX/MacOSX/Run/Universal_System/lives.o .eobjs/MacOSX/MacOSX/Run/Universal_System/loading.o .eobjs/MacOSX/MacOSX/Run/Universal_System/lodepng.o .eobjs/MacOSX/MacOSX/Run/Universal_System/mathnc.o .eobjs/MacOSX/MacOSX/Run/Universal_System/move_functions.o .eobjs/MacOSX/MacOSX/Run/Universal_System/multifunction_variant.o .eobjs/MacOSX/MacOSX/Run/Universal_System/object.o .eobjs/MacOSX/MacOSX/Run/Universal_System/planar_object.o .eobjs/MacOSX/MacOSX/Run/Universal_System/rectpack.o .eobjs/MacOSX/MacOSX/Run/Universal_System/reflexive_types.o .eobjs/MacOSX/MacOSX/Run/Universal_System/resource_data.o .eobjs/MacOSX/MacOSX/Run/Universal_System/roomsystem.o .eobjs/MacOSX/MacOSX/Run/Universal_System/soundinit.o .eobjs/MacOSX/MacOSX/Run/Universal_System/spriteinit.o .eobjs/MacOSX/MacOSX/Run/Universal_System/spritestruct.o .eobjs/MacOSX/MacOSX/Run/Universal_System/terminal_io.o .eobjs/MacOSX/MacOSX/Run/Universal_System/transform_object.o .eobjs/MacOSX/MacOSX/Run/Universal_System/var4.o .eobjs/MacOSX/MacOSX/Run/Universal_System/var4_lua.o .eobjs/MacOSX/MacOSX/Run/Universal_System/zlib.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/Alarms/alarmcode.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/Timelines/timelines.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/Paths/path_functions.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/Paths/pathinit.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/Paths/pathstruct.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/MotionPlanning/motion_planning.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/MotionPlanning/motion_planning_struct.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/MotionPlanning/mp_movement.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/DateTime/date_time.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/ParticleSystems/PS_actions.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/ParticleSystems/PS_effects.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/ParticleSystems/PS_particle_attractor.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/ParticleSystems/PS_particle_changer.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/ParticleSystems/PS_particle_deflector.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/ParticleSystems/PS_particle_depths.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/ParticleSystems/PS_particle_destroyer.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/ParticleSystems/PS_particle_emitter.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/ParticleSystems/PS_particle_particles_apiimpl.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/ParticleSystems/PS_particle_sprites.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/ParticleSystems/PS_particle_system.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/ParticleSystems/PS_particle_system_apiimpl.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/ParticleSystems/PS_particle_system_manager.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/ParticleSystems/PS_particle_type.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/ParticleSystems/PS_particle_updatedraw.o .eobjs/MacOSX/MacOSX/Run/Universal_System/Extensions/DataStructures/data_structures.o  -lz -framework Cocoa -framework OpenGL -framework SFML -framework sfml-audio -framework sfml-system -framework OpenAL -framework sndfile -lz
Undefined symbols for architecture x86_64:
  "sf::SoundBuffer::loadFromFile(std::string const&)", referenced from:
      enigma_user::sound_add(std::string, int, bool) in SFMLbasic.o
      enigma_user::sound_replace(int, std::string, int, bool) in SFMLbasic.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [compile_game] Error 1
make: *** [Game] Error 2

/** Copyright (C) 2013 cheeseboy the great, Robert B. Colton
*** Copyright (C) 2013 Josh Ventura <JoshV@zoominternet.net>
***
*** This file is a part of the ENIGMA Development Environment.
***
*** ENIGMA is free software: you can redistribute it and/or modify it under the
*** terms of the GNU General Public License as published by the Free Software
*** Foundation, version 3 of the license or any later version.
***
*** This application and its source code is distributed AS-IS, WITHOUT ANY
*** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
*** FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
*** details.
***
*** You should have received a copy of the GNU General Public License along
*** with this code. If not, see <http://www.gnu.org/licenses/>
**/


#ifdef _WIN32
#define AL_LIBTYPE_STATIC
#define SFML_STATIC
#endif

#include <SFML/Audio.hpp>
#include <vector>
#include "../General/ASbasic.h"

#include <cstdlib>
#include <cstdio>

struct normalizer {
  unsigned char lowbyte, highbyte;
  void normalize() {
    if (highbyte > 255) highbyte = 1, lowbyte = 1;
  }
};

class CustomSoundStream: public sf::SoundStream {
  void *userdata;
  void *buffer;
  const size_t buffer_size;
 
  size_t (*ongetdata)(void *userdata, void *buffer, size_t size);
  void (*onseek)(void *userdata, float position);
  void (*oncleanup)(void *userdata);
 
  public:
 
  CustomSoundStream(size_t (*callback)(void *userdata, void *buffer, size_t size),
    void (*seek)(void *userdata, float position), void (*cleanup)(void *userdata), void* userdata):
      userdata(userdata), buffer(new char[BUFSIZ]), buffer_size(BUFSIZ),
      ongetdata(callback), onseek(seek), oncleanup(cleanup) { initialize(2, 44100); }

  ~CustomSoundStream() {
    oncleanup(userdata);
  }
 
  private:

  void clipBuffer() {
    for (size_t i = 0; i < BUFSIZ / sizeof(normalizer); ++i)
      ((normalizer*)buffer)[i].normalize();
  }

  bool onGetData(Chunk& data) {
    data.samples = (short*) buffer;
    data.sampleCount = ongetdata(userdata, buffer, buffer_size)/sizeof(short);
    //clipBuffer();
    return true;
  }
 
  void onSeek(sf::Time timeOffset) {
    onseek(userdata, timeOffset.asSeconds());
  }
};

struct PlayableSound {
    virtual ~PlayableSound() {

    }
        virtual bool play() = 0;
        virtual bool pause() = 0;
    virtual void stop() = 0;
        virtual sf::SoundSource::Status getStatus() = 0;
        virtual sf::Time getPlayingOffset() = 0;
        virtual sf::Time getDuration() = 0;
        virtual unsigned int getSampleRate() = 0;
        virtual unsigned int getChannelCount() = 0;
        virtual float getVolume() = 0;
        virtual float getPitch() = 0;
        virtual float getMinDistance() = 0;
        virtual float getAttenuation() = 0;
        virtual sf::Vector3f getPosition() = 0;
        virtual float getX() = 0;
        virtual float getY() = 0;
        virtual float getZ() = 0;
        virtual bool setLoop(bool loop) = 0;
    virtual void setVolume(float volume) = 0;
        virtual void setPlayingOffset(sf::Time offset) = 0;
        virtual void setPosition(float x, float y, float z) = 0;
        virtual void setPitch(float pitch) = 0;
        virtual void setMinDistance(float distance) = 0;
        virtual void setAttenuation(float attenuation) = 0;
};

struct PlayableSoundInstance : public PlayableSound {
        sf::Sound *sound;
        sf::SoundBuffer *buffer;

        PlayableSoundInstance(sf::Sound *s, sf::SoundBuffer *b): sound(s), buffer(b) {};
       
        ~PlayableSoundInstance() {
          delete sound;
          delete buffer;
        }

        bool play() {
          sound->play();
        }

        bool pause() {
          sound->pause();
        }

        void stop() {
          sound->stop();
        }

        sf::SoundSource::Status getStatus() {
          return sound->getStatus();
        }

        sf::Time getPlayingOffset() {
          return sound->getPlayingOffset();
        }

        sf::Time getDuration() {
          return buffer->getDuration();
        }

        unsigned int getSampleRate() {
          return buffer->getSampleRate();
        }

        unsigned int getChannelCount() {
          return buffer->getChannelCount();
        }

        float getVolume() {
          return sound->getVolume();
        }

        float getPitch() {
          return sound->getPitch();
        }

        float getMinDistance() {
          return sound->getMinDistance();
        }

        float getAttenuation() {
          return sound->getAttenuation();
        }

        sf::Vector3f getPosition() {
          return sound->getPosition();
        }

        float getX() {
          return sound->getPosition().x;
        }

        float getY() {
          return sound->getPosition().y;
        }

        float getZ() {
          return sound->getPosition().z;
        }

        bool setLoop(bool loop) {
          sound->setLoop(loop);
        }

        void setVolume(float volume) {
          sound->setVolume(volume);
        }

        void setPlayingOffset(sf::Time offset) {
          sound->setPlayingOffset(offset);
        }

        void setPosition(float x, float y, float z) {
          sound->setPosition(x, y, z);
        }

        void setPitch(float pitch) {
          sound->setPitch(pitch);
        }

        void setMinDistance(float distance) {
          sound->setMinDistance(distance);
        }

        void setAttenuation(float attenuation) {
          sound->setAttenuation(attenuation);
        }
};

struct PlayableSoundStream : public PlayableSound {
        sf::SoundStream *stream;

        PlayableSoundStream(sf::SoundStream *s): stream(s) {};

        ~PlayableSoundStream() {
          delete stream;
        }

        bool play() {
          stream->play();
        }

        bool pause() {
          stream->pause();
        }

        void stop() {
          stream->stop();
        }

        sf::SoundSource::Status getStatus() {
          return stream->getStatus();
        }

        sf::Time getPlayingOffset() {
          return stream->getPlayingOffset();
        }

        sf::Time getDuration() {
          // sfml soundstreams do not have a way of getting their duration
          //return stream->getDuration();
        }

        unsigned int getSampleRate() {
          return stream->getSampleRate();
        }

        unsigned int getChannelCount() {
          return stream->getChannelCount();
        }

        float getVolume() {
          return stream->getVolume();
        }

        float getPitch() {
          return stream->getPitch();
        }

        float getMinDistance() {
          return stream->getMinDistance();
        }

        float getAttenuation() {
          return stream->getAttenuation();
        }

        sf::Vector3f getPosition() {
          return stream->getPosition();
        }

        float getX() {
          return stream->getPosition().x;
        }

        float getY() {
          return stream->getPosition().y;
        }

        float getZ() {
          return stream->getPosition().z;
        }

        bool setLoop(bool loop) {
          stream->setLoop(loop);
        }

        void setVolume(float volume) {
          stream->setVolume(volume);
        }

        void setPlayingOffset(sf::Time offset) {
          stream->setPlayingOffset(offset);
        }

        void setPosition(float x, float y, float z) {
          stream->setPosition(x, y, z);
        }

        void setPitch(float pitch) {
          stream->setPitch(pitch);
        }

        void setMinDistance(float distance) {
          stream->setMinDistance(distance);
        }

        void setAttenuation(float attenuation) {
          stream->setAttenuation(attenuation);
        }
};

std::vector<PlayableSound*> sounds;

namespace enigma
{
  int audiosystem_initialize() {
    //TODO: Initialize audio system
    return 0;
  }

  void audiosystem_update() {
    //TODO: Perform audio fall off and emitter updating
  }

  int sound_add_from_buffer(int id, void* buffer, size_t size) {
    int i = (int)sounds.size();
    sf::SoundBuffer *buf = new sf::SoundBuffer();
    sf::Sound *snd;

    buf->loadFromMemory(buffer, size);
               
    snd = new sf::Sound();
    snd->setBuffer(*buf);
    sounds.push_back(new PlayableSoundInstance(snd, buf));
    return i;
  }

  void audiosystem_cleanup() {
    //TODO: Cleanup and delete/free sounds/existing buffers from memory
  }

  int sound_allocate() {
    int i = sounds.size();
    sounds.push_back(NULL);
    return i;
  }

  int sound_add_from_stream(int id, size_t (*callback)(void *userdata, void *buffer, size_t size), void (*seek)(void *userdata, float position), void (*cleanup)(void *userdata), void *userdata)
  {
      CustomSoundStream *snd;

      snd = new CustomSoundStream(callback, seek, cleanup, userdata);
      sounds[id] = new PlayableSoundStream(snd);       
      return 0;
  }

}

namespace enigma_user {

int sound_add(std::string fname, int kind, bool preload)
{
  int i = (int)sounds.size();
  sf::SoundBuffer *buffer = new sf::SoundBuffer();
  sf::Sound *snd;
               
  if (!buffer->loadFromFile(fname))
  {
    delete buffer;
    return -1;
  }
  else
  {
    snd = new sf::Sound();
    snd->setBuffer(*buffer);
    sounds.push_back(new PlayableSoundInstance(snd, buffer));
    return i;
  }
}

bool sound_exists(int sound)
{
        return unsigned(sound) < sounds.size();
}

void sound_delete(int sound)
{
        delete sounds[sound];
}

bool sound_replace(int sound, std::string fname, int kind, bool preload)
{
  sf::SoundBuffer *buffer = new sf::SoundBuffer();
  sf::Sound *snd;

  if (!buffer->loadFromFile(fname))
  {
    delete buffer;
    return -1;
  }
  else
  {
    delete sounds[sound];
    snd = new sf::Sound();
    snd->setBuffer(*buffer);
    sounds.push_back(new PlayableSoundInstance(snd, buffer));
    return true;
  }
}

bool sound_play(int sound)
{
        sounds[sound]->play();
        return sounds[sound]->getStatus() == sf::Sound::Playing;
}

void action_sound(int snd, bool loop)
{
        (loop ? sound_loop:sound_play)(snd);
}

bool sound_loop(int sound)
{
        sounds[sound]->setLoop(true);
        sounds[sound]->play();
        return sounds[sound]->getStatus() == sf::Sound::Playing;
}

void sound_stop(int sound)
{
        sounds[sound]->setLoop(false);
        sounds[sound]->stop();
}

void sound_stop_all()
{
        for(unsigned i=0; i < sounds.size(); i++)
        {
          sounds[i]->stop();
        }
}

bool sound_pause(int sound)
{
        sounds[sound]->pause();
        return sounds[sound]->getStatus() == sf::Sound::Paused;
}

void sound_pause_all()
{
        for(unsigned i=0; i < sounds.size(); i++)
        {
          sounds[i]->pause();
        }
}
void sound_resume_all()
{
        for(unsigned i=0; i < sounds.size(); i++)
        {
          if (sounds[i]->getStatus() == sf::Sound::Paused)
                sounds[i]->play();
        }
}

void sound_global_volume(float volume)
{
        sf::Listener::setGlobalVolume(volume);
}

void sound_set_volume(int sound, float volume)
{
        sounds[sound]->setVolume(volume);
}

void sound_seek(int sound, float position)
{
        sounds[sound]->setPlayingOffset(sf::seconds(position));
}

void sound_seek_all(float position)
{
        for(unsigned i=0; i < sounds.size(); i++)
        {
          sounds[i]->setPlayingOffset(sf::seconds(position));
        }
}

void sound_set_pitch(int sound, float pitch)
{
        sounds[sound]->setPitch(pitch);
}

void sound_3d_set_sound_position(int sound, float x, float y, float z)
{
        sounds[sound]->setPosition(x, y, z);
}

void sound_3d_set_sound_distance(int sound, float mindist, float maxdist)
{
        sounds[sound]->setMinDistance(mindist);
        sounds[sound]->setAttenuation(1/(maxdist-mindist));
}

bool sound_isplaying(int sound)
{
        return sounds[sound]->getStatus() == sf::Sound::Playing;
}

bool sound_ispaused(int sound)
{
        return sounds[sound]->getStatus() == sf::Sound::Paused;
}

float sound_get_position(int sound)
{
        return sounds[sound]->getPlayingOffset().asSeconds();
}

float sound_get_length(int sound)
{
        return sounds[sound]->getDuration().asSeconds();
}

unsigned int sound_get_samplerate(int sound)
{
        return sounds[sound]->getSampleRate();
}

unsigned int sound_get_channels(int sound)
{
        return sounds[sound]->getChannelCount();
}

int sound_get_x(int sound)
{
        return sounds[sound]->getX();
}
int sound_get_y(int sound)
{
        return sounds[sound]->getY();
}
int sound_get_z(int sound)
{
        return sounds[sound]->getZ();
}

float sound_get_volume(int sound)
{
        return sounds[sound]->getVolume();
}

float sound_get_pitch(int sound)
{
        return sounds[sound]->getPitch();
}

}
 

Why the errors?

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Linking sfml on Mac OSX
« Reply #1 on: August 26, 2013, 08:08:45 pm »
most probably because of one red warning not read carefully here http://www.sfml-dev.org/tutorials/2.1/start-osx.php  ;)
SFML / OS X developer