Sign in to follow this  
adamrwlngs

Xcode SDL C++ error

Recommended Posts

Okay, first off to give, anyone willing to help, an idea of what im doing: I currently am using Xcode 3.0 to learn SDL, OpenGl etc. to attempt to make some 2D side scrolling type games. I got SDL libs and installed them using these instructions. http://www.meandmark.com/sdlopenglpart2.html I did exactly as it says and it complies just fine when i create a new project. The main project file is a C file and I would prefer to use C++. So i do as the walkthrough suggests and delete the main.c and replace it with a main.cpp, but as soon as the new main.cpp is in place and i attempt to recompile I get this error which I dont understand: Building target “Test” of project “Test” with configuration “Debug” — (1 error) cd /Users/adamrawlings/Desktop/Test /Developer/usr/bin/g++-4.0 -o /Users/adamrawlings/Desktop/Test/build/Debug/Test.app/Contents/MacOS/Test -L/Users/adamrawlings/Desktop/Test/build/Debug -F/Users/adamrawlings/Desktop/Test/build/Debug -F/Users/adamrawlings/Library/Frameworks -F/Developer/SDKs/MacOSX10.4u.sdk/Library/Frameworks -filelist /Users/adamrawlings/Desktop/Test/build/Test.build/Debug/Test.build/Objects-normal/i386/Test.LinkFileList -framework SDL -framework Cocoa -framework OpenGL -arch i386 -mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk ld: duplicate symbol _main in /Users/adamrawlings/Desktop/Test/build/Test.build/Debug/Test.build/Objects-normal/i386/main.o and /Users/adamrawlings/Desktop/Test/build/Test.build/Debug/Test.build/Objects-normal/i386/SDLMain.o collect2: ld returned 1 exit status ld: duplicate symbol _main in /Users/adamrawlings/Desktop/Test/build/Test.build/Debug/Test.build/Objects-normal/i386/main.o and /Users/adamrawlings/Desktop/Test/build/Test.build/Debug/Test.build/Objects-normal/i386/SDLMain.o collect2: ld returned 1 exit status Build failed (1 error) If anyone could shed some light on this It would help bunches. Also if anyone suggests a different website, book, or anything that should make this process a little easier I'd appreciate that also.

Share this post


Link to post
Share on other sites
SDL on mac requires SDLmain.m and SDLmain.h to be part of the project. A default version of these are included in the standard package, and there is an addons package for mac that has a couple of other versions.

The basic process for creating a new SDL project is as follows:
1. create a new Cocoa application
2. move/rename main.m to main.cpp
3. link the SDL (and opengl if needed) frameworks to the project (right click on the frameworks folder, add existing framework, navigate to the thing, blah, blah...)
4. add SDLmain.m and SDLmain.h to the project, you can choose to copy them to the project directory as well, or not, your choice
5. edit main.cpp to something like:

#include <SDL/SDL.h>

int main(int argc,char** argv) {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Quit();
return 0;
}


That should compile. If it does it means that SDL is working properly and that you can continue. If you get any errors or warnings you might need to recheck something.


Edit: Just looked at your image. Looks like your main method doesn't have the right signature. SDL (at least on mac) requires main to be of the form "int main(int,char**)" I'm not actually sure why, but I know that it definitely won't compile unless main is correct.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this