SFML community forums
Bindings - other languages => C => Topic started by: Crank1d on July 25, 2010, 04:38:29 pm
-
I´ve just started with CSFML and i am getting linking errors everytime i try to compile my app (i am using Visual Sudio 2005, as i´ve said in title).
I´ve included all needed libraries for app (csfml-audio.lib, csfml-graphics.lib, csfml-network.lib, csfml-system.lib, csfml-window.lib). Here is the code:
SoundSystem.h
#include <SFML/Audio.h>
#include "DataTypes.h"
// sound
extern void PlayMusic(C8 *FileName);
SoundSystem.cpp
#include "DataTypes.h"
#include "SoundSystem.h"
sfMusic *Music;
void PlayMusic(C8 *FileName)
{
sfMusic_CreateFromFile(FileName);
sfMusic_Play(Music);
// Loop while the music is playing
while(sfMusic_GetStatus(Music) == sfPlaying)
{
sfSleep(0.1f);
}
}
main.cpp
#include "SoundSystem.h"
int main()
{
PlayMusic("data/sound.ogg");
return EXIT_SUCCESS;
}
...and here are the linking errors.
1>Compiling...
1>main.cpp
1>SoundSystem.cpp
1>Linking...
1>SoundSystem.obj : error LNK2001: unresolved external symbol "void __cdecl sfMusic_Play(struct sfMusic *)" (?sfMusic_Play@@YAXPAUsfMusic@@@Z)
1>SoundSystem.obj : error LNK2001: unresolved external symbol "void __cdecl sfSleep(float)" (?sfSleep@@YAXM@Z)
1>SoundSystem.obj : error LNK2001: unresolved external symbol "struct sfMusic * __cdecl sfMusic_CreateFromFile(char const *)" (?sfMusic_CreateFromFile@@YAPAUsfMusic@@PBD@Z)
1>SoundSystem.obj : error LNK2001: unresolved external symbol "enum sfSoundStatus __cdecl sfMusic_GetStatus(struct sfMusic *)" (?sfMusic_GetStatus@@YA?AW4sfSoundStatus@@PAUsfMusic@@@Z)
1>..\bin32\game_c.exe : fatal error LNK1120: 4 unresolved externals
I don´t know if i´ve forgot to set some options to compiler or forgot to include some file... so i´m looking for a help.
-
Is it happening for every SFML function that you use? Even from other modules? If so, make sure that you use the VC2005 libs (not the VC2008 ones, for example).
Or maybe you've made a mistake in the linker options.
-
It happens for every CSFML function that i use (tried to create simple SFML window, it also didnt compiled sucessfully). Using VS2005 version of CSFML SDK and precompiled libraries that came with SDK. Tried to compile SDK from source (compiling succesfull) but it fails to compile without linking errors for my app.
-
Can you send me your project?
-
I´ve sended it on your e-mail adress.
-
This is because you compile in C++. When doing so, the compiler uses the C++ naming rules for imported symbols (for example "?sfMusic_Play@@YAXPAUsfMusic@@@Z") instead of the C ones ("_sfMusic_Play"), that's why it can't find them in the CSFML DLLs.
You have to use this code to tell the compiler to use the C rules:
extern "C"
{
#include <SFML/Audio.h>
}
-
It works! Thanks! I knew that i´ve forgot to add something (didn´t used this "extern C" code for a long time, so i´ve forgot it because of only C++ programming in past years). :D
-
By the way, may I ask why you're using CSFML in C++ code?
-
Can you explain it more closely, why do you think i use CSFML in C++ code (because of C++ source files (.cpp) with C code in it or something else) ? :?: :?
-
because of C++ source files (.cpp) with C code in it
Yes.
-
I´m trying to create a simple 3D OpenGL engine with CSFML similar to Cube Engine http://cubeengine.com/. Cube source files are also .cpp with C code in it and the game uses SDL. I found design of a Cube Engine quite interesting. It won´t be tottally same but i wil try to keep similar design of a Cube source files for code of my project.
-
But why do you use C in C++ sources? And why don't you use the C++ API of SFML (which is far more convenient to use) if you use a C++ compiler?
-
1.) But why do you use C in C++ sources? 2.) And why don't you use the C++ API of SFML (which is far more convenient to use) if you use a C++ compiler?
1.) Experimenting. :wink: But i would probably switch to C++ version of SFML.
2.) I´ve didn´t configured all of the project options yet.