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

Author Topic: VS 2010 and C - initial test program compile problem  (Read 4790 times)

0 Members and 1 Guest are viewing this topic.

Machuse

  • Newbie
  • *
  • Posts: 2
    • View Profile
VS 2010 and C - initial test program compile problem
« 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;

Code: [Select]

 #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]

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
VS 2010 and C - initial test program compile problem
« Reply #1 on: May 01, 2011, 03:55:33 pm »
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:
Code: [Select]
extern "C"
{
    #include <SFML/Audio.h>
    #include <SFML/Graphics.h>
}
Laurent Gomila - SFML developer

Machuse

  • Newbie
  • *
  • Posts: 2
    • View Profile
VS 2010 and C - initial test program compile problem
« Reply #2 on: May 01, 2011, 05:17:12 pm »
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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
VS 2010 and C - initial test program compile problem
« Reply #3 on: May 01, 2011, 05:57:43 pm »
Quote
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).
Laurent Gomila - SFML developer

 

anything