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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - practikalmagik

Pages: [1]
1
Thank you, keeping the Sound object as a permanent part of the Game class is what worked!
 I had done the same with the background music so I'm feeling silly that I didn't just do the same with a Sound object too.

2
Thanks for pointing that bit out (must have missed it last time).
Additional Dependencies are now:
sfml-graphics-s-d.lib;sfml-window-s-d.lib;sfml-system-s-d.lib;opengl32.lib;winmm.lib;gdi32.lib

sfml-graphics-s.lib;sfml-window-s.lib;sfml-system-s.lib;opengl32.lib;winmm.lib;gdi32.lib

However, I'm still getting the imilar errors (only 10 of them this time though!)

Error   LNK2001   unresolved external symbol _jpeg_std_error   ConsoleApplication2   C:\Users\NAME\Documents\Visual Studio 2015\Projects\ConsoleApplication2\ConsoleApplication2\sfml-graphics-s.lib(ImageLoader.cpp.obj)   1   1   

Error   LNK2001   unresolved external symbol _jpeg_CreateCompress   ConsoleApplication2   C:\Users\NAME\Documents\Visual Studio 2015\Projects\ConsoleApplication2\ConsoleApplication2\sfml-graphics-s.lib(ImageLoader.cpp.obj)   1   1   



have you added the -s & -s-d lib files to:

C:\Users\NAME\Documents\Visual Studio 2015\Projects\ConsoleApplication2\ConsoleApplication2
I know some turoeials only tell you to add the standard lib files.
- isn't that essentially what I am doing by providing the SFML/lib address for additional library directories and then adding the addtional dependencies as above?

Or do I also need to copy the lib files over to the project folder too? So far the only thing I have added to the project folder was the .dll files from sfml/bin.

3
Yup sorry I should have added them originally. Edited OP to add.

4
General / [SOLVED]Unresolved external symbol when statically linking
« on: July 27, 2016, 03:38:13 pm »
SOLUTION:
Firstly, thanks to the patient community who helped me (eventually) figure this out. The answer was in the tutorials and FAQs but it didn't click for me in the way it was written. So just in case anyone finds this thread in a similar situation, the Additional Dependencies needs to include ALL the window libs, not just the SFML libs,opengl32,winmmn.lib and gdi32.lib. As such, mine now works with them as:
Debug
sfml-window-s-d.lib;sfml-graphics-s-d.lib;sfml-audio-s-d.lib;sfml-network-s-d.lib;sfml-system-s-d.lib;sfml-main-d.lib;opengl32.lib;winmm.lib;gdi32.lib;freetype.lib;jpeg.lib;openal32.lib;flac.lib;vorbisenc.lib;vorbisfile.lib;vorbis.lib;ogg.lib;ws2_32.lib;
Release
sfml-window-s.lib;sfml-graphics-s.lib;sfml-audio-s.lib;sfml-network-s.lib;sfml-system-s.lib;sfml-main.lib;opengl32.lib;winmm.lib;gdi32.lib;freetype.lib;jpeg.lib;openal32.lib;flac.lib;vorbisenc.lib;vorbisfile.lib;vorbis.lib;ogg.lib;ws2_32.lib;


ORIGINAL POST:
I am having problems with static linking in SFML and Visual Studio. I'm having this linking problem in my game so I thought I would test out why by going back to basics by following the tutorial below:
http://www.sfml-dev.org/tutorials/2.2/start-vc.php

Using dynamic linking (and copying the .dlls from the sfml/bin folder to the project folder) it works as expected and I get that lime green circle as per the tutorial.

However if I then add the -s suffix as below:
Debug:
sfml-graphics-s-d.lib;sfml-window-s-d.lib;sfml-system-s-d.lib
Release:
sfml-graphics-s.lib;sfml-window-s.lib;sfml-system-s.lib

and add the SFML_STATIC macro to c/c++ preprocessor defintion I get a lot of "unresolved external symbol" errors referring to the sfml-graphics-s.lib, with the same error if its build in debug or release mode.

Can anyone advise as I can't see what I have missed from the tutorial and it works fine dynamically.

EDITED TO ADD ERRORS:

Error   LNK2001   unresolved external symbol __imp__glReadPixels@28   ConsoleApplication2   C:\Users\NAME\Documents\Visual Studio 2015\Projects\ConsoleApplication2\ConsoleApplication2\sfml-graphics-s.lib(RenderWindow.cpp.obj)   1   1   

Error   LNK2001   unresolved external symbol __imp__glBlendFunc@8   ConsoleApplication2   C:\Users\NAME\Documents\Visual Studio 2015\Projects\ConsoleApplication2\ConsoleApplication2\sfml-graphics-s.lib(RenderTarget.cpp.obj)   1   1   


etc. There are about 65 of these errors, all the same error type of LNK2001 for various functions in the sfml-graphics.lib

5
I appreciate your response and I feel like I'm getting a better understanding of how this works. Sorry to ask further but I'm struggling to figure out where to put the call to play the Sound in my game.
I have a standard game loop of:
eventHandler
update
draw
restart after certain time

and at the moment, the Sound.play() line is in the event handler (so when the player picks something up a sound plays). If I have the following code the sound does play, but it pauses the game loop until it's finished playing (as the while loop is holding everything up):
sf::Sound sound;
        sound.setBuffer(buffer);
        sound.play();
        while (sound.getStatus() == sf::Sound::Playing) {

        }

however if I remove the while loop it doesn't play at all, I assume as the game loop is much faster than the sound length so it doesn't get a chance to play, before the object is destroyed.

I'm struggling to figure out where to put this sound.play() call, as I essentially want it to run simultaneously to the game loop. I sure I'm overcomplicating things but I just can't seem to put this bit together in my head!

6
Thanks for a quick response. I tried arranging the code as per your example and the Sound is now playing. Hurrah! It makes sense that the sound needs time to play before moving to the return statement. Thanks!  :D

This causes an issue when I'm running the full game as the game loop pauses while the sound is playing in that while loop but I'm sure I can probably figure the appropriate solution to that.

7
I have been working on a game using SFML and have managed to implement Music objects without problems. However, I can't seem to get a Sound object to work. I've tried a bare bones SFML project as per code below to make sure it's not anything related to my game and it still doesn't play a sound. The program just runs through and returns at the end, with no error messages.

SFML version 2.3.2
Visual Studio 2015

#include <SFML/Audio.hpp>
#include <iostream>

int main()
{
        sf::SoundBuffer buffer;
        sf::Sound sound;

        if (!buffer.loadFromFile("assets/sounds/pickup.wav")) {
               //error handling
                std::cout << "can't find sound file" << std::endl;
        }
        sound.setBuffer(buffer);

        if (sound.getStatus() != sf::Sound::Playing) {
                sound.play();
        }
        return 0;
}

The error handling message doesn't trigger so it seems to be loading ok, and its from the same folder as the correctly working music wav file. During debugging I have set a breakpoint at the sound.play() function and it definitely calls this, with the sound object seeming to hold the correct data (e.g. sound duration looks right etc). However it does have the following message:
sound   <Information not available, no symbols loaded for sfml-audio-d-2.dll>   sf::Sound

I've tried googling and it seems that there might be an issue with the .dll or .lib so I've checked these again and I'm sure I have this right:

All sfml 2.3.2 dll files are all in the same folder as main.

Project properties:
Debug
C/C++ - Additional Include Directories = C:\Users\[name]\Documents\SFML-2.3.2\include
Linker - Additional Library Directories = C:\Users\[name]\Documents\SFML-2.3.2\lib
Linker - Additional Dependencies = sfml-audio-d.lib;sfml-graphics-d.lib;sfml-window-d.lib;sfml-system-d.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)

Release
C/C++ - Additional Include Directories = C:\Users\[name]\Documents\SFML-2.3.2\include
Linker - Additional Library Directories = C:\Users\[name]\Documents\SFML-2.3.2\lib
Linker - Additional Dependencies = sfml-audio.lib;sfml-graphics.lib;sfml-window.lib;sfml-system.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)

Can anyone advise as I feel like I'm banging my head against a wall here. I hope this is enough info but let me know if you want to know anything else about the setup.

Pages: [1]