g++...">

SDL calls the Undefined: "_main" characters referenced: start at crt1.10.5.o

When I try to use SDL in my C ++ program, I get the following:

> g++ minimal.cpp SDLMain.m Undefined symbols: "_main", referenced from: start in crt1.10.5.o ld: symbol(s) not found collect2: ld returned 1 exit status 

Here is my minimal.cpp:

 #include <SDL/SDL.h> int main(int argc, char **argv) { return 0; } 

What I can collect from http://www.libsdl.org/faq.php?action=listentries&category=7 was that by turning on SDL.h it renames my main function with some macro magic. But then SDLMain.m should again do everything right by calling this renamed function. But for some reason this is not happening?

I am running Leopard.

Please note that this is another issue from question 550455.

+4
source share
3 answers

The solution was to use the SDLMain.m file included in SDL-devel-1.2.14-extras.dmg from the SDL homepage. For some reason, the one I used before mysteriously stopped working. Here is my working compilation command:

 g++ -framework SDL -framework Cocoa -I/usr/local/include/SDL/ minimal.cpp "/Library/Application Support/Developer/Shared/Xcode/Project Templates/SDL Application/SDLMain.m" 
+2
source

You can also use the provided sdl-config SDL tool:

 gcc sdltest.c -o sdltest `sdl-config --cflags --libs` 
+3
source

Config: OSX 10.10.5 XCODE 7.0 SDL 1.2.15

How to reproduce:

  • Copy SDL.Framework to / Library / Frameworks as described in readme.txt

  • In the XCODE template> Building Settings> Platform Search View as / Library / Frameworks

  • I included the SDL structure in the main.cpp file as follows:

    #include <SDL / SDL.h>

Then I had the same problem as loading the SDL Framework on XCODE due to the double declaration of the main class, which blocked compilation.

This error message is:

 Undefined symbols for architecture x86_64: "_main", referenced from: implicit entry/start for main executable (maybe you meant: _SDL_main) 

Here's how I solved it:

I checked and saw that SDL.h includes all of the following files:

 #include "SDL_main.h" #include "SDL_stdinc.h" #include "SDL_audio.h" #include "SDL_cdrom.h" #include "SDL_cpuinfo.h" #include "SDL_endian.h" #include "SDL_error.h" #include "SDL_events.h" #include "SDL_loadso.h" #include "SDL_mutex.h" #include "SDL_rwops.h" #include "SDL_thread.h" #include "SDL_timer.h" #include "SDL_video.h" #include "SDL_version.h" #include "begin_code.h" 

One of them is SDL_main.h, and in this file we see:

 #define main SDL_main 

This line creates a conflict with the main class on main.cpp, commenting on this line on SDL_main.h or commenting on the #include "SDL_main.h" line on SDL.h, solving the problem. I am noob in C ++ (I just studied it at the university many years ago), but from other languages ​​I know that hacking the library is a very bad practice ... although it seems to be a special compatibility problem with MAXOSX and I really I want to use XCODE ...

Please correct and comment, justify yes or no, as I participate in the learning process.

Hurrah!

0
source

Source: https://habr.com/ru/post/1302295/


All Articles