SDL and IDEs in Windows

Hello,

I’m trying to work on a C programming project for a course where I’m
effectively turning my keyboard into a piano. I’d like to use SDL for
audio input, but I keep getting odd linking errors or compiler errors
with both Dev C++ and CodeWarrior. Are there any tricks to getting the
projects in either to actually compile using SDL? Do I need to #include
more than just the SDL.h file?

Sample errors:
Codewarrior:
Error : Undefined symbol: '_main’
referenced from ‘_mainCRTStartup’ in maincrt.c:81 (MSL_All_x86_D.lib)
maincrt.c line 81

Dev C++:
[Linker error] undefined reference to `WinMain at 16’
AND:
C:\Program Files\Dev-C++\Dev-Cpp\Piano\Makefile.win
[Build Error] [Audio.exe] Error 1

Thanks,
Will

Sample errors:
Codewarrior:
Error : Undefined symbol: '_main’
referenced from ‘_mainCRTStartup’ in maincrt.c:81 (MSL_All_x86_D.lib)
maincrt.c line 81

Dev C++:
[Linker error] undefined reference to <mailto:WinMain at 16'>WinMain at 16’
AND:
C:\Program Files\Dev-C++\Dev-Cpp\Piano\Makefile.win
[Build Error] [Audio.exe] Error 1

Those errors aren’t linker problems, it would seem that you haven’t defined
a main method. Does your code define one?

Neil.

William Clayton wrote:

Sample errors:
/Dev C++:/
[Linker error] undefined reference to WinMain at 16' <mailto:WinMain at 16’>
/AND:/
C:\Program Files\Dev-C++\Dev-Cpp\Piano\Makefile.win
[Build Error] [Audio.exe] Error 1

You need to link both SDL.lib, and SDLmain.lib into the program.

Regards,
\Mikkel Gjoel

Mikkel Gj?l wrote:

William Clayton wrote:

Sample errors:
/Dev C++:/
[Linker error] undefined reference to WinMain at 16' <mailto:WinMain at 16’>
/AND:/
C:\Program Files\Dev-C++\Dev-Cpp\Piano\Makefile.win
[Build Error] [Audio.exe] Error 1

You need to link both SDL.lib, and SDLmain.lib into the program.

Regards,
\Mikkel Gjoel

Let me add that on my system (Dev-C++), it’s important to write the
-lSDLmain before -lSDL, or I get the exact same error that you describe.
So, try that.

Does anyone on this list know the cause for this behaviour?

Sebastian

Let me add that on my system (Dev-C++), it’s important to write the
-lSDLmain before -lSDL, or I get the exact same error that you describe.
So, try that.

Does anyone on this list know the cause for this behaviour?

I assume the topic is MinGW, therefor GCC.

From gcc info (about -l option):
It makes a difference where in the command you write this option;
the linker searches and processes libraries and object files in
the order they are specified. Thus, foo.o -lz bar.o' searches libraryz’ after file foo.o' but beforebar.o’. If bar.o' refers to functions inz’, those functions may not be loaded.

I do not know in detail, which functions from SDL refer to SDLmain or vice
versa. But basically the cause for the behaviour is just how GCC handles
object files. As far as I know, with MSVC for example the order makes no
difference.

PeterOn Tue, 04 Nov 2003 20:22:27 +0100, Sebastian Beschke <s.beschke at gmx.de> wrote: