Ogre & SFML Audio problem

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
TheNightmare44
Gnoblar
Posts: 17
Joined: Tue May 27, 2014 7:13 pm
Location: Poland

Ogre & SFML Audio problem

Post by TheNightmare44 »

Hi everybody.

At first, I want to say that I'm very new at Ogre and SFML. I'm trying to make a simple game based on Ogre Graphics Engine to earn some experience with these things. So I need some kind of free and useful sound library. I've tried to integrate OpenAL with Ogre (using OgreAL), but I have had many "unresolved external symbol" errors with it (i'm working on VC++ 2008). After hours spent on searching how to solve that problem and testing any possible way to fix it, I decided to change the sound library. Then I've integrated Audiere with the engine and it worked well.
But it was still 2d sound, so I've found another library, which supports three-dimensional sound. It was SFML. I have done the tutorial about setting it up and compiled the project. No errors. But when I started to write the code using the sf namespace, it gives me similar "unresolved external symbol" errors (just like OgreAL):

I've noticed, that that code:

sf::SoundBuffer buffer;

Generates these errors:

BasicTutorial.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::SoundBuffer::SoundBuffer(void)" (__imp_??0SoundBuffer@sf@@QAE@XZ) referenced in function "void __cdecl `dynamic initializer for 'buffer''(void)" (??__Ebuffer@@YAXXZ)
1>BasicTutorial.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::SoundBuffer::~SoundBuffer(void)" (__imp_??1SoundBuffer@sf@@QAE@XZ) referenced in function "void __cdecl `dynamic atexit destructor for 'buffer''(void)" (??__Fbuffer@@YAXXZ)

But when 'buffer' is just a pointer to SoundBuffer class:

sf::SoundBuffer * buffer;

It hasn't got any errors.


So why creating an object of this class (like in the SFML tutorial) makes the problem?
As I said, I'm very new to this stuff, so maybe I do something really simple wrong.

Or if you can explain me what could be wrong with the OgreAL, it will be great.

Thanks for help.
PS. Sorry for my English - I'm from another country. :wink: Please, be forgiving.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: Ogre & SFML Audio problem

Post by Kojack »

This would be because you aren't linking with the sfml audio library.
The header files are enough for a pointer (such as SoundBuffer*) to be ok, but to make an actual instance of the SoundBuffer class you need the library to be linked in.
User avatar
TheNightmare44
Gnoblar
Posts: 17
Joined: Tue May 27, 2014 7:13 pm
Location: Poland

Re: Ogre & SFML Audio problem

Post by TheNightmare44 »

Thanks for reply, but I' ve already linked the .lib files:

sfml-audio-d.lib - for Debug Configuration
sfml-audio.lib - for Release Configuration

Or maybe I missed something?
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Ogre & SFML Audio problem

Post by c6burns »

You did miss something. Linker errors are almost always very simple ... no magic involved. Whatever library defines sf::SoundBuffer::SoundBuffer, you are not linking against it.

The reason this doesn't happen with just a pointer, is that the class constructor isn't being called with a pointer. Once you change to creating an instance of the class, the class constructor is being called. But the class constructor isn't defined anywhere, only declared in the header which got you past the compiler to the linker.
User avatar
TheNightmare44
Gnoblar
Posts: 17
Joined: Tue May 27, 2014 7:13 pm
Location: Poland

Re: Ogre & SFML Audio problem

Post by TheNightmare44 »

Thanks a lot, I think I've understood that.
So, now I'll try to link the correct library.
User avatar
TheNightmare44
Gnoblar
Posts: 17
Joined: Tue May 27, 2014 7:13 pm
Location: Poland

Re: Ogre & SFML Audio problem

Post by TheNightmare44 »

Could somebody (who was trying to use SFML before) tell me, which .lib file I forgot to link?
Isn't sfml-audio-d.lib enough for my project? Because I don't see more these .lib's which may be connected with audio.
User avatar
Thyrion
Goblin
Posts: 224
Joined: Wed Jul 31, 2013 1:58 pm
Location: germany
x 8

Re: Ogre & SFML Audio problem

Post by Thyrion »

as far as i can see the sfml audio example needs:

sfml-audio-d.lib
sfml-system-d.lib
extlibs\libs-msvc\x86\sndfile.lib
extlibs\libs-msvc\x86\openal32.lib

?
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Ogre & SFML Audio problem

Post by c6burns »

I just tried out the library with their 2.1 precompiled package. Thyrion is exactly right about the libs needed, though you don't need to specifically link against anything past the audio lib.

I think the __declspec(dllimport) might be the problem. Perhaps you are linking the static lib, but your includes are exporting for dll. In that case the linker would not find those symbols.

EDIT: yeah, try adding SFML_STATIC to your preprocessor defines if you are linking static, then it won't export the classes on you. And you might have to specifically link sfml-system
User avatar
TheNightmare44
Gnoblar
Posts: 17
Joined: Tue May 27, 2014 7:13 pm
Location: Poland

Re: Ogre & SFML Audio problem

Post by TheNightmare44 »

OK, I've added SFML_STATIC to the Preprocessor Definitions and changed linked .lib files to their static versions . But now, when I compile the project, I have got these errors as a result:

1>BasicTutorial.obj : error LNK2019: unresolved external symbol "public: __thiscall sf::SoundBuffer::SoundBuffer(void)" (??0SoundBuffer@sf@@QAE@XZ) referenced in function "void __cdecl `dynamic initializer for 'buffer''(void)" (??__Ebuffer@@YAXXZ)
1>BasicTutorial.obj : error LNK2019: unresolved external symbol "public: __thiscall sf::SoundBuffer::~SoundBuffer(void)" (??1SoundBuffer@sf@@QAE@XZ) referenced in function "void __cdecl `dynamic atexit destructor for 'buffer''(void)" (??__Fbuffer@@YAXXZ)

(In my code there is only this line of SFML code:
sf::SoundBuffer buffer;)
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Ogre & SFML Audio problem

Post by c6burns »

Yeah sf::SoundBuffer buffer; is instantiating a class, so its calling the default constructor even though you didn't put a () at the end. That's why the linker needs sf::SoundBuffer::SoundBuffer

I don't get what's going on. I've linked it shared and static just fine. Are you using 32 bit lib w/ 64 bit compiler? Can't think of anything else :(
User avatar
TheNightmare44
Gnoblar
Posts: 17
Joined: Tue May 27, 2014 7:13 pm
Location: Poland

Re: Ogre & SFML Audio problem

Post by TheNightmare44 »

I'm using 32bit compiler, if that you mean.
User avatar
TheNightmare44
Gnoblar
Posts: 17
Joined: Tue May 27, 2014 7:13 pm
Location: Poland

Re: Ogre & SFML Audio problem

Post by TheNightmare44 »

OK, I've noticed that I have forgotten to change Runtime Library to Multi-threaded in Code Generation options. But now when I compile the project it generates this error:

1>LINK : fatal error LNK1104: cannot open file 'libboost_thread-vc90-mt-sgd-1_49.lib'

I have read that it is a problem with boost libraries and I can solve it using bjam. But I completly don't know anything about this. Could someone tell me if I can fix it that way or maybe there is another method?
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Ogre & SFML Audio problem

Post by c6burns »

Sounds like you set the project to /MT which is multi threaded static runtime, which means you would need boost built that way as well (sgd vs. gd). /MD is multi threaded dynamic runtime.
User avatar
TheNightmare44
Gnoblar
Posts: 17
Joined: Tue May 27, 2014 7:13 pm
Location: Poland

Re: Ogre & SFML Audio problem

Post by TheNightmare44 »

Yeah, you're right, I've set the project to /MT. So what should I do to get boost built that way too?
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Ogre & SFML Audio problem

Post by c6burns »

Probably there's a link option you pass to b2, like link=static. Boost docu will say. Why the change to static runtime?
User avatar
TheNightmare44
Gnoblar
Posts: 17
Joined: Tue May 27, 2014 7:13 pm
Location: Poland

Re: Ogre & SFML Audio problem

Post by TheNightmare44 »

Don't know, I just thought, that it will be more practical to have libraries integrated to the executable file.

But I could try to change it to /MD if that will help.
User avatar
TheNightmare44
Gnoblar
Posts: 17
Joined: Tue May 27, 2014 7:13 pm
Location: Poland

Re: Ogre & SFML Audio problem

Post by TheNightmare44 »

I have returned to dynamic runtime, as it was at the beginning. So now I have the same problem with these "unresolved external symbol" errors. I don't know what else to do. I've tried to link SFML libraries in other ways (changing their static versions to dynamic and vice versa). But it still gave me similar errors.

With the SFML libs linked dynamically, I've got still the same problem:

1>BasicTutorial.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::SoundBuffer::SoundBuffer(void)" (__imp_??0SoundBuffer@sf@@QAE@XZ) referenced in function "void __cdecl `dynamic initializer for 'buffer''(void)" (??__Ebuffer@@YAXXZ)
1>BasicTutorial.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::SoundBuffer::~SoundBuffer(void)" (__imp_??1SoundBuffer@sf@@QAE@XZ) referenced in function "void __cdecl `dynamic atexit destructor for 'buffer''(void)" (??__Fbuffer@@YAXXZ)

So what else can generate these errors?
Slicky
Bronze Sponsor
Bronze Sponsor
Posts: 614
Joined: Mon Apr 14, 2003 11:48 pm
Location: Was LA now France
x 25

Re: Ogre & SFML Audio problem

Post by Slicky »

You need to link to libraries that are built the same way. It seems like you were almost there at one point and just need to link also to boost (but the correct type to match your build setup).
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Ogre & SFML Audio problem

Post by c6burns »

/MT versus /MD is about how you link against the windows runtime. You are free to link other static libraries and use /MD, as long as they are built using /MD.

Did you build SFML from source with /MT? When I tested this, I used the version 2.1 package precompiled with visual studio 2010. I linked it both statically and dynamically using /MD. All I did to satisfy the linker was add my lib dir (F:\Work\Code\SFML-2.1\lib) to Linker>General>Additional Dirs. Then I added the lib (sfml-audio-d.lib) to Linker>Input>Additional Deps

I feel like switching to /MT is a dead end. The linker simply hasn't got around to the missing symbols because it can't find your boost lib. Once you satisfy that, you will be back where you started.
User avatar
TheNightmare44
Gnoblar
Posts: 17
Joined: Tue May 27, 2014 7:13 pm
Location: Poland

Re: Ogre & SFML Audio problem

Post by TheNightmare44 »

Well, I think the same - switching the \MT and \MD isn't a good idea.
Back to your question - the problem is that I have downloaded SFML package for VC++ 9 (32 bit), not built it from the source code...
User avatar
TheNightmare44
Gnoblar
Posts: 17
Joined: Tue May 27, 2014 7:13 pm
Location: Poland

Re: Ogre & SFML Audio problem

Post by TheNightmare44 »

Any suggestions?

Does it make a big difference that I'm using downloaded SFML package (for VC++ 9) instead of buliding it on my own from the source?
Sorry for noobish question, but I'm new to these things.
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Ogre & SFML Audio problem

Post by c6burns »

As long as you are using VC9 then linking against their precompiled VC9 should not be a problem. I am using VC10 and I linked against their precompiled VC10.

I really can't understand what the problem is at this point. In the rare case that this happens to me, I go and check the symbols or exports of the library against which I am linking. For example:

Code: Select all

F:\Work\Code\SFML-2.1\lib>dumpbin /exports sfml-audio-d.lib
Microsoft (R) COFF/PE Dumper Version 10.00.40219.01
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file sfml-audio-d.lib

File Type: LIBRARY

     Exports

       ordinal    name

                  ??0Music@sf@@QAE@XZ (public: __thiscall sf::Music::Music(void))
                  ??0Sound@sf@@QAE@ABV01@@Z (public: __thiscall sf::Sound::Sound(class sf::Sound const &))
                  ??0Sound@sf@@QAE@ABVSoundBuffer@1@@Z (public: __thiscall sf::Sound::Sound(class sf::SoundBuffer const&))
                  ??0Sound@sf@@QAE@XZ (public: __thiscall sf::Sound::Sound(void))
                  ??0SoundBuffer@sf@@QAE@ABV01@@Z (public: __thiscall sf::SoundBuffer::SoundBuffer(class sf::SoundBuffer const &))
                  ??0SoundBuffer@sf@@QAE@XZ (public: __thiscall sf::SoundBuffer::SoundBuffer(void))
...
I can see sf::SoundBuffer::SoundBuffer(void) is exported, so I know it will be available in the dll once I link against the lib.
User avatar
TheNightmare44
Gnoblar
Posts: 17
Joined: Tue May 27, 2014 7:13 pm
Location: Poland

Re: Ogre & SFML Audio problem

Post by TheNightmare44 »

I have removed all SFML directories from Additional Diretcories and Dependencies. In other words, I have just rebuilt my OGRE project without the SFML libraries. Then I've linked them again and... It works now. The libraries seems to be linked correctly, no linker errors while creating an instance of a class...
I really don't get what was wrong.

However, thank you for your help.
Post Reply