SFML community forums
Bindings - other languages => C => Topic started by: Machuse on May 01, 2011, 03:41:53 pm
-
Just trying to get my feet wet.
using VS 2010 and SFML 1.6
I have included the libs in additional dependicies :
csfml-system-s.lib;csfml-window-s.lib;csfml-graphics-s.lib;
#include <SFML/Audio.h>
#include <SFML/Graphics.h>
int main()
{
sfWindowSettings Settings = {24, 8, 0};
sfVideoMode Mode = {800, 600, 32};
sfRenderWindow* App;
/* Create the main window */
App = sfRenderWindow_Create(Mode, "SFML window", sfResize | sfClose, Settings);
if (!App)
return EXIT_FAILURE;
sfRenderWindow_Destroy(App);
return EXIT_SUCCESS;
}
I am getting
Error 3 error LNK1120: 2 unresolved externals B:\Dropbox\***\Experimentation\Gorgon\Dev\Gorgon\Source\Gorgon\Release\Gorgon.exe Gorgon
Error 1 error LNK2001: unresolved external symbol "struct sfRenderWindow * __cdecl sfRenderWindow_Create(struct sfVideoMode,char const *,unsigned long,struct sfWindowSettings)" (?sfRenderWindow_Create@@YAPAUsfRenderWindow@@UsfVideoMode@@PBDKUsfWindowSettings@@@Z)
B:\Dropbox\***\Experimentation\Gorgon\Dev\Gorgon\Source\Gorgon\main.obj Gorgon
Error 2 error LNK2001: unresolved external symbol "void __cdecl sfRenderWindow_Destroy(struct sfRenderWindow *)" (?sfRenderWindow_Destroy@@YAXPAUsfRenderWindow@@@Z) B:\Dropbox\PrideOfConcept\Experimentation\Gorgon\Dev\Gorgon\Source\Gorgon\main.obj Gorgon
I get this error when using the static libs and the dll's (with the corresponding Macro enabled)
Thanks[/code]
-
First, you can't use CSFML static libs, unless you're compiling with a C++ compiler.
Then, if you're using a C++ compiler, you must enclose the CSFML includes in a extern "C" block:
extern "C"
{
#include <SFML/Audio.h>
#include <SFML/Graphics.h>
}
-
Thank you,
That actually got it working right out the box.
I am using the standard VS2010.
Only strange thing is, I have to use the extern - even when using the dll's is this correct?
i.e. linking to csfml-system.lib;csfml-window.lib;csfml-graphics.lib;
and SFML_DYNAMIC macro set
-
Only strange thing is, I have to use the extern - even when using the dll's is this correct?
Yes. extern "C" tell the linker to look for the C names of the functions that it finds in the header, instead of the C++ ones (C and C++ have different name mangling conventions for compiled symbols).