SFML community forums

Help => General => Topic started by: Jeffrey on July 22, 2012, 04:44:27 am

Title: Mac OS X 10.6.8 SFML 2.0
Post by: Jeffrey on July 22, 2012, 04:44:27 am
I read the installation tutorial about SFML 2.0 and it says that you need XCode preferably the fourth version. I was wondering what does that exactly means. Can I use the installer also for the latest version of XCode 3? I can't install the 4 because I don't want to upgrade to Lion (actually I just downgraded back to Snow Leopard).

Also is there any other way to use SFML without XCode? Maybe with Code Blocks for Mac?

Thanks.
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Hiura on July 22, 2012, 09:35:44 am
You are absolutely free to use any IDE or command line tool you want, of course. You just need to know how to link against a library (not specifically SFML since it's always the same operation) with the tool you chose to use.

Now, if you don't have Xcode 4 you can't benefit from the project templates. But that's it.
Quote from: tutorial
Be aware that these templates are not compatible with Xcode 3. If you are still using this version of the IDE and you are not considering updating your tool then you can still, of course, create SFML-based applications, however, we will not discuss here how you can do that. Please refer to Apple's documentation about Xcode 3 and how to add a library to your project.
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Jeffrey on July 22, 2012, 04:23:09 pm
Thanks for your answer. Let's say Iìd like to do this from the Terminal. How can I link all the files of the library? Thanks.
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Hiura on July 22, 2012, 04:33:38 pm
If you only want a classic binary (i.e., you don't want an application bundle) then you can do pretty much like on any Unix :
g++ main.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system
if you use dylibs or
g++ main.o -o sfml-app -framework sfml-graphics -framework sfml-window -framework sfml-system
if you use frameworks.
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Jeffrey on July 22, 2012, 04:54:30 pm
Sorry, could you please explain me step by step how to be able to compile like that? Do I have to download the source code? Do I have to install something? Where do I put my main.cpp file? What folder is that command referred to?
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Hiura on July 22, 2012, 07:11:03 pm

Ok, so you should read Introduction and Installing SFML ... from Tutorial - Getting started - SFML and Xcode (Mac OS X) (http://www.sfml-dev.org/tutorials/2.0/start-osx.php), then read Compiling a SFML program from Tutorial - Getting started - SFML and Linux (http://www.sfml-dev.org/tutorials/2.0/start-linux.php) to get an idea of how compilation work.

Now, it's very important to know what are a compiler and a linker. Wikipedia should give you a start : http://en.wikipedia.org/wiki/Compiler (http://en.wikipedia.org/wiki/Compiler) and http://en.wikipedia.org/wiki/Linker_(computing) (http://en.wikipedia.org/wiki/Linker_(computing)). (Don't go too deep in the details, you only to know how they work together.)

Except the link step, it is the same as compiling a program that doesn't require any external library.
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Jeffrey on July 22, 2012, 08:27:51 pm
Thanks, I followed the tutorial which basically brought me to follow the Code::Block IDE tutorial. I followed the steps. I added the include folder in the compiler and the lib folder in the linker. I linked in the linker settings:

Quote
-lsfml-system

But now when I try to run the test source code I get:

Quote
-------------- Build: Debug in Test ---------------

Linking console executable: bin/Debug/Test
ld: library not found for -lsfml-system
collect2: ld returned 1 exit status

What have I missed?
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Hiura on July 22, 2012, 08:32:27 pm
You're mixing header files and binary versions somehow. Probably because you have more than one version installed on your computer.

(With SFML 2.0, functions start with a lower case letter. You can use this property to identify the old headers from the new one easily.)
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Jeffrey on July 22, 2012, 08:34:44 pm
I tried installing SFML 1.6 and I've edited my previous post, please, take a look. The previous error was because I didn't set the linker settings.
Thanks.

PS: I'm following this: http://www.sfml-dev.org/tutorials/1.6/start-cb.php
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Hiura on July 22, 2012, 08:36:56 pm
I'm lost, now you're using 1.6 or 2.0 ?
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Jeffrey on July 22, 2012, 08:37:30 pm
I've decided to use SFML 1.6.
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Hiura on July 22, 2012, 08:43:04 pm
I can only recommend you to use 2.0 (1.6 is way more buggy that 2.0 for one thing, and also slower, and not maintained since a long time now). But it's your call.

Anyway, if you're using 1.6 you can use Xcode 3 as described in the dedicated tutorial (http://www.sfml-dev.org/tutorials/1.6/start-osx.php) since you don't use the terminal anymore. Also the error you get let me thing something was not installed correctly. The tutorial should help you with that.
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Jeffrey on July 22, 2012, 08:49:34 pm
Ok, now it's getting confusing. I decided to use 1.6 because I thought 2.0 was still in some kind of beta version and was still buggy. But if you tell me the opposite I guess I should go back on deciding for 2.0 again.

I'm sorry for the confusion. So I'll try to follow this tutorial for CodeBlocks on Windows for SFML 2.0: http://www.sfml-dev.org/tutorials/2.0/start-cb.php
Is there anything that I should change in that tutorial to make it work on my Mac too? (Considering that I'm using Mac OS X)
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Hiura on July 22, 2012, 09:00:06 pm
Ok, now it's getting confusing. I decided to use 1.6 because I thought 2.0 was still in some kind of beta version and was still buggy.
Yes, this is a little paradoxal : SFML 2.0 RC is not the "stable" version yet but is already less buggy than 1.6, it's the release candidate which means nothing will change in the API until the 2.0 stable version.

Is there anything that I should change in that tutorial to make it work on my Mac too? (Considering that I'm using Mac OS X)
So you have to do one thing before following this tutorial : install SFML for Mac with the installer. Then you have to use /usr/local/include and /usr/local/lib for the search directories. Also you can't use the static version as it doesn't exist on Mac. That's should do the trick.

Let me know if you still have some issues.
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Jeffrey on July 22, 2012, 10:43:02 pm
Now I get:


Quote
-------------- Build: Debug in Test ---------------

Compiling: main.cpp
/Users/Jeffrey/Desktop/TestProject/Test/main.cpp: In function 'int main()':
/Users/Jeffrey/Desktop/TestProject/Test/main.cpp:6: error: 'Text' is not a member of 'sf'
/Users/Jeffrey/Desktop/TestProject/Test/main.cpp:6: error: expected `;' before 'text'
/Users/Jeffrey/Desktop/TestProject/Test/main.cpp:8: error: 'class sf::RenderWindow' has no member named 'isOpen'
/Users/Jeffrey/Desktop/TestProject/Test/main.cpp:11: error: 'class sf::RenderWindow' has no member named 'pollEvent'
/Users/Jeffrey/Desktop/TestProject/Test/main.cpp:13: error: 'class sf::Event' has no member named 'type'
/Users/Jeffrey/Desktop/TestProject/Test/main.cpp:14: error: 'class sf::RenderWindow' has no member named 'close'
/Users/Jeffrey/Desktop/TestProject/Test/main.cpp:17: error: 'class sf::RenderWindow' has no member named 'clear'
/Users/Jeffrey/Desktop/TestProject/Test/main.cpp:18: error: 'class sf::RenderWindow' has no member named 'draw'
/Users/Jeffrey/Desktop/TestProject/Test/main.cpp:18: error: 'text' was not declared in this scope
/Users/Jeffrey/Desktop/TestProject/Test/main.cpp:19: error: 'class sf::RenderWindow' has no member named 'display'

I've installed by the 2.0 installer for mac, linked those folders you said (copied and pasted it) in Code::blocks, under build options > Linker settings I've added sfml-graphics, sfml-window, sfml-system and tried to run the sample code.

:(
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Jeffrey on July 22, 2012, 11:36:46 pm
Code Blocks seems to get crashy by itself. It can't quit, it always force me to force quit. It doesn't save projects settings and linker settings, and can't save files. Sometimes even the main.cpp file generated disappear or gets deleted and when you are ready to save it says "main.cpp file does not longer exists".
I re downloaded and re installed Code Blocks but nothing changed.

I'm really sorry, I know I'm changing things too often, but I don't feel to be too stable with that IDE, so I'd like to move to Netbeans. I tried it and it seems to work fine with normal setting. It also has makefile which may simplify things. Could you please tell me how to set SFML up (2.0 if possible) on that? Considering that I've already run the installer for 2.0?

Also please note that after the installation of 2.0 in /Developer/usr/local/ there's just one folder: bin/; there's no include/ nor lib/.
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Hiura on July 23, 2012, 10:56:26 am
Now I get:


Quote
-------------- Build: Debug in Test ---------------

Compiling: main.cpp
/Users/Jeffrey/Desktop/TestProject/Test/main.cpp: In function 'int main()':
/Users/Jeffrey/Desktop/TestProject/Test/main.cpp:6: error: 'Text' is not a member of 'sf'
/Users/Jeffrey/Desktop/TestProject/Test/main.cpp:6: error: expected `;' before 'text'
/Users/Jeffrey/Desktop/TestProject/Test/main.cpp:8: error: 'class sf::RenderWindow' has no member named 'isOpen'
/Users/Jeffrey/Desktop/TestProject/Test/main.cpp:11: error: 'class sf::RenderWindow' has no member named 'pollEvent'
/Users/Jeffrey/Desktop/TestProject/Test/main.cpp:13: error: 'class sf::Event' has no member named 'type'
/Users/Jeffrey/Desktop/TestProject/Test/main.cpp:14: error: 'class sf::RenderWindow' has no member named 'close'
/Users/Jeffrey/Desktop/TestProject/Test/main.cpp:17: error: 'class sf::RenderWindow' has no member named 'clear'
/Users/Jeffrey/Desktop/TestProject/Test/main.cpp:18: error: 'class sf::RenderWindow' has no member named 'draw'
/Users/Jeffrey/Desktop/TestProject/Test/main.cpp:18: error: 'text' was not declared in this scope
/Users/Jeffrey/Desktop/TestProject/Test/main.cpp:19: error: 'class sf::RenderWindow' has no member named 'display'
Just an idea, not sure about it, but did you uninstall SFML 1.6 before installing 2.0 RC ? Maybe the installer didn't override the old headers. Can you confirme this by showing me what prints the following command in a Terminal ?
perl -ne 'BEGIN { $found = 0; print "\n\n\n"; } END { if ($found == 0) { print "SFML 1.x\n\n\n"; } else { print "SFML 2.x\n\n\n"; } } $found = 1 if m/#define SFML_VERSION_MAJOR 2/' /usr/local/include/SFML/Config.hpp

If it prints "SFML 1.x" then run the following command before reinstalling SFML 2.0 RC with the installer :
rm -r /usr/local/include/SFML
(Note : if it fails because of access right, juste type sudo !! right after the last command and enter your password as prompted.)

Now your project should compile fine, at least in C::B.

I'd like to move to Netbeans. I tried it and it seems to work fine with normal setting. It also has makefile which may simplify things. Could you please tell me how to set SFML up (2.0 if possible) on that?
Well, I don't know how NetBeans works with C++ (I only used it some years ago for Java development) but I guess it's pretty much the same as any IDE : you need to find three thing :
like you did in C::B.

You will probably find that on the web.

Now if you use Makefiles, you need to know how they work. I didn't read this tutorial (http://mrbook.org/tutorials/make/) but it should help you, I guess. You can also have a look at the documentation (http://www.gnu.org/software/make/manual/make.html).

Also please note that after the installation of 2.0 in /Developer/usr/local/ there's just one folder: bin/; there's no include/ nor lib/.
Why did you install SFML in /Developer ? (This folder is removed with future version of Xcode, you probably should not use it anymore. Use instead /usr/local as explained in the tutorial.)
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Jeffrey on July 23, 2012, 06:40:03 pm
For the Developer thing: just forget what I said, no problem. I misunderstood what you where saying.
In Netbeans I found the project settings and added "/usr/local/include" under Compiler > Include directories.
Now under Linker there are:

- Additional library directories (path)
- Libraries (I don't know what this is but there are sever buttons, some of which are: Add project, add library, add standard library, add library file, add options)
- Compilation line > Additional options

What would you do here?
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Jeffrey on July 23, 2012, 06:47:54 pm
I could make it work. Thanks for you help.
For netbeans the steps are the following:

0. Run the Mac OS X 2.0 installer
1. Create a new project
2. Click Run>Set project configuration>Customize
3. Under Build>C++ Compiler and set Include directories to /usr/local/include
4. Under Build>Linker and set Additional library directories to /usr/local/lib
5. Under Build>Linker set Additional options to -lsfml-graphics -lsfml-window -lsfml-system

Now you are able to make the tutorial sample work.
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Hiura on July 23, 2012, 07:40:44 pm
Great!

Just an idea, not sure about it, but did you uninstall SFML 1.6 before installing 2.0 RC ? Maybe the installer didn't override the old headers. Can you confirme this by showing me what prints the following command in a Terminal ?
perl -ne 'BEGIN { $found = 0; print "\n\n\n"; } END { if ($found == 0) { print "SFML 1.x\n\n\n"; } else { print "SFML 2.x\n\n\n"; } } $found = 1 if m/#define SFML_VERSION_MAJOR 2/' /usr/local/include/SFML/Config.hpp
Did you run the command ?
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Jeffrey on July 23, 2012, 07:41:42 pm
It printed:


SFML 2.x
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Hiura on July 23, 2012, 07:42:58 pm
Ok, that's strange.

Anyway, you got it working so it's cool.
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Jeffrey on July 23, 2012, 08:29:32 pm
What should it have printed?
Title: Re: Mac OS X 10.6.8 SFML 2.0
Post by: Hiura on July 23, 2012, 10:44:33 pm
SFML 1.x if my deductions were corrects. The error you got (/Users/Jeffrey/Desktop/TestProject/Test/main.cpp:6: error: 'Text' is not a member of 'sf') led me thing you had still 1.6 installed somehow.

Anyway, it's working so...  ;)