views:

538

answers:

2

Hey all,

I have been trying to build the logstalgia project (http://code.google.com/p/logstalgia/) on my Mac (10.5). Rather than having to link it to the system libraries correctly, I have built and added all of the dependencies to the project. I am new at this, but I do think I have done this correctly, mostly because I have had two of my friends who are much more experienced say so.

Adding the frameworks removed all of the compile errors, but I still get a linker error. It seems to not be able to find the main() function. I have verified I included main.cpp in the sources to be compiled (using XCode) and that there are no accidental double declarations. I have also verified that the main function is correctly declared (no missing brackets, etc).

It is as though XCode does not link in the correct order. Any help would be really appreciated, I am really excited to be down to a single error! (Hope fixing this does not open a floodgate).

Thanks, Hamilton

PS - I can definitely provide a zip of the Xcode project if anyone is willing to look!

Checking Dependencies

Ld "/Users/hamiltont/Downloads/logstalgia-0.9.2 2/Untitled/build/Debug/Untitled" normal i386
    cd "/Users/hamiltont/Downloads/logstalgia-0.9.2 2/Untitled"
    setenv MACOSX_DEPLOYMENT_TARGET 10.5
    /developer/usr/bin/g++-4.0 -arch i386 -isysroot /developer/SDKs/MacOSX10.5.sdk "-L/Users/hamiltont/Downloads/logstalgia-0.9.2 2/Untitled/build/Debug" -L/sw/lib "-L/Users/hamiltont/Downloads/logstalgia-0.9.2 2/Untitled/../../pcre-7.9/.libs" -L/opt/local/lib -L/sw/lib "-F/Users/hamiltont/Downloads/logstalgia-0.9.2 2/Untitled/build/Debug" -F/Users/hamiltont/Downloads/logstalgia-0.9.2 -F2/src/SDL.framework "-F/Users/hamiltont/Downloads/logstalgia-0.9.2 2/Untitled" -filelist "/Users/hamiltont/Downloads/logstalgia-0.9.2 2/Untitled/build/Untitled.build/Debug/Untitled.build/Objects-normal/i386/Untitled.LinkFileList" -mmacosx-version-min=10.5 -framework OpenGL -lpcre -lSDL -lSDL_image-1.2.0 -prebind -o "/Users/hamiltont/Downloads/logstalgia-0.9.2 2/Untitled/build/Debug/Untitled"
Undefined symbols:
  "_main", referenced from:
      start in crt1.10.5.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
A: 

Double-check the link file list to make sure main.cpp's object file is present there:

/Users/hamiltont/Downloads/logstalgia-0.9.2 2/Untitled/build/Untitled.build/Debug/Untitled.build/Objects-normal/i386/Untitled.LinkFileList

You might also want to preprocess the main.cpp to make sure main isn't getting inadvertently renamed (via a rogue macro) or omitted (via a rogue #if).

fbrereto
fbrereto, Thanks for the quick reply. I checked the LinkFileList, and main.o was the first entry. Also, I verified that the main file was not getting omitted by a macro (luckily, it is not defined within any macros). I am not sure how to check if it is being renamed. There is a main.o present in the build folder, which seems to indicate it is not, but I could be wrong here
Hamy
I was suggesting those checks for the main routine, not the main.cpp file- sorry for the confusion there. You can preprocess a file by right-clicking on it in XCode and choosing the option from the context menu. Once the output pops up you'll want to scroll to the very bottom of the file- it'll be big! Make sure main looks as it should, that it a) exists and b) is called what you'd expect.
fbrereto
fbrereto, I think you are correct about the rogue macro! I worked on this some more - a nm main.o | grep main only shows _SDL_mainI went into the SDL framework headers, and in SDLmain.h, I see this: /* The application's main() function must be called with C linkage, and should be declared like this:#ifdef __cplusplusextern "C"#endif int main(int argc, char *argv[]) { } */#define main SDL_main/* The prototype for the application's main() function */extern C_LINKAGE int SDL_main(int argc, char *argv[]);Any idea what I need to do?
Hamy
Just read your comment, but that is definitely what it was, if I scroll to the bottom of the pre-processed file I seeint SDL_main (int argc, char * argv[]);Any ideas what I should do from here?
Hamy
I would read up on the SDL documentation about setting up your first SDL application... that's outside the bounds of what I'm familiar with. You could also post another question on Stack Overflow, too.
fbrereto
The lostalgia docs may have something for you, too.
fbrereto
Thanks, really. This has given me a huge moral boost to get this far. I voted your answer up, but I think I will leave this unanswered until I finish it.
Hamy
A: 

Hey all,

I got this error to go away. If I understand, essentially SDL re-names the main function, so that it can do some stuff, then run your application, then clean up. Turns out that if you are building in Xcode, you must use ObjectiveC to compile your application.

In Xcode, telling the linker to try and use SDL_main(), rather than just main() does not work (for some technical reasons that are a bit beyond me). So, you include a few Objective C files. In Oc, you get the benefit of being able to say explicitely what the name of your main class is. Hence, the Objective C files you include seem to do nothing more than let Xcode know to look for SDL_main().

In summary, this really had nothing to do with Logstalgia, but was entirely a problem with getting SDL to link correctly in Xcode. This link is talking about this problem exactly. The SDLMain.h and SDLMain.m are Objective C files. If you can't find them, try googleing "Setting up SDL templates in Xcode." I installed the templates in Xcode, used one of them to create an empty project that would compile, link, and run (and promptly do nothing!) and then I added the project files I wanted to the pre-configured project.

Thanks!

Hamy