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

Author Topic: C++11 and SFML 2.0  (Read 11529 times)

0 Members and 1 Guest are viewing this topic.

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
C++11 and SFML 2.0
« on: February 14, 2013, 04:42:46 am »
I was working with the network module from SFML 2.0 this morning and tried to use the std::thread class that was introduced in C++11 and noticed that I could only use sf::Thread class from SFML.

Am I doing something wrong? or is C++11 not supported yet on SFML 2.0?

As a side note I'm on a Mac so I'm not sure if that's the issue.

Gan

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
Re: C++11 and SFML 2.0
« Reply #1 on: February 14, 2013, 04:56:07 am »
You have to compile SFML using clang and the C++11 flag.
The flag needs to be for C and CXX.
I think it gets more specific in the compile for Xcode tutorial.

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: C++11 and SFML 2.0
« Reply #2 on: February 14, 2013, 06:10:36 am »
Where do I set flags? and are you talking about the tutorial found in the tutorials section of the site? or is it somewhere on the forums? :)

Gan

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
Re: C++11 and SFML 2.0
« Reply #3 on: February 14, 2013, 06:39:21 am »
You set the flags when setting up the Cmake.

It's in the tutorial section for 2.0. Specifically Cmake.

http://www.sfml-dev.org/tutorials/2.0/start-osx.php

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: C++11 and SFML 2.0
« Reply #4 on: February 14, 2013, 06:49:09 am »
Thanks! :D

Is it known if SFML will ever just support C++11 out of the box like it does with the current version of C++?

Gan

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
Re: C++11 and SFML 2.0
« Reply #5 on: February 14, 2013, 07:28:56 am »
C++11 only works on mac os 10.7+ I believe. That's probably why it isn't default.

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: C++11 and SFML 2.0
« Reply #6 on: February 14, 2013, 07:38:13 am »
I am running Mac OSX 10.7.5 and have my Xcode update to the latest version.  I can run C++11 features fine without SFML, just with SFML I can't seem to use C++11 :o

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: C++11 and SFML 2.0
« Reply #7 on: February 14, 2013, 08:07:36 am »
SFML doesn't have to support C++11 for it to work in your own code. If it doesn't work, then there's probably something wrong in your setup or environment. Please describe the exact errors that you get.
Laurent Gomila - SFML developer

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: C++11 and SFML 2.0
« Reply #8 on: February 14, 2013, 08:30:43 am »
Okay, I typed up the code under the Networking tutorial for SFML and included <thread>

#include <iostream>
#include <thread>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include "ResourcePath.hpp"

using namespace sf;
using namespace std;

int main(){
    RenderWindow window(VideoMode(800, 600), "SFML Networking - MarcuzPwnz");
   
    cout << "Would you like to be a server or client? (c/s)" << endl;
    char input = ' ';
    cin >> input;
    if(input == 'c'){
    /* CLIENT */
        TcpSocket socket;
        socket.connect("localhost", 1337);
       
        string message = "Hey, I'm the client!";
        socket.send(message.c_str(), message.size() + 1);
       
        char buffer[1024];
        size_t received = 0;
        socket.receive(buffer, sizeof(buffer), received);
        cout << "[Server]: " << buffer << endl;
            }else{
    /* SERVER */
        TcpListener listener;
        listener.listen(1337);
       
        TcpSocket socket;
        listener.accept(socket);
        cout << "Client connected: " << socket.getRemoteAddress() << endl;
       
        char buffer[1024];
        size_t received;
        socket.receive(buffer, sizeof(buffer), received);
        cout << "Client: " << buffer << endl;
       
        string message = "Welcome client!";
        socket.send(message.c_str(), message.size() + 1);
       
    }
   
    while(window.isOpen()){
       
       
        Event event;
        while(window.pollEvent(event)){
           
        }
    }
    return 0;
}

The code runs fine without #include <thread> on the second line, but with it I get errors.

Error: Lexical or Preprocessor Issue. 'thread' file not found.

Thanks for the reply. :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: C++11 and SFML 2.0
« Reply #9 on: February 14, 2013, 08:38:34 am »
Your compiler is probably not configured properly.

What about this code, with the exact same setup (ie. don't create a new project to try it)?

#include <thread>

int main()
{
    return 0;
}
Laurent Gomila - SFML developer

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: C++11 and SFML 2.0
« Reply #10 on: February 14, 2013, 08:44:30 am »
Yep, I still get an error with the code you posted above.

Any clue what I would be doing wrong with my setup?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: C++11 and SFML 2.0
« Reply #11 on: February 14, 2013, 08:49:21 am »
C++11 is probably not enabled. I can't help more, I'm not an OS X expert.
Laurent Gomila - SFML developer

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: C++11 and SFML 2.0
« Reply #12 on: February 14, 2013, 08:53:28 am »
Hmm ok :/

Like I said, projects without SFML work with C++11 fine, just seems odd it stops working as soon as I link SFML.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: C++11 and SFML 2.0
« Reply #13 on: February 14, 2013, 09:10:40 am »
Linking SFML cannot produce preprocessor errors. These are two different worlds. So while adding SFML, you probably changed something else. Try to restart a project from scratch.
Laurent Gomila - SFML developer

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: C++11 and SFML 2.0
« Reply #14 on: February 14, 2013, 09:12:03 am »
Sorry, my language isn't 100% correct.

Will do. :)