0

I've recently managed to set up SFML for qt creator however upon compilation of the code bellow, I get three strange errors which have nothing to do with my program. I must specify other C++ programs run fine. This is the code:

#include <SFML/System.hpp>
#include <iostream>

int main()
{
    sf::Clock Clock;
    while (Clock.GetElapsedTime() < 5.f)
    {
        std::cout << Clock.GetElapsedTime() << std::endl;
        sf::Sleep(0.5f);
    }

    return 0;
}

The errors are as follows:

f:\SFML-1.6\include\SFML\System\Unicode.hpp:82: error: C2535: 'sf::Unicode::Text::Text(const wchar_t *)' : member function already defined or declared

f:\SFML-1.6\include\SFML\System\Unicode.hpp:87: error: C2535: 'sf::Unicode::Text::Text(const std::wstring &)' : member function already defined or declared

f:\SFML-1.6\include\SFML\System\Unicode.hpp:99: error: C2535: 'sf::Unicode::Text::operator std::wstring(void) const' : member function already defined or declared

Any idea what may be causing this?

EDIT:

I should also mention I never touched the files which give the errors. All I tried was to paste the sample code from the SFML website which resulted in the errors above. I believe I've set up SFML correctly.

EDIT2: I'm using Windows XP SP3, Mingw compiler

Bugster
  • 1,552
  • 8
  • 34
  • 56
  • No idea, but usually I would look at the pre-processed version of the source (myfile.cpp). Usually the option is -E, but might differ based on compiler. something like: `CC -E my.cpp > preprocessed.cpp`, --edit-- you would need to use all other cmd line opts passed to CC normally. – Kashyap Aug 21 '12 at 14:58
  • According to [source code](http://www.sfml-dev.org/documentation/1.4/Unicode_8hpp_source.php), the most probable reason is that somewhere you have `typedef wchar_t Unit16`, or `typedef Uint16 wchar_t` – Lol4t0 Aug 21 '12 at 17:06
  • @Lol4t0, That's impossible I didn't even touch it, but I will take a look. – Bugster Aug 21 '12 at 17:09
  • @It may depend on config and system headers. – Lol4t0 Aug 21 '12 at 17:14
  • 2
    Given that you're combining this with Qt, I seem to recall that this might be caused by your Qt configuration. That is, there probably is a Zc:wchar_t option enabled in your qmake.conf... Perhaps that gives you some Google-fu already. – Bart Aug 22 '12 at 15:00
  • @Bart Thanks, that's very useful and I'll further research this problem, I love Qt and developing things just seems easier on it. Thanks! – Bugster Aug 22 '12 at 15:06

2 Answers2

1

I faced the problem a long time ago, the only solution and explanation that worked for me (Copying from another forum post that I originally consulted):

QMake sets the compiler option treat wchar_t as a built-in type to false, making wchar_t a typedef to unsigned short, which makes functions overloaded for both unsigned short and wchar_t (like the sf::Unicode::Text constructor) fail...

I think the only solution, other than modifying SFML sources, is to change the option "Zc:wchar_t" to "-Zc:wchar_t" in your \mkspecs\win32-msvc2008\qmake.conf file. And then probably recompile Qt.

I changed my configuration file and recompiled qt and it has started working as a charm.

Seçkin Savaşçı
  • 3,446
  • 2
  • 23
  • 39
0

According to http://msdn.microsoft.com/en-us/library/dh8che7s%28v=vs.80%29.aspx

If /Zc:wchar_t- is specified, the compiler requires you to either define wchar_t or to include one of the many header files that defines it (for example, wchar.h). Typically, wchar_t is defined as an unsigned short.

To set this compiler option in the Visual Studio development environment

Open the project's Property Pages dialog box. For details, see Modifying Project Settings.

Click the C/C++ folder.

Click the Language property page.

Modify the Treat wchar_t as Built-in Type property.

So the problem is that in Config.hpp

typedef unsigned short Uint16;

and with this /Zc:wchar_t option wchar_t is

typedef unsigned short wchar_t;

so they are equals

  • Any idea how to set that in qt creator? – Bugster Aug 25 '12 at 14:25
  • @ThePlan in my time, i had done it with a flag for g++. Searching now for it. – Seçkin Savaşçı Aug 25 '12 at 14:26
  • According to http://stackoverflow.com/questions/4521252/qt-msvc-and-zcwchar-t-i-want-to-blow-up-the-world it is a bug https://bugreports.qt-project.org/browse/QTBUG-6345 – Industrial-antidepressant Aug 25 '12 at 14:27
  • @ThePlan It looks like It's a bug for QT not using built-in wchar_t. What is your compiler and OS by the way, so we can give better solutions to you. – Seçkin Savaşçı Aug 25 '12 at 14:36
  • I am running the windows XP SP3 and using Mingw – Bugster Aug 25 '12 at 14:39
  • @ThePlan if you think you can do it, try my answer content, that is: change zc:wchar_t status and recompile qt from source. – Seçkin Savaşçı Aug 25 '12 at 17:36
  • @Seçkin Savaşçı, I tried but it seems rather complicated, and it lead to 50 different errors so I rolled it back, but I haven't had a chance to try out the other answers because of another question I posted which dazzled me. I never thought setting sfml for qt creator would be so hard :( – Bugster Aug 25 '12 at 19:34
  • @Back then, I faced this error on my ubuntu while using gcc. So I have no clue about your errors and possible solutions for them. I think we hit the wall hard here. Maybe another one can help you. – Seçkin Savaşçı Aug 25 '12 at 19:37