The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
lazyfoo.net Tutorial 33 Will Not Compile
Blaze


Joined: 05 Jul 2015
Posts: 11
Hello, this is my first post, so understand that.

This is not so much a game development question, but since it involves lazyfoo.net's SDL game tutorials I figured I might find help here.

I have followed the lazyfoo.net tutorials so far, compiling them with MinGW on Windows 8.1 and they worked fine, until I get to tutorial 33 (http://lazyfoo.net/tutorials/SDL/33_file_reading_and_writing/index.php), on reading and writing to files. When I compile it with g++, I get a string of errors like this one:

Code:
33_file_reading_and_writing.cpp:370:43: error: 'to_string' is not a member of 's
td'
  gDataTextures[ 0 ].loadFromRenderedText( std::to_string( (_Longlong)gData[ 0 ]
 ), highlightColor );
                                           ^


I searched for this problem and found bug fixes for gcc 4.7 in MinGW, but I have gcc 4.8.1. How can I fix this.
Naith


Joined: 03 Jul 2014
Posts: 158
The to_string - function was introduced in C++ 11 and your compiler might not support it. Might be worth trying another compiler. I use Visual Studio 2013 and I can compile the program fine.
Blaze


Joined: 05 Jul 2015
Posts: 11
No, I don't think that is the problem, because I can use c++11 in MinGW by adding the option -std=c++11. That has worked with other programs but not with this one.
MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
Is

#include <iostream>
#include <string>

being used ?
Blaze


Joined: 05 Jul 2015
Posts: 11
No, this is the original include list:

Code:
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
#include <stdio.h>
#include <string>
#include <sstream>


I tried adding "#include <iostream>" and I still have the same errors.
MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
Wonder if some wrong headers are being used, or even wrong libraries.

And you use pass c++0x to the compiler ?
Blaze


Joined: 05 Jul 2015
Posts: 11
I had been using the option "-std=c++11" which I guess is equivalent to "-std=c++0x". I tried both and they both work with other source code, but not this one.
MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
I suspect to_string has no function for converting (_Longlong)gData[ 0 ] to a string - in which case, you will need to write your own.
Blaze


Joined: 05 Jul 2015
Posts: 11
What I got from other sources is that this is a bug with MinGW for 32-bit applications. I'll just find a workaround.
jungletek


Joined: 30 Oct 2011
Posts: 4
Blaze wrote:
What I got from other sources is that this is a bug with MinGW for 32-bit applications. I'll just find a workaround.


I believe this is a combination of a MinGW bug (update MinGL to a newer version), and a bug/error(?) with Lazy Foo's code.

Changing all instances of '_Longlong' to 'long long' causes the code to compile properly, and the executable seems to perform as expected, as far as I can see. If anyone can let me know if this is in some way an incorrect solution, I'd love to hear it as I'm still very much in the process of learning.

Also make sure you're compiling for the c++11 standard, using the proper compiler flags.