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

Author Topic: SFML2, cmake and Windows 64 bits  (Read 9036 times)

0 Members and 1 Guest are viewing this topic.

Wiz

  • Newbie
  • *
  • Posts: 6
    • View Profile
SFML2, cmake and Windows 64 bits
« on: June 29, 2011, 03:45:06 pm »
Hi,

As a Linux user I thought it would be a good idea to make my apps Windows compatible, so I installed Microsoft Visual Studio 2008 Express.
Building sfml with cmake was easy following the tutorial (used nmake to compile), and sfml examples are working.

But when I get to a basic app compiled from a visual studio project generated by cmake, the sfml window title is make of a few garbage characters before my app name.
That was my first and last warning : when I tried to load an sf::Image from file I got a unhandled exception (Access violation reading location 0xcccccccc.), inside sf::Image::LoadFromFile.
Copy/pasting the sfml's opengl example gave me the exact same crash, as for using nmake rather than directly Visual Studio.

I don't understand what could cause the crash.
Could it be a x64/x86 problem ? (My windows 7 is x64, but visual studio express only compiles x86 so I'm pretty sure it didn't tried to combine x86 app with x64 dlls).
Or am I just using cmake wrong ? My app's CMakeLists.txt is just a basic cmake file, using this FindSFML.cake.

Contadotempo

  • Full Member
  • ***
  • Posts: 167
  • Firelink Shrine
    • View Profile
SFML2, cmake and Windows 64 bits
« Reply #1 on: June 29, 2011, 04:55:18 pm »
I had that problem when I compiled the "Debug" version instead of the "Release" version, and then used the wrong configuration on my projects.

Make sure you compile and use the correct configuration.
For example: If you compiled a non-debug version you must select "Release" on the project configurations on Visual Studio.

Wiz

  • Newbie
  • *
  • Posts: 6
    • View Profile
SFML2, cmake and Windows 64 bits
« Reply #2 on: June 29, 2011, 05:26:22 pm »
Indeed by selecting release mode my executables are working.

But I'll not have the courage to recompile sfml whenever I want to switch between release and debug.
I don't see why Visual Studio can't make calls to sfml release lib inside my debug app.
Isn't there a way to use both ?

Xander314

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
    • http://sfmlcoder.wordpress.com/
    • Email
SFML2, cmake and Windows 64 bits
« Reply #3 on: June 30, 2011, 10:49:10 am »
I'm not quite sure what you're asking, but:

1) You can change project settings independently for debug and release.
2) You can build both sets of binaries: debug and release
Therefore,
3) You can link to the debug binaries in debug configuration and the release binaries in release configuration (and swapping between them is as simple as using the dropdown box)

EDIT: Did you build debug and release binaries? You need to run CMake once for each one, changing the value of CMAKE_BUILD_TYPE (first time it is "Release" and then "Debug" - without the quotes).

Wiz

  • Newbie
  • *
  • Posts: 6
    • View Profile
SFML2, cmake and Windows 64 bits
« Reply #4 on: June 30, 2011, 11:24:26 am »
I understood that with Contadotempo's reponse.
It works and I can compile/run my code, but it still feel strange to need the debug version of sfml when I just want to debug my application, not sfml.

Xander314

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
    • http://sfmlcoder.wordpress.com/
    • Email
SFML2, cmake and Windows 64 bits
« Reply #5 on: June 30, 2011, 11:34:53 am »
Oh, I see. I'm not sure, but at a guess, it's because when your application is running, you can still get crashes inside the SFML binaries as well as in your own code.

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
SFML2, cmake and Windows 64 bits
« Reply #6 on: July 03, 2011, 10:36:16 am »
Why don't you just cross compile your project for Windows from Linux? I do that and I think it is a lot more comfortable. Just use mingw-w64. If you need details on that, just ask.

GatorQue

  • Newbie
  • *
  • Posts: 36
    • View Profile
SFML2, cmake and Windows 64 bits
« Reply #7 on: July 06, 2011, 04:34:51 pm »
Can you please post your cross compiling details?  Thanks.

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
SFML2, cmake and Windows 64 bits
« Reply #8 on: July 06, 2011, 04:36:31 pm »
Here, I keep it and all its deps here in AUR: http://aur.archlinux.org/packages.php?ID=48474

You can thus easily grab it with a single command from your AUR helper. Couldn't be more convenient.

Wiz

  • Newbie
  • *
  • Posts: 6
    • View Profile
SFML2, cmake and Windows 64 bits
« Reply #9 on: July 06, 2011, 05:40:54 pm »
I wanted to have my code compatible with visual studio for once, but cross compiling seems much cooler.
In the end I think I'll opt for that, thank you Svenstaro !

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
SFML2, cmake and Windows 64 bits
« Reply #10 on: January 22, 2012, 12:35:22 pm »
I just switched to Windows 7 64-bit and cannot build SFML anymore because of "undefined references". It cannot find any library, my guess is that's because all the libraries in "extlibs/libs-mingw" are for 32-bit only.

I am using mingw-w64 and created a MSYS makefile using CMake, this procedure just worked perfectly on 32-bit. However, now I wonder:
  • How can I build SFML for 64-bit without getting those undefined references? I dearly hope there is a way that does not include compiling the dependencies for 64-bit myself...
  • How can I tell CMake if I want to build for 32-bit? For what I know, all this requires is passing "-m32" to g++ (I tested that by compiling a simple application manually and it worked great, but how would I tell CMake?)
JSFML - The Java binding to SFML.

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
SFML2, cmake and Windows 64 bits
« Reply #11 on: January 22, 2012, 12:38:17 pm »
Use add_definitions(-m32) for your purpose. However, building it natively 64bit would be more proper. For that, you need all linked libs to be 64bit as well.

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
SFML2, cmake and Windows 64 bits
« Reply #12 on: January 22, 2012, 12:43:04 pm »
Thanks for that ultra-quick reply!

Quote from: "Svenstaro"
Use add_definitions(-m32) for your purpose.

Where? I'm not really versed configuring CMake, up until now I could just happily generate the buildfiles I needed without changing anything. :D

Quote from: "Svenstaro"
However, building it natively 64bit would be more proper. For that, you need all linked libs to be 64bit as well.

Well, I will need to be able to build both 32bit and 64bit anyway.
For the linked libs to be 64bit, I guess I will have to build those myself then.
JSFML - The Java binding to SFML.

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
SFML2, cmake and Windows 64 bits
« Reply #13 on: January 22, 2012, 12:45:27 pm »
Just add it anywhere in your CMakeLists.txt. You could also add it to your CFLAGS env var or use cmake -DCMAKE_CXX_FLAGS+="-m32" when running cmake.

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
SFML2, cmake and Windows 64 bits
« Reply #14 on: January 22, 2012, 01:06:59 pm »
Quote from: "Svenstaro"
Just add it anywhere in your CMakeLists.txt. You could also add it to your CFLAGS env var or use cmake -DCMAKE_CXX_FLAGS+="-m32" when running cmake.

Works fine when I add -m32 to the CXX_FLAGS and the LINKER_SHARED_FLAGS, thanks again! :)
JSFML - The Java binding to SFML.

 

anything