Advertisement Jump to content
Sign in to follow this  

Xcode SDL C++ error

This topic is 3822 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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. 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/ -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/ -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/ and /Users/adamrawlings/Desktop/Test/build/ collect2: ld returned 1 exit status ld: duplicate symbol _main in /Users/adamrawlings/Desktop/Test/build/ and /Users/adamrawlings/Desktop/Test/build/ 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
Yes, or at least I believe I do.

Here is a screenshot of what I have at the moment:

Thanks again.

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) {
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
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!