{"assets":[{"original":"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/MPH_Computer-550x368.gif","local":"\/data\/posts\/2013\/04\/840e86580d735959a35549f4c18ff90d.gif"},{"original":"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/LDOSX1-300x108.png","local":"\/data\/posts\/2013\/04\/426c36c260f39327978e0fb04a8e6060.png"},{"original":"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/LDOSX2-300x83.png","local":"\/data\/posts\/2013\/04\/63f7ec1e26e969ff50bdacfa4a799d4f.png"}],"author_link":"author\/sko\/","author_name":"Avant-Marde","cat":"LD #26","categories":["LD #26"],"comments":[],"epoch":1366805460,"event":"LD26","likes":9,"metadata":{"p_key":"80224","p_author":"Avant-Marde","p_authorkey":"0","p_urlkey":"289234","p_title":"Holy trinity of SFML 2.0 (how to set up)","p_cat":"LD #26","p_event":"LD26","p_time":"1366805460","p_likes":"9","p_comments":"0","p_status":"WAYBACK","us_key":null,"us_name":null,"us_username":null,"event_start":"1366934400","event_key":"16","event_name":"LD26"},"source_url":"2013\/04\/24\/holy-trinity-of-sfml-2-0-how-to-set-up\/","text":"<p><strong><span style=\"color: #ff6600\">Cheers!<\/span><\/strong> I have now successfully set up <strong>SFML 2.0<\/strong> (for <em>C++<\/em>) to compile for\u00a0<strong>OS X<\/strong>,\u00a0<strong>Linux<\/strong> and\u00a0<strong>Windows<\/strong>! This confirms my main framework for programming. Initially, though, I was as confused as a\u00a0<em><strong><span style=\"color: #808000\">pOtaToR<\/span><\/strong>.<\/em><\/p>\n<p style=\"text-align: center\"><a href=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/MPH_Computer.gif\"><img alt=\"POTATOR\" class=\"size-large wp-image-228196 aligncenter\" height=\"368\" src=\"\/data\/posts\/2013\/04\/840e86580d735959a35549f4c18ff90d.gif\" width=\"550\"\/><\/a><\/p>\n<p>Let me explain what I went through, and let me see if I can help you too, in case you are also having problems setting SFML 2.0 up in a cross-platform environment!<\/p>\n<p><span id=\"more-228084\"><\/span><\/p>\n<p>So, I have two laptops for this purpose. One is a <em>Mac<\/em> and, naturally, what I use to compile for <em>OS X<\/em>. I am using <strong>Xcode 4.6.2<\/strong>, to which I updated just two days ago or so. The other laptop is running, now good and old, <strong>Ubuntu 10.10 Maverick Meerkat<\/strong>. This is where dual cross-compiling magic happens; I natively compile the\u00a0<em>Linux<\/em>\u00a0executable here, of course, using <em>G++<\/em>, but also the\u00a0<em>Windows<\/em> version, using <em>MinGW<\/em>. My Linux IDE is\u00a0<strong>Code::Blocks<\/strong>. I will be working on the Mac, only moving on to this laptop when I need to compile for the other two systems. The Windows version also runs fine in\u00a0<strong>Wine<\/strong>.<strong><br\/>\n<\/strong><\/p>\n<p>I did have some trouble here and there when it came to setting it up for the various systems, and I thought I\u2019d briefly mention them in case anybody else wishes to work with a multi-platform SFML 2.0 setup and is running into problems similar to those that I have had.<\/p>\n<p>\u00a0<\/p>\n<h2>OS X<\/h2>\n<p>For OS X, I first downloaded the <a href=\"http:\/\/sfml-dev.org\/download.php#2.0-rc\" target=\"_blank\" title=\"SFML 2.0 OS X release candidate download page\">SFML 2.0 OS X release candidate<\/a>\u00a0and\u00a0tried setting up the frameworks and the Xcode templates. This all seemed unsuccessful, initially. I never got the templates properly working in the end either, but I didn\u2019t need them. I set up an empty project instead, and started setting it up.<\/p>\n<p>I never needed to manually set, in the project\u2019s\u00a0<em>build phases<\/em>, any frameworks to link with, because I decided to do it with <em>linker flags*<\/em> instead,\u00a0but if linking errors crop up, I would suggesting manually dragging the SFML frameworks here. The build phase settings are found by clicking the project name at the top of the Xcode window\u2019s left file hierarchy bar (shown by pressing <em>cmd+1<\/em> if it is not visible), and then the target with the same name. At the top of the main box will be a few tabs, and one of them is for the build phases.<\/p>\n<div class=\"wp-caption aligncenter\" id=\"attachment_228105\" style=\"width: 310px\"><a href=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/LDOSX1.png\"><img alt=\"Xcode build phases\" class=\"size-medium wp-image-228105\" height=\"108\" src=\"\/data\/posts\/2013\/04\/426c36c260f39327978e0fb04a8e6060.png\" width=\"300\"\/><\/a><p class=\"wp-caption-text\">Ignore the AngelScript target \u2013 it has nothing to do with SFML. I just happened to be testing AS in the same project.<\/p><\/div>\n<p>What I did have to do, however, were two things, located in the <em>build settings<\/em>. Those of the project, above the targets in the white middle column visible in the above picture, rather than those of any specific target. If your only target is the application itself, though, and you don\u2019t have a second one like my AS one here, it doesn\u2019t matter, though.<\/p>\n<ol>\n<li>*This asterisk refers back to those aforementioned\u00a0<strong>linker flags<\/strong>. Instead of adding the frameworks to the project\u2019s build settings, I added the following line to the\u00a0<em>other linker flags<\/em>:\n<pre>-framework sfml-system\u00a0-framework sfml-window\u00a0-framework sfml-graphics<\/pre>\n<p>If audio or networking or anything is needed, add those as well. The\u00a0<em>other linker flags\u00a0<\/em>are found as such:<\/p>\n<div class=\"wp-caption alignnone\" id=\"attachment_228115\" style=\"width: 310px\"><a href=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/LDOSX2.png\"><img alt=\"Setting linker flags in Xcode\" class=\"size-medium wp-image-228115\" height=\"83\" src=\"\/data\/posts\/2013\/04\/63f7ec1e26e969ff50bdacfa4a799d4f.png\" width=\"300\"\/><\/a><p class=\"wp-caption-text\">Setting linker flags in Xcode<\/p><\/div>\n<p>I also had to manually set the path to the global frameworks\u2019 folder, under the <em>framework search paths<\/em>, for some reason, which Google helped me find out. I set it to\u00a0<em>\/Library\/Frameworks<\/em> and I did it in the application\u2019s target, but the project\u2019s global build settings will work just fine too.<\/p>\n<p><div class=\"wp-caption alignnone\" id=\"attachment_228141\" style=\"width: 310px\"><a href=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/LDOSX4.png\"><img alt=\"Setting the frameworks' search path\" class=\"size-medium wp-image-228141\" height=\"67\" src=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/LDOSX4-300x67.png\" width=\"300\"\/><\/a><p class=\"wp-caption-text\">Setting the frameworks\u2019 search path<\/p><\/div><\/p><\/li>\n<li>Then I had to pick compilers\u00a0<em>without C++11 support<\/em>\u00a0because the RC of SFML has been compiled without such support and is incompatible with a program compiled with it, which would give errors.\n<p><div class=\"wp-caption alignnone\" id=\"attachment_228125\" style=\"width: 310px\"><a href=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/LDOSX3.png\"><img alt=\"Setting non-C++11 compiler\" class=\"size-medium wp-image-228125\" height=\"102\" src=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/LDOSX3-300x102.png\" width=\"300\"\/><\/a><p class=\"wp-caption-text\">Setting non-C++11 compiler<\/p><\/div><\/p><\/li>\n<\/ol>\n<p>That was it, and I had it working under\u00a0<strong>OS X<\/strong>!<\/p>\n<p>\u00a0<\/p>\n<h2>Linux<\/h2>\n<p>For Linux, I tried doing things in various ways until I eventually ended up compiling SFML myself using Make, following <a href=\"http:\/\/sfmlcoder.wordpress.com\/2011\/08\/16\/building-sfml-2-0-with-make-for-gcc\/\" target=\"_blank\" title=\"Building SFML 2.0 with Make (GCC\/Ubuntu)\">this wonderful tutorial for Ubuntu<\/a> written by a certain\u00a0<em>Xandier314<\/em> in 2011. This means that I did not download the release candidate for Linux, but the <a href=\"http:\/\/sfml-dev.org\/download.php\" target=\"_blank\" title=\"SFML download page\">latest development snapshot<\/a> found at the very top of the download page.<\/p>\n<p>As the article itself says, the tutorial focuses on Ubuntu specifically, but should be applicable to most Linux distributions with the exception of package management which might work differently in order to acquire the <em>prerequisities<\/em> needed to compile SFML. Surely any programming Linux user would already know how to do this on their specific system. If not, Google is your very best friend.<\/p>\n<p>Having followed this didn\u2019t end my problems right away, though. Compiling or linking still didn\u2019t work properly even after installing everything. The solution, however, was simple, even though it did require a little searching on my part.<\/p>\n<ul>\n<li><span style=\"line-height: 13px\"><span style=\"line-height: 13px\">You probably need to run the following command in your terminal after having installed the libraries:<\/span><\/span>\n<pre>sudo ldconfig<\/pre>\n<p>This did the trick for me.<\/p><\/li>\n<li>If it still does not work, you may have to set your LD (fitting name!) library path, also done through the terminal:\n<pre>export \"LD_LIBRARY_PATH=\/path\/to\/folder\/\"<\/pre>\n<p>The folder path is to where the libraries were installed. This was probably in <em>\/usr\/local\/lib<\/em>. To confirm that you have successfully changed the path, you can type the following command into the terminal:<\/p>\n<pre>echo $LD_LIBRARY_PATH<\/pre>\n<\/li>\n<\/ul>\n<p>If Code::Blocks still refuses to find your libraries or headers, you might have to set things up within the IDE as well.<\/p>\n<ol>\n<li><span style=\"line-height: 13px\"><span style=\"line-height: 13px\">You may need to right-click your project root in the file hierarchy in the program\u2019s left column and open up the\u00a0<em>build options<\/em>. Make sure to select the project\u00a0<em>root<\/em> in the left column of the window that pops up, and tab to\u00a0<em>search directories<\/em>. You might have to add a path for the\u00a0<em>compiler<\/em> and for the\u00a0<em>linker<\/em>, respectively. The compiler requires the path to the folder within which the\u00a0<em>SFML<\/em> folder containing the library\u2019s headers lies, and the linker wants the folder of the library files. In my case, these paths are\u00a0<em>\/usr\/local\/include<\/em>\u00a0for the compiler and\u00a0<em>\/usr\/local\/lib<\/em> for the linker.<br\/>\n<\/span><\/span>\n<p><div class=\"wp-caption alignnone\" id=\"attachment_228144\" style=\"width: 310px\"><a href=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/LDLinux1.png\"><img alt=\"Setting search directories in Code::Blocks\" class=\"size-medium wp-image-228144\" height=\"235\" src=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/LDLinux1-300x235.png\" width=\"300\"\/><\/a><p class=\"wp-caption-text\">Setting search directories in Code::Blocks<\/p><\/div><\/p><\/li>\n<li>I then jumped down to the\u00a0<em>debug<\/em> target specifically, and chose the tab for the\u00a0<em>linker settings<\/em>, so that the debug and release targets could be assigned different versions of the libraries. I clicked the\u00a0<em>add<\/em> button and browsed to find my <em>shared object files<\/em>\u00a0in the folder that I had assigned as the linker search directory, and chose to add the three libraries corresponding to the frameworks that I had added in OS X. I made sure to give the debug target the ones with the\u00a0<em>-d<\/em> suffixes. Then I went on to the\u00a0<em>release<\/em> target and did the same thing, adding the\u00a0<em>.so<\/em> files with the same names, but without the <em>-d<\/em> suffix.\n<p><div class=\"wp-caption alignnone\" id=\"attachment_228151\" style=\"width: 310px\"><a href=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/LDLinux2.png\"><img alt=\"Adding libraries to link in Code::Blocks\" class=\"size-medium wp-image-228151\" height=\"195\" src=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/LDLinux2-300x195.png\" width=\"300\"\/><\/a><p class=\"wp-caption-text\">Adding libraries to link in Code::Blocks<\/p><\/div><\/p><\/li>\n<\/ol>\n<p>That was it! \u00a0I was now able to compile and run my application both in debug and release mode for\u00a0<strong>Linux<\/strong>.<\/p>\n<p>\u00a0<\/p>\n<h2>Windows<\/h2>\n<p>This title is, of course, slightly deceiving; I did not actually use Windows to compile the Windows version, and I\u2019m sure it would pretty easy to set up there by following the instructions on the website either way \u2013 or perhaps not, seeing how the tutorials for OS X and Linux proved to result in problems to which I had to find solutions elsewhere. Either way, I do not possess any computer running Windows, and this section is about getting SFML 2.0 up and running for cross-compilation using Code::Blocks in Linux. The very same Ubuntu previously used, specifically.<\/p>\n<p><em>Getting this to work assumes that you have already got the <strong>MinGW Windows cross-compiler<\/strong> for Linux up and running. I will not go through the steps of installing it. <a href=\"http:\/\/www.mingw.org\/wiki\/LinuxCrossMinGW\" target=\"_blank\" title=\"MinGW cross compiler for Linux\">You can find the downloads and information needed here<\/a>. I will tell you, however, that in order to set up the search paths to set the MinGW compiler for use by Code::Blocks later, you will need to go from the program\u2019s top menu\u00a0<strong>Settings &gt; Compiler and debugger<\/strong> and then move on to the tab\u00a0<strong>Search directories<\/strong> and add the path to the\u00a0<strong>bin<\/strong> subfolder of your MinGW folder.<\/em><\/p>\n<div class=\"wp-caption aligncenter\" id=\"attachment_228171\" style=\"width: 310px\"><a href=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/LDWindows0.png\"><img alt=\"Setting compiler search directories in Code::Blocks\" class=\"size-medium wp-image-228171\" height=\"265\" src=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/LDWindows0-300x265.png\" width=\"300\"\/><\/a><p class=\"wp-caption-text\">Setting compiler search directories in Code::Blocks<\/p><\/div>\n<p>Getting it to work in Windows after having gotten it to work in Linux was surprisingly quick and without pain, actually. I made a copy of my Linux project and started making a couple of changes to it.<\/p>\n<ol>\n<li>First of all, though, I obviously had to acquire the Windows version of the SDK. In this case too, just like for Mac, I simply got the <a href=\"http:\/\/sfml-dev.org\/download.php#2.0-rc\" target=\"_blank\" title=\"SFML 2.0 Windows release candidate\">release candidate<\/a> of SFML 2.0. Specifically, the one with <i>Code::Blocks<\/i> written in parentheses after the name.<\/li>\n<li><span style=\"line-height: 13px\"><span style=\"line-height: 13px\">Having downloaded this, I opened up the project\u2019s\u00a0<em>build options<\/em> again. I began by making sure to go into the <em>root<\/em> and not a specific target, and\u00a0went into the\u00a0<em>search directories<\/em> once again. I removed the paths that I had assigned to the Linux project before, and replaced them by clicking the\u00a0<em>add<\/em> button and simply browsing to the\u00a0<em>include<\/em> and\u00a0<em>lib<\/em> subfolders of the downloaded RC folder, for the\u00a0<em>compiler<\/em> and\u00a0<em>linker<\/em>\u00a0search directories, respectively. You could install them in a more standard location if you wish.<br\/>\n<\/span><\/span>\n<p><div class=\"wp-caption alignnone\" id=\"attachment_228169\" style=\"width: 310px\"><a href=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/LDWindows1.png\"><img alt=\"Setting search directories for MinGW in Code::Blocks\" class=\"size-medium wp-image-228169\" height=\"235\" src=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/LDWindows1-300x235.png\" width=\"300\"\/><\/a><p class=\"wp-caption-text\">Setting search directories for MinGW in Code::Blocks<\/p><\/div><\/p><\/li>\n<li>Then move on to the two specific targets\u2019\u00a0<em>linker settings<\/em> like before, and\u00a0<em>clear<\/em> the lists using the designated button. Time to fill them up with Windows libraries instead. Look them up in the <i>\/lib\/<\/i>\u00a0subfolder of your downloaded SFML 2.0 RC for Windows. We want the\u00a0<em>.a<\/em> files this time. There are <em>-d<\/em> suffixed files for Windows too<span style=\"color: #808080\"><del>, though the debug target doesn\u2019t properly compile for me, but that\u2019s OK \u2013 I\u2019ll just compile a final release copy for Windows in the end either way<\/del><span style=\"color: #000000\"> [<strong>EDIT<\/strong>: the problem was that I, for some reason, had picked static libraries (suffixed\u00a0<em>-s<\/em>) for debug but not release \u2013 switching to dynamic (no suffix; <em>-d<\/em> means\u00a0<em>debug<\/em>, not\u00a0<em>dynamic<\/em>) solved this issue \u2013 however, I do have memories of cross-compiled, dynamically linked Windows applications not running for a lot of native Windows users back when I used SFML 1.6, so you might want to confirm the functionality of your application \u2013 I shall personally go and ask some people who had problems running those applications to see whether they can run dynamically linked 2.0 applications]<\/span><\/span>. The\u00a0<em>release<\/em> target obviously uses the unsuffixed files. Now, remember that for Windows, SFML requires one more library to be linked to, in addition to whatever other ones you use. This one is called\u00a0<em>libsfml-main<\/em>.\n<div class=\"wp-caption alignnone\" id=\"attachment_228178\" style=\"width: 310px\"><a href=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/LDWindows2.png\"><img alt=\"Setting libraries to link to for MinGW in Code::Blocks\" class=\"size-medium wp-image-228178\" height=\"235\" src=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/LDWindows2-300x235.png\" width=\"300\"\/><\/a><p class=\"wp-caption-text\">Setting libraries to link to for MinGW in Code::Blocks<\/p><\/div>\n<p>[<strong>EDIT<\/strong>: So you\u2019re\u00a0<em>not<\/em> supposed to use the\u00a0<em>-s<\/em> suffixed libraries as shown in the image above;\u00a0<em>libsfml-system(-d).a<\/em>, not\u00a0<em>libsfml-system-s(-d).a<\/em>]<\/p><\/li>\n<li>For a final Code::Blocks setting, you now need to go back into\u00a0<strong>Settings &gt; Compiler<\/strong> and visit the tab one step after the one we previously visited. This one is called\u00a0<strong>Toolchain executables<\/strong>. Here you will need to replace the first four or five\u00a0<em>program files<\/em>\u00a0by assigning a prefix to them to denote the file names of the <em>MinGW executables<\/em> located in the <em>MinGW \/bin\/ subfolder<\/em> that you wish to use. I choose to use the\u00a0<em>i586-mingw32<\/em> one, and so I prefix this, followed by a hyphen, to the already existing filenames, namely\u00a0<em>gcc<\/em>,\u00a0<em>g++<\/em>,\u00a0<em>g++<\/em> again, and\u00a0<em>ar<\/em> and possibly also <i>gdb<\/i>. Assuming your regular Linux compiler is GCC, of course. Remember that you will need to remove these prefixes again when you want to compile for Linux. If anybody knows how to set this up on a target basis rather than a global one, I would be greatly thankful to learn how to do this.\n<p><div class=\"wp-caption alignnone\" id=\"attachment_228188\" style=\"width: 310px\"><a href=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/LDWindows4.png\"><img alt=\"Changing Code::Blocks toolchain executables\" class=\"size-medium wp-image-228188\" height=\"265\" src=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/LDWindows4-300x265.png\" width=\"300\"\/><\/a><p class=\"wp-caption-text\">Changing Code::Blocks toolchain executables<\/p><\/div><\/p><\/li>\n<li>Finally, in order to be able to properly run your application, you need to copy some DLL files from the\u00a0<em>\/bin\/<\/em> subfolder of your SFML 2.0 RC folder for Windows into the same folder as your Code::Blocks project. In addition to the ones corresponding to the names of the sublibraries of SFML to which you have linked, you need <em>openal32.dll in case you\u2019re using sfml-graphics<\/em>, and in case you\u2019re using\u00a0<em>sfml-audio<\/em>, also\u00a0<em>libsndfile-1.dll<\/em>.<\/li>\n<\/ol>\n<p>You should now be ready to compile and see the project properly running for Windows as well, through Wine! Remember that for me, only the\u00a0<em>release<\/em> target <span style=\"color: #808080\"><del>will<\/del><\/span>would (before I solved it; see above)\u00a0work, so in case you get any errors when trying to compile or link the\u00a0<em>debug<\/em> target, make sure to try out the release target before you deem your endeavours a failure. Also remember that you will need to clean the project first if you did like me and copied the Linux project and compiled that one earlier, as there will be incompatible leftover object files from there.<\/p>\n<p>I hope this was helpful to somebody! If not, I\u2019ll at least have these notes for myself in the future!<\/p>\n<p><a href=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/Potato.jpg\"><img alt=\"Potato\" class=\"aligncenter size-full wp-image-225792\" height=\"288\" src=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2013\/04\/Potato.jpg\" width=\"329\"\/><\/a><\/p>\n<p>Tags: <a href=\"http:\/\/ludumdare.com\/compo\/tag\/potator\/\" rel=\"tag\">potator<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/tutorial-sfml-2-0-mac-osx-os-x-linux-windows-ubuntu-mingw-g-gcc-cross-compile-help\/\" rel=\"tag\">tutorial sfml 2.0 mac osx os x linux windows ubuntu mingw g++ gcc cross-compile help<\/a><\/p>","time":"April 24th, 2013 12:11 pm","title":"Holy trinity of SFML 2.0 (how to set up)","title_was_empty":false}