Can't compile SDL apps on OS X

I’m using OS X 10.3.1, and I whenever I try to compile an application
that uses SDL, it gives the following error:

ld: Undefined symbols:
_main

I have looked at the FAQ at
http://www.libsdl.org/faq.php?action=listentries&category=7 , and as
far as I can tell, I’m doing everything as I should; I’m including
SDL.h and SDL_main.h, and my main() has the appropriate prototype. I
have tried both the prebuilt SDL libraries and Fink’s SDL, with the
lines:

g++ -o test test.cpp -F$HOME/Library/Frameworks -framework Cocoa
-framework SDL
g++ -o test test.cpp -I/sw/include -L/sw/lib -lSDL -framework Cocoa

respectively. Both give the same error, even with a file as simple as
I can make, such as:

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

int main(int argc, char *argv[])
{
return 0;
}

Is there something really simple that I’m doing wrong? I see further
down in the FAQ a question labeled “
Is there a way to avoid SDLMain.m and Objective-C in my program? I want
a pure C/C++ program.”, but neither the pre-built download or Fink’s
SDL installed any .m files.

Thanks in advance,
P. J. Reed

I am putting together a new pkg installer for SDL-devel on OSX, for
Xcode. This new installer includes updated versions of the “SDL
Application” and “SDL OpenGL Application” project templates, an updated
SDL target template, and installs these templates in the correct
location for Xcode.

I realize another individual has handled packaging files for OSX in the
past but Xcode has been out for a while now without any update to the
SDL installer. I hope I don’t hurt anyone’s feelings, but users are
starting to have trouble with the templates that don’t work anymore.

That said, I need to ask a question of those familiar with SDL on OSX:
Can we move the framework installation path from the user’s to the
global library?
Xcode features ZeroLink, a system to increase compile speeds in
development builds by delaying linking until execution. However,
running an SDL application with ZeroLink enabled fails unless you add
SDL.framework to the project. However, Xcode references frameworks by
their path ("/users/phip/library/frameworks/SDL.framework"). A template
with such a reference would only work for that user. If we moved the
framework to the global /library/frameworks, this would work fine.
Is there a reason installing SDL into /Library/Frameworks would be a
bad idea?

I’ll wait for an answer to that and then publish the installer.

Thanks guys
John

About the undefined _main problem, from the FAQ:

 You *must* include SDLMain.m/.h in your application,
   because this is the code that defines SDL's entry point.
   If you fail to do this, it is likely that "_main undefined"
   will be thrown by the linker.

You need to add -lSDLmain to the link line, which includes the compiled
version of SDLMain.m.

I am putting together a new pkg installer for SDL-devel on OSX, for
Xcode. This new installer includes updated versions of the “SDL
Application” and “SDL OpenGL Application” project templates, an updated
SDL target template, and installs these templates in the correct
location for Xcode.

OK, but realize that I’ve already done this work last weekend :wink: The
new projects should be included with SDL 1.2.7. The exact same project
files work for both XCode and Project Builder 2.x. The only downside is
that the Xcode bells and whistles don’t activate (zero-link,
fix-and-continue, perhaps others) until the target is converted to a
native target, which Xcode handily performs for you (minus the
framework annoyance you have mentioned).

I realize another individual has handled packaging files for OSX in the
past but Xcode has been out for a while now without any update to the
SDL installer. I hope I don’t hurt anyone’s feelings, but users are
starting to have trouble with the templates that don’t work anymore.

The new SDL installer will put the stationary/templates in the right
directories.

That said, I need to ask a question of those familiar with SDL on OSX:
Can we move the framework installation path from the user’s to the
global library?
Xcode features ZeroLink, a system to increase compile speeds in
development builds by delaying linking until execution. However,
running an SDL application with ZeroLink enabled fails unless you add
SDL.framework to the project. However, Xcode references frameworks by
their path ("/users/phip/library/frameworks/SDL.framework"). A template
with such a reference would only work for that user. If we moved the
framework to the global /library/frameworks, this would work fine.
Is there a reason installing SDL into /Library/Frameworks would be a
bad idea?

The current “runtime” installers place the library in
/Library/Frameworks, and the “devel” installers put frameworks in
~/Library/Frameworks. There may not be much of an advantage to this
anymore, but there will be a few issues migrating to a condition where
all files are installed in /Library/Frameworks.

The big problem is to convert all of the projects (including the
projects we use to compile SDL and the installer packages). This also
includes other projects like SDL_image, SDL_mixer, SDL_sound, SMPEG,
and others that already rely on the framework to be where it is now,
and all put themselves into ~/Library/Frameworks/

OR I suppose it could be installed in both places to avoid breakage in
all existing project files (everyone using Xcode/Project Builder and
the framework up to this point will be affected).

I do, however, want to keep the projects working back to Mac OS X 10.1
(yes people still use it and we’ve actually done some work to make sure
10.1 is still supported). If the Xcode projects will break
backword-compatibility, then we’ll have to distribute both sets of
projects & templates with the installer and install the correct set
with the installer script (not a big deal really).

Regards,
DarrellOn Feb 4, 2004, at 4:50 PM, sdl-request at libsdl.org wrote:

That said, I need to ask a question of those familiar with
SDL on OSX:
Can we move the framework installation path from the user’s to the
global library?
Xcode features ZeroLink, a system to increase compile speeds in
development builds by delaying linking until execution. However,
running an SDL application with ZeroLink enabled fails
unless you add
SDL.framework to the project. However, Xcode references
frameworks by
their path
("/users/phip/library/frameworks/SDL.framework"). A template
with such a reference would only work for that user. If we moved the
framework to the global /library/frameworks, this would work fine.
Is there a reason installing SDL into /Library/Frameworks would be a
bad idea?

Will XCode bundle SDL along with the compiled application so the application
can run on systems without SDL already installed?

Quoting “Millaway, John” <John_Millaway at ghrsystems.com>:

Will XCode bundle SDL along with the compiled application so the application
can run on systems without SDL already installed?

This is a function of the deployment target. Simply, the answer is “YES”.

SDL can be included within an App bundle as an embedded framework or as an
embedded dynamic library (.dylib). I’ve done both.

However, that’s a function of Xcode or whatever IDE you choose (or manual
process, if so desired). To that end, such is off-topic for this list. Feel
free to ping me offline and I can point you towards resources that are
appropriate.

-daniel–
Do your kids need more space?
Get Low-cost Loft Bed Plans!
http://loft.hedrick.org/

John Philip wrote:

However, Xcode references frameworks by their path
("/users/phip/library/frameworks/SDL.framework"). A template with such a
reference would only work for that user.

My experience is that you can change that explicit path that Xcode
inserted when you added the framework to
"$(HOME)/Library/Frameworks/SDL.framework" afterwards, and things continue
to work. This could be a way to make the templates user-independent.

-Christian

I have not found a way to change the path of a framework. Do you mean a
framework added to the “groups & files” section by selecting “Add
Frameworks…” from the “Project” menu?

If you get info on the SDL framework added in this way, the path field
of the get info window will say (in my case)
"/Users/phip/Library/Frameworks/SDL.framework" - Which is not editable.

-johnOn Feb 6, 2004, at 9:24 AM, Christian Walther wrote:

John Philip wrote:

However, Xcode references frameworks by their path
("/users/phip/library/frameworks/SDL.framework"). A template with
such a
reference would only work for that user.

My experience is that you can change that explicit path that Xcode
inserted when you added the framework to
"$(HOME)/Library/Frameworks/SDL.framework" afterwards, and things
continue
to work. This could be a way to make the templates user-independent.

-Christian

John,

What about installing the framework in ~/Library/Frameworks and putting
a symlink to it in /Library/Frameworks? That should work and is
something we can easily do in the developer installer script.On Feb 12, 2004, at 1:56 PM, sdl-request at libsdl.org wrote:

Message: 10
From: John Philip
Subject: Re: [SDL] Re: Can’t compile SDL apps on OS X
Date: Wed, 11 Feb 2004 18:46:38 -0500
To: sdl at libsdl.org
Reply-To: sdl at libsdl.org

I have not found a way to change the path of a framework. Do you mean a
framework added to the “groups & files” section by selecting “Add
Frameworks…” from the “Project” menu?

If you get info on the SDL framework added in this way, the path field
of the get info window will say (in my case)
"/Users/phip/Library/Frameworks/SDL.framework" - Which is not editable.

-john

I thought that’s what the installer package already did?

The trouble is that $(HOME)/Library/Frameworks/SDL.framework and
~/Library/Frameworks/SDL.framework don’t appear to work as entries in
the project. And installation to /Users/me/… hard codes the path
(from what I’ve seen). I tried hacking the project.pbxproj file, but
the $(HOME) and ~ constructs didn’t work.

I ended up installing (locally) into /Library/Frameworks/SDL.framework,
and then building a template Xcode project that copied that framework
into the App bundle using a ‘Copy Files’ build phase. That way my
project builds completely self-contained executables.

-danielOn Feb 12, 2004, at 8:17 PM, Darrell Walisser wrote:

What about installing the framework in ~/Library/Frameworks and
putting a symlink to it in /Library/Frameworks? That should work and
is something we can easily do in the developer installer script.


Do your kids need more space?
Get Low-cost Loft Bed Plans!
http://loft.hedrick.org/

John Philip wrote:

I have not found a way to change the path of a framework. Do you mean a
framework added to the “groups & files” section by selecting “Add
Frameworks…” from the “Project” menu?

If you get info on the SDL framework added in this way, the path field
of the get info window will say (in my case)
"/Users/phip/Library/Frameworks/SDL.framework" - Which is not editable.

I mean the “Framework Search Paths” entry in the “Build” tab in the
info window for the target, which gets added when you “Add Frameworks…”.
This one is editable and continues to work with “$(HOME)” instead of
"/Users/username".

You are right, the path which the IDE uses to reference the framework
in the Groups & Files list is not editable. But I just did a quick test,
and it didn’t seem to matter that this framework can’t be found because
its path points to a nonexisting user’s home - even ZeroLink seems to work.

-Christian