Friday, March 30, 2012

Simple Fast Multimedia Library - setup with Code::Blocks

I love this library.  Compiling and running the basic program was a bit tricky; I had a bunch of "libgcc_s_dw2-1.dll is missing" errors.  What I ended up doing to solve these errors was:
  • First, download the compiler "mingw-with-gcc-4.4.zip" discussed on the webpage http://www.sfml-dev.org/tutorials/1.6/start-cb.php; unzip it into an easy-to-find directory such as C:\MinGW
  • Next, install the Code::Blocks IDE from http://www.codeblocks.org/downloads/26 -- but choose the one that does not include MinGW. When installing, if Code::Blocks doesn't automatically find the MinGW directory you set up earlier, you can configure the compiler afterwards as follows: 
    • In the menu bar, go to "Settings", select "Compiler and Debugger..."
    • In the new window make sure the "Global Compiler Settings" image on the left is highlighted/selected
    • In the "Selected Compiler" dropdown list choose "GNU GCC Compiler"
    • In the tabs underneath the dropdown list, click on "Toolchain Executables". 
    • There will be a textbox where you can type the name of the directory where you unzipped the MinGW compiler
  • In the window described above
    ("Settings -> "Compiler and Debugger..." -> "Global Compiler Settings"), click the "Linker Settings" tab, and in the textbox labelled "Other Linker Options", enter the following five lines of text:
            -static-libgcc
            -static-libstdc++
            -lsfml-graphics
            -lsfml-window
            -lsfml-system
Hope this helps somebody out there (perhaps even my future self?).

Thursday, March 29, 2012

(re)learning C++

I haven't really used C++ since my undergraduate days -- I've mostly worked in Java recently.  Feeling nostalgic, I decided to refresh these particular skills.  I'll be using the freely available C++ IDE called Code::Blocks (available at http://www.codeblocks.org/) and the tutorials at http://www.cplusplus.com/doc/tutorial/introduction/ (where Code::Blocks appears to be recommended above Dev-C++).  Running the "Hello World" program was easy, but to stop the exiting immediately, I recommend adding an int "dummy" variable and a "cin" to the standard code, e.g.,

// my first program in C++

#include <iostream>
using namespace std;

int main ()
{
  int pauseVariable;
  cout << "Hello World!" << endl;
  cout << "Type something and press Enter to continue..." << endl;
  cin >> pauseVariable;
  return 0;
}
P.S. Figured out syntax highlighting thanks to http://mlawire.blogspot.com/2009/07/blogger-syntax-highlighting.html except that (at the time of posting) "Edit HTML" is located under the Template menu in your Blogger dashboard.
P.P.S. Code::Blocks integrates nicely with the Simple and Fast Multimedia Library - http://www.sfml-dev.org/