1

I thought Ubuntu and OS X would have similar interfaces for compiling a C/C++ program with SDL but nothing I am trying, or finding on Google seems to be working.

I have found a solution for Xcode, but I am not using Xcode. I am writing my programs from Sublime Text 2 and compiling via command-line since I prefer it and work much faster that way.

Long story short, I am receiving an array of errors with each attempt and thus far I have copied SDL.framework into my /Library/Frameworks directory.

This is the closest I have gotten to actually compiling:

[ 674 / 174 / 0 ] $ compcpsdl

Undefined symbols for architecture x86_64:
  "_SDL_main", referenced from:
      -[SDLMain applicationDidFinishLaunching:] in ccYYA0Ea.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

Terminal command (i.e. compcpsdl)

g++ -I/Library/Frameworks/SDL.framework/Headers main.cpp SDLmain.m -framework SDL -framework Cocoa

With the following project structure:

Project-Directory/
--- main.cpp
--- SDLMain.m
--- SDLMain.h

And lastly, the following source code:

#include <iostream>
#include <SDL/SDL.h>

using namespace std;

int main ()
{
  cout << "Hello World!";
  return 0;
}

It appears I'm doing everything correctly, yet nothing seems to be working.

Any ideas guys?

tsujp
  • 1,066
  • 1
  • 12
  • 29
  • 1
    [Note sure if this is relevant?](http://stackoverflow.com/a/8221508/1171191) It would match your linking error. – BoBTFish May 30 '13 at 08:25
  • @BoBTFish many thanks. It didn't solve my question but one of the other answers satisfied a secondary query I had. – tsujp May 30 '13 at 08:33

1 Answers1

3

I Think SDL does sometimes a bit strange stuff with the main function it assumes the mainfunction is defined in one way. Notice that I added int argc and char** argv to the definition of you main function.

Try:

int main (int argc, char** argv)
{
  cout << "Hello World!";
  return 0;
}

I encountered this problem also once and it was quite mystifying. for more info see this stackoverflow question: Why SDL defines main macro?

Community
  • 1
  • 1
hetepeperfan
  • 4,292
  • 1
  • 29
  • 47
  • Oh wow. It just compiled successfully then. It appears that SDLmain.m is required for Cocoa and not native C++ (which is what I want). Removing SDLmain.m and -framework Cocoa from the compile command results in another error, if I leave them in it compiles, however. – tsujp May 30 '13 at 08:30
  • Ignore my above comment, I realise SDLmain.m etc... is required for the program to quote: "SDL application can be a well-behaving OS X application." Thanks @BoBTFish – tsujp May 30 '13 at 08:32