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

Author Topic: Installing SFML in Visual C++ 2010  (Read 13551 times)

0 Members and 1 Guest are viewing this topic.

Raptor88

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
Installing SFML in Visual C++ 2010
« on: June 19, 2012, 10:00:38 am »
Well, I finally got SFML installed and working with VC++ 2010.  My problem was that I was using the steps per a youtube tutorial and copied that C++ code instead of following the tutorial on the SFML website and using the provided code.  My bad. Just mentioning this to help other newbies so they don't make the same mistake that I did.

My question now is:
Do I need to enter all of the info into VC++ for every project that uses SFML?  Or is there a way to do it just once?

Thanks,
Raptor

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Installing SFML in Visual C++ 2010
« Reply #1 on: June 19, 2012, 10:07:46 am »
Global search paths have disappeared in VS 2010, but I heard that you can do some interesting things with property sheets.
Laurent Gomila - SFML developer

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Installing SFML in Visual C++ 2010
« Reply #2 on: June 19, 2012, 01:52:03 pm »
There are still global (user level) paths you can define, but they're a bit hidden:
http://msdn.microsoft.com/en-us/library/Ee855621(v=vs.100).aspx

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Installing SFML in Visual C++ 2010
« Reply #3 on: June 19, 2012, 05:31:01 pm »
Mario, your link describes only the two project-specific ways to set the directory: Project properties and property sheets. I don't think it is possible to let a newly-generated project automatically use a user-defined path.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Raptor88

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
Re: Installing SFML in Visual C++ 2010
« Reply #4 on: June 20, 2012, 12:38:48 am »
Global search paths have disappeared in VS 2010, but I heard that you can do some interesting things with property sheets.

Thanks Laurent.  Will research property sheets.
Raptor

Raptor88

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
Re: Installing SFML in Visual C++ 2010
« Reply #5 on: June 20, 2012, 12:39:35 am »
There are still global (user level) paths you can define, but they're a bit hidden:
http://msdn.microsoft.com/en-us/library/Ee855621(v=vs.100).aspx

Mario,
Will check out the link you gave.  Thanks,
Raptor

Raptor88

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
Re: Installing SFML in Visual C++ 2010
« Reply #6 on: June 20, 2012, 01:06:26 am »
Well, I finally got SFML installed and working with VC++ 2010.  My problem was that I was using the steps per a youtube tutorial and copied that C++ code instead of following the tutorial on the SFML website and using the provided code.  My bad. Just mentioning this to help other newbies so they don't make the same mistake that I did.

Laurent,

When I got VC++ 2010 working with SFML 2.0 using your tutorial for SFML 2.0 (http://www.sfml-dev.org/tutorials/2.0/start-vc.php), it was with the project I had  already started using a youtube tutorial on installing SFML 2.0 with VC++ 2010.

After I got it working, I tried following your tutorial from scratch using a new project.  When I ran debug, I received an error that said 16 links were misssing or something to that effect.  I discovered that I had to insert the following right after the

"Warning
It is important to link to the libraries that match the configuration: "sfml-xxx-d.lib" for Debug, and "sfml-xxx.lib" for Release. A bad mix may result in crashes."

to get VC++ 2010 to compile without errors:

==========
Running debug at this time resulted in 16 errors.  The fix was to link Debug to the five "sfml-xxx-d.lib" libraries.  To do this, use the screen capture above, click the down arrow for the "Configuration" text box, and select "Debug".  Then for the "Additional Dependencies" enter the five sfml libraries that have the -d (for debug) as follows:

---------- Insert This ----------
... sfml-graphics-d.lib
... sfml-window-d.lib
... sfml-system-d.lib
... sfml-audio-d.lib
... sfml-network-d.lib

Now VC++ compiled the Laurent supplied code without any errors.
==========

Maybe you already alluded to doing that but it wasn't obvious to me as a beginner.  If you find my comments have merit, maybe consider adding the screen shot of adding the -d libraries to debug.

FWIW, thanks to the youtube author.  Without following his tutorial first, I would  not have been able to figure out how to recover from the 16 errors.  Also, his tutorial showed how to copy the smfl dll files to the folder containing main.cpp which also allowed SFML to compile without errrors with VC++ 2010.  Laurent, maybe also consider adding that to the SFML 2.0 tutorial for completeness to help beginners get SFML 2.0 working with VC++ 2010.

Thanks,
Raptor

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Installing SFML in Visual C++ 2010
« Reply #7 on: June 20, 2012, 08:07:40 am »
It seems like you don't understand what you do, or at least what you did to make it "work" ;)

Quote
The fix was to link Debug to the five "sfml-xxx-d.lib" libraries.
It's not a fix. The example uses three modules: system, window and graphics, which the tutorial says you must link. The two other modules are not needed (unless you added some network or audio code).
I'd like to see those 16 link errors to find out what really happened.

Quote
Also, his tutorial showed how to copy the smfl dll files to the folder containing main.cpp which also allowed SFML to compile without errrors with VC++ 2010
The tutorial says that too (and I assume you know how to copy files on Windows). You mustn't copy them to the folder containing main.cpp, but to the folder containing the executable. Then you must configure your project so that the working directory is this folder when you run the program from Visual Studio (maybe I should explain that in the tutorial).
And copying DLLs never solved compile errors, only runtime errors.

Quote
Laurent, maybe also consider adding that to the SFML 2.0 tutorial for completeness to help beginners get SFML 2.0 working with VC++ 2010.
I can add more details, but when I find the right solution to your problems. So please describe what happened, post the error messages, instead of solutions that happen to work by chance.
Laurent Gomila - SFML developer

Raptor88

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
Re: Installing SFML in Visual C++ 2010
« Reply #8 on: June 22, 2012, 12:52:15 am »
I can add more details, but when I find the right solution to your problems. So please describe what happened, post the error messages, instead of solutions that happen to work by chance.
Am on the road now.  Will do a write-up when I get back home.
Thanks,
Raptor

Raptor88

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
Re: Installing SFML in Visual C++ 2010
« Reply #9 on: June 26, 2012, 07:58:32 am »
I can add more details, but when I find the right solution to your problems. So please describe what happened, post the error messages, instead of solutions that happen to work by chance.

Hi Laurent,

Here is the step-by-step procedure that I have to use to get the sample C++ code from the SFML 2.0 tutorial working in VC++ 2010 Express.  Note that up to step-6, the procedures are what are shown in the SFML 2.0 Tutorial.

Step-7 corrects the errors in step-6.  Step-9 corrects the error in step-8.  These steps were not apparent to me as a SFML beginner, by reading the 2.0 tutorial.

1. Open VC++ 2010 Express

2. Click "New Project":
.... a. Select "Visual C++" in left pane.
.... b. Select "Empty Project" in right pane.
.... c. In Name text box, enter name of project.
.... d. In Location text box, enter path where project will be stored.
.... e. Click OK.

3. In VC++:
.... a. Click "Project > Add New Item".
.... b. Select "Code" in left pane. (do not select "Visual C++" or CLR warning will appear)
.... c. Select "C++ File (.cpp)" in right pane.
.... d. Enter name of the .cpp file as "main".
.... e. Click ADD.
.... f. A blank main.cpp file opens in right pane.

4. Paste the sample SFML code from "file:///D:/SFML%20-2.0%20Install%20Tutorial/Install%20SFML%20for%20VC++.htm"

5. Click "Project > ProjectName Properties.
.... a. Click + to expand "Configuration Properties".
.... b. Select "C/C++ > General" in left pane.
........ 1. *** Select "All Configurations" in the Configuration text box. ***
........ 2. Click "Additional Include Directories" in right pane, click down arrow > Edit.
........ 3. Type or navigate to "D:\SFML -2.0\include" (where ever "include" is on your computer).
........ 4. Click APPLY.
.... c. Select "Linker > General" in left pane.
........ 1. *** Select "All Configurations" in the Configuration text box. ***
........ 2. Click "Additional Library Directories" in right pane, click down arrow > Edit.
........ 3. Type or navigate to "D:\SFML -2.0\lib" (where ever "lib" is on your computer).
........ 4. Click APPLY.
.... d. Select "Linker > Input" in left pane.
........ 1. *** Select "Release" in the Configuration text box. ***
........ 2. Click "Additional Dependencies" in right pane, click down arrow > Edit.
........ 3. Type the links to the SFML libraries you will need.  The five libraries are:
............ a. sfml-graphics.lib, sfml-window.lib, sfml-system.lib, sfml-audio.lib, sfml-network.lib
............ b. For windows application, also link to:  sfml-main.lib

6. Run VC++ debug:
.... a. Got the following errors:

1>------ Build started: Project: Test 02, Configuration: Debug Win32 ------
1>  main.cpp
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::RenderWindow::~RenderWindow(void)" (__imp_??
1RenderWindow@sf@@UAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::Text::~Text(void)" (__imp_??1Text@sf@@UAE@XZ) referenced in
function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::display(void)" (__imp_?display@Window@sf@@QAEXXZ)
referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::RenderTarget::draw(class sf::Drawable const &,class sf::RenderStates
const &)" (__imp_?draw@RenderTarget@sf@@QAEXABVDrawable@2@ABVRenderStates@2@@Z) referenced in function _main
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class sf::RenderStates const sf::RenderStates::Default" (__imp_?
Default@RenderStates@sf@@2V12@B)
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::RenderTarget::clear(class sf::Color const &)" (__imp_?
clear@RenderTarget@sf@@QAEXABVColor@2@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Color::Color(unsigned char,unsigned char,unsigned char,unsigned char)"
(__imp_??0Color@sf@@QAE@EEEE@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::close(void)" (__imp_?close@Window@sf@@QAEXXZ)
referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Window::pollEvent(class sf::Event &)" (__imp_?
pollEvent@Window@sf@@QAE_NAAVEvent@2@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Window::isOpen(void)const " (__imp_?
isOpen@Window@sf@@QBE_NXZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::String::~String(void)" (__imp_??1String@sf@@QAE@XZ) referenced in
function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Text::Text(class sf::String const &,class sf::Font const &,unsigned int)"
(__imp_??0Text@sf@@QAE@ABVString@1@ABVFont@1@I@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class sf::Font const & __cdecl sf::Font::getDefaultFont(void)" (__imp_?
getDefaultFont@Font@sf@@SAABV12@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::String::String(char const *,class std::locale const &)" (__imp_??
0String@sf@@QAE@PBDABVlocale@std@@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::RenderWindow::RenderWindow(class sf::VideoMode,class
std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned int,struct sf::ContextSettings const &)" (__imp_??
0RenderWindow@sf@@QAE@VVideoMode@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@IABUContextSettings@1@@Z) referenced in function
_main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (__imp_??
0VideoMode@sf@@QAE@III@Z) referenced in function _main
1>D:\C++ Projects\Test 02\Debug\Test 02.exe : fatal error LNK1120: 16 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

7. To get rid of these errors:
.... a. Select "Linker > Input" in left pane.
........ 1. *** Select "Debug" in the Configuration text box. ***
........ 2. Click "Additional Dependencies" in right pane, click down arrow > Edit.
........ 3. Type the links to the SFML libraries you will need.  The five libraries are:
............ a. sfml-graphics-d.lib, sfml-window-d.lib, sfml-system-d.lib, sfml-audio-d.lib, sfml-network-d.lib
............ b. For windows application, also link to:  sfml-main-d.lib

8. Run VC++ debug:
.... a. Got the following error:

Test 02.exe - System Error
The program caan't start because sfml-graphics-d-2.dll is missing from
your computer.  Try reinstalling the program to fix this problem.

9. To get rid of this error:
.... a. Copy and paste all of the SFML dll files in the bin folder to the same folder the main.cpp file is in:
........ 1. Go to D:\SFML-2.0\bin.
........ 2. Copy all of the dll files.
........ 3. In VC++, right click the "main.cpp" tab at the top of the right pane to open the folder where main.cpp is stored.
........ 4. Paste all of the dll files.

10. Run VC++ debug:
.... a. Now everything compiles without errors and the SFML window is displayed with "Hello SFML" text displayed.

11. ==== DONE ====

BTW, is step-5.d.3.b "....b. For windows application, also link to:  sfml-main.lib" correct?
The link to sfml-main.lib was added per:
"If you chose to create a "Windows application" project, then the entry point of your code has to be the "WinMain" function instead of "main". Since it's Windows specific, and your code would therefore not compile on Linux or Mac OS X, SFML provides a way to keep a standard "main" entry point in this case: link your project to the sfml-main module ("sfml-main-d.lib" in Debug, "sfml-main.lib" in Release), the same way you linked sfml-graphics, sfml-window and sfml-system. "

Thanks,
Raptor

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Installing SFML in Visual C++ 2010
« Reply #10 on: June 26, 2012, 08:10:41 am »
Quote
1. *** Select "Release" in the Configuration text box. ***
[...]
6. Run VC++ debug:
.... a. Got the following errors
So, to you, "set the Release settings and then run the Debug configuration" is what the tutorial says, and I should add "set the Debug settings" as a fix? Seriously? Isn't "oh yeah that was a stupid mistake" a more obvious conclusion? ???

Quote
The program caan't start because sfml-graphics-d-2.dll is missing from
your computer.  Try reinstalling the program to fix this problem.

9. To get rid of this error:
.... a. Copy and paste all of the SFML dll files in the bin folder to the same folder the main.cpp file is in:
It's written in the tutorial.

Quote
BTW, is step-5.d.3.b "....b. For windows application, also link to:  sfml-main.lib" correct?
Yes, this is correct.
Laurent Gomila - SFML developer

Raptor88

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
Re: Installing SFML in Visual C++ 2010
« Reply #11 on: June 26, 2012, 08:41:10 am »
Quote
1. *** Select "Release" in the Configuration text box. ***
[...]
6. Run VC++ debug:
.... a. Got the following errors
So, to you, "set the Release settings and then run the Debug configuration" is what the tutorial says, and I should add "set the Debug settings" as a fix? Seriously? Isn't "oh yeah that was a stupid mistake" a more obvious conclusion? ???

Quote
The program caan't start because sfml-graphics-d-2.dll is missing from
your computer.  Try reinstalling the program to fix this problem.

9. To get rid of this error:
.... a. Copy and paste all of the SFML dll files in the bin folder to the same folder the main.cpp file is in:
It's written in the tutorial.

Quote
BTW, is step-5.d.3.b "....b. For windows application, also link to:  sfml-main.lib" correct?
Yes, this is correct.

Hi Laurent,

Yes, I figured all of the steps were there but my problems were ignorance on my part.  As a beginner in VC++ and SFML, a lot is not apparent as it is to experienced programmers.

Thanks for your response and helping us out in this forum,
Raptor

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Installing SFML in Visual C++ 2010
« Reply #12 on: June 26, 2012, 08:54:44 am »
I know it's hard for beginners to figure out all these configuration steps. The SFML tutorials try to provide a step-by-step explanation that works out of the box, but it cannot solve all the problems (however it could solve 99.9% of them if people read the tutorials really carefully ;) ).

I think that people should take some time to learn how to use their development environment, rather than blindly following the step-by-step tutorials of every library that they use. There are only a few things to remember in order to add a new library: include/linker paths, input libraries, and copying the DLLs. Once you know that, you won't even have to follow the "getting started" tutorials of libraries :)

And thanks for the time you took to describe what you did.
« Last Edit: June 26, 2012, 08:56:34 am by Laurent »
Laurent Gomila - SFML developer

singlejeopardy

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Installing SFML in Visual C++ 2010
« Reply #13 on: August 05, 2012, 10:42:13 pm »
As someone who was completely new and just figured out how to do it, I would suggest clarifying right after this line in the tutorial:

Quote
These paths are the same in both Debug and Release configuration, so you can set them globally for your project ("All configurations").

Just mention to set the "Configuration" text box in the upper left to "Release" and "Debug" before linking to their respective libraries. I think because you never mention changing it from All Configurations to something else, it gets confusing. When I read the line about linking to the proper libraries between debug and release, I had no idea what to change and must have spent 30 minutes looking for debug and release in the configuration properties. I finally looked back at the tutorials and noticed the configuration box was different in the screenshots (but not outlined in red   :-[ )

 

anything