Recent

Author Topic: SDL2 on mac  (Read 6598 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
SDL2 on mac
« on: December 26, 2021, 12:27:56 pm »
Hi everyone, I need to compile a project that uses sdl2s on mac. I downloaded the binaries from the link

https://www.libsdl.org/download-2.0.php

I copied the framework to / Library / Frameworks as explained in the readme.txt but it doesn't compile. Tells me:

Code: Pascal  [Select][+][-]
  1. Hint: (11030) Start of reading config file /fpcupdeluxe/installazioni/20210424_stabile/fpc/bin/x86_64-darwin/fpc.cfg
  2. Hint: (11031) End of reading config file /fpcupdeluxe/installazioni/20210424_stabile/fpc/bin/x86_64-darwin/fpc.cfg
  3. Free Pascal Compiler version 3.2.0-r45643 [2021/04/24] for x86_64
  4. Copyright (c) 1993-2020 by Florian Klaempfl and others
  5. (1002) Target OS: Darwin for x86_64
  6. (3104) Compiling trustInvaders.lpr
  7. (9001) Assembling (pipe) /Users/ngit/Downloads/TrustInvaders/lib/x86_64-darwin/trustInvaders.s
  8. (9015) Linking /Users/ngit/Downloads/TrustInvaders/bin/x86_64-darwin/trustInvaders
  9. Undefined symbols for architecture x86_64:
  10.   "_SDL_RenderDrawRect", referenced from:
  11.       _SDLGAMEENEMIES$_$TENEMY_$__$$_DRAW in sdlGameEnemies.o
  12.       _SHOTS$_$TEXPLOSION_$__$$_DRAW in Shots.o
  13.       _SHOTS$_$TSHOT_$__$$_DRAWSHOT in Shots.o
  14.   "_SDL_SetTextureColorMod", referenced from:
  15.       _SCNGAMEPLAY$_$TMENU_$__$$_DRAW in scnGamePlay.o
  16.       _SDLGAMEENEMIES$_$TENEMY_$__$$_DRAW in sdlGameEnemies.o
  17.       _SHOTS$_$TEXPLOSION_$__$$_DRAW in Shots.o
  18.   "_SDL_SetTextureBlendMode", referenced from:
  19.       _SCNMAINMENU$_$TMAINMENUSCENE_$__$$_DOONRENDER$PSDL_RENDERER in scnMainMenu.o
  20.       _SCNGAMEPLAY$_$TMENU_$__$$_DRAW in scnGamePlay.o
  21.   "_SDL_JoystickNameForIndex", referenced from:
  22.       _SDLENGINE$_$TENGINE_$__$$_DOCHECKDEVICES in sdlEngine.o
  23.   "_Mix_PauseMusic", referenced from:
  24.       _SDLGAMESOUND$_$TSOUNDMANAGER_$__$$_STOPMUSIC$LONGINT in sdlGameSound.o
  25.   "_Mix_PlayMusic", referenced from:
  26.       _SDLGAMESOUND$_$TSOUNDMANAGER_$__$$_PLAYMUSIC$LONGINT$LONGINT in sdlGameSound.o
  27.       _SDLGAMESOUND$_$TSOUNDMANAGER_$__$$_STOPMUSIC$LONGINT in sdlGameSound.o
  28.   "_Mix_LoadMUS", referenced from:
  29.       _SDLGAMESOUND$_$TSOUNDMANAGER_$__$$_LOADMUSIC$ANSISTRING$$LONGINT in sdlGameSound.o
  30.   "_Mix_FreeChunk", referenced from:
  31.       _SDLGAMESOUND$_$TSOUNDMANAGER_$__$$_DESTROY in sdlGameSound.o
  32.   "_SDL_JoystickOpen", referenced from:
  33.       _SDLENGINE$_$TENGINE_$__$$_DOCHECKDEVICES in sdlEngine.o
  34.   "_IMG_Load", referenced from:
  35.       _SDLGAMETEXTURE$_$TTEXTUREMANAGER_$__$$_LOADPNGTEXTURE$ANSISTRING$$TTEXTURE in sdlGameTexture.o
  36.   "_TTF_OpenFont", referenced from:
  37.       _SDLGAMETEXT$_$TFONTS_$__$$_LOADFONTS$ANSISTRING in sdlGameText.o
  38.   "_SDL_RenderPresent", referenced from:
  39.       _SDLENGINE$_$TENGINE_$__$$_DORENDER in sdlEngine.o
  40.   "_SDL_SetRenderDrawBlendMode", referenced from:
  41.       _SDLGAMETEXT$_$TTEXTMANAGER_$__$$_DRAW$ANSISTRING$LONGINT$LONGINT$TGAMEFONT in sdlGameText.o
  42.       _SDLGAMETEXT$_$TTEXTMANAGER_$__$$_DRAW$ANSISTRING$LONGINT$LONGINT$TGAMEFONT$BYTE in sdlGameText.o
  43.       _SCNINTRO$_$TINTROSCENE_$__$$_DOONRENDER$PSDL_RENDERER in scnIntro.o
  44.       _SCNMAINMENU$_$TMAINMENUSCENE_$__$$_DOONRENDER$PSDL_RENDERER in scnMainMenu.o
  45.       _SCNGAMEPLAY$_$TGAMEPLAYSCENE_$__$$_DRAWUI in scnGamePlay.o
  46.       _SCNGAMEPLAY$_$TMENU_$__$$_DRAW in scnGamePlay.o
  47.       _SDLPARTICLES$_$TEMITTER_$__$$_DRAW in sdlParticles.o
  48.       ...
  49.   "_SDL_SetTextureAlphaMod", referenced from:
  50.       _SDLGAMETEXT$_$TTEXTMANAGER_$__$$_DRAW$ANSISTRING$LONGINT$LONGINT$TGAMEFONT$BYTE in sdlGameText.o
  51.       _SCNINTRO$_$TINTROSCENE_$__$$_DOONRENDER$PSDL_RENDERER in scnIntro.o
  52.       _SCNMAINMENU$_$TMAINMENUSCENE_$__$$_DOONRENDER$PSDL_RENDERER in scnMainMenu.o
  53.       _SCNGAMEPLAY$_$TMENU_$__$$_DRAW in scnGamePlay.o
  54.       _SHOTS$_$TEXPLOSION_$__$$_DRAW in Shots.o
  55.   "_SDL_RenderCopy", referenced from:
  56.       _SDLGAMETEXT$_$TTEXTMANAGER_$__$$_DRAW$ANSISTRING$LONGINT$LONGINT$TGAMEFONT in sdlGameText.o
  57.       _SDLGAMETEXT$_$TTEXTMANAGER_$__$$_DRAW$ANSISTRING$LONGINT$LONGINT$TGAMEFONT$BYTE in sdlGameText.o
  58.       _SCNINTRO$_$TINTROSCENE_$__$$_DOONRENDER$PSDL_RENDERER in scnIntro.o
  59.       _SCNMAINMENU$_$TMAINMENUSCENE_$__$$_DOONRENDER$PSDL_RENDERER in scnMainMenu.o
  60.       _SCNGAMEPLAY$_$TGAMEPLAYSCENE_$__$$_DRAWUI in scnGamePlay.o
  61.       _SCNGAMEPLAY$_$TMENU_$__$$_DRAW in scnGamePlay.o
  62.       _SDLGAMEPLAYER$_$TPLAYER_$__$$_DRAW in sdlGamePlayer.o
  63.       ...
  64.   "_TTF_RenderUTF8_Blended", referenced from:
  65.       _SDLGAMETEXT$_$TGAMEFONTTEXTURELIST_$__$$_ADD$ANSISTRING$TGAMEFONT$$LONGINT in sdlGameText.o
  66.   "_Mix_PlayChannelTimed", referenced from:
  67.       _SDL2_MIXER_$$_MIX_PLAYCHANNEL$LONGINT$PMIX_CHUNK$LONGINT$$LONGINT in sdl2_mixer.o
  68.   "_SDL_CreateTextureFromSurface", referenced from:
  69.       _SDLGAMETEXT$_$TGAMEFONTTEXTURELIST_$__$$_ADD$ANSISTRING$TGAMEFONT$$LONGINT in sdlGameText.o
  70.       _SDLGAMETEXTURE$_$TTEXTUREMANAGER_$__$$_LOADPNGTEXTURE$ANSISTRING$$TTEXTURE in sdlGameTexture.o
  71.   "_SDL_FreeSurface", referenced from:
  72.       _SDLGAMETEXT$_$TGAMEFONTTEXTURELIST_$__$$_ADD$ANSISTRING$TGAMEFONT$$LONGINT in sdlGameText.o
  73.       _SDLGAMETEXTURE$_$TTEXTUREMANAGER_$__$$_LOADPNGTEXTURE$ANSISTRING$$TTEXTURE in sdlGameTexture.o
  74.   "_SDL_JoystickNumAxes", referenced from:
  75.       _SDLENGINE$_$TENGINE_$__$$_DOCHECKDEVICES in sdlEngine.o
  76.   "_IMG_Init", referenced from:
  77.       _SDLENGINE$_$TENGINE_$__$$_INITIALIZE$LONGINT$LONGINT$ANSISTRING in sdlEngine.o
  78.   "_SDL_DestroyTexture", referenced from:
  79.       _SDLGAMETEXT$_$TGAMEFONTTEXTURELIST_$__$$_DESTROY in sdlGameText.o
  80.   "_SDL_GetError", referenced from:
  81.       _SDLENGINE$_$TENGINE_$__$$_INITIALIZE$LONGINT$LONGINT$ANSISTRING in sdlEngine.o
  82.       _SDL2_IMAGE_$$_IMG_GETERROR$$PCHAR in sdl2_image.o
  83.       _SDL2_MIXER_$$_MIX_GETERROR$$PCHAR in sdl2_mixer.o
  84.       _SDL2_TTF_$$_TTF_GETERROR$$PCHAR in sdl2_ttf.o
  85.       _SDLGAMETEXT$_$TGAMEFONTTEXTURELIST_$__$$_ADD$ANSISTRING$TGAMEFONT$$LONGINT in sdlGameText.o
  86.       _SDLGAMETEXTURE$_$TTEXTUREMANAGER_$__$$_LOADPNGTEXTURE$ANSISTRING$$TTEXTURE in sdlGameTexture.o
  87.   "_SDL_RWFromFile", referenced from:
  88.       _SDL2_MIXER_$$_MIX_LOADWAV$PCHAR$$PMIX_CHUNK in sdl2_mixer.o
  89.   "_SDL_RenderCopyEx", referenced from:
  90.       _SCNINTRO$_$TINTROSCENE_$__$$_DOONRENDER$PSDL_RENDERER in scnIntro.o
  91.       _SCNMAINMENU$_$TMAINMENUSCENE_$__$$_DOONRENDER$PSDL_RENDERER in scnMainMenu.o
  92.       _SCNGAMEPLAY$_$TMENU_$__$$_DRAW in scnGamePlay.o
  93.       _SHOTS$_$TSHOT_$__$$_DRAWSHOT in Shots.o
  94.   "_Mix_LoadWAV_RW", referenced from:
  95.       _SDL2_MIXER_$$_MIX_LOADWAV$PCHAR$$PMIX_CHUNK in sdl2_mixer.o
  96.   "_SDL_GetTicks", referenced from:
  97.       _SDLENGINE$_$TENGINE_$__$$_RUN in sdlEngine.o
  98.       _SDLGAMEUTILS$_$TFPSCOUNTER_$__$$_RESET in sdlGameUtils.o
  99.       _SDLGAMEUTILS$_$TFPSCOUNTER_$__$$_INCREMENT in sdlGameUtils.o
  100.       _SDLSCENE$_$TSCENE_$__$$_DOONUPDATE$REAL in sdlScene.o
  101.       _SDLSCENE$_$TSCENE_$__$$_EXECUTEDELAYED$LONGWORD$TSCENEMETHOD in sdlScene.o
  102.       _SCNINTRO$_$TINTROSCENE_$__$$_CREATE$$TINTROSCENE in scnIntro.o
  103.       _SDLGAMEENEMIES$_$TENEMY_$__$$_UPDATE$REAL in sdlGameEnemies.o
  104.       ...
  105.   "_Mix_FreeMusic", referenced from:
  106.       _SDLGAMESOUND$_$TSOUNDMANAGER_$__$$_DESTROY in sdlGameSound.o
  107.       _SDLGAMESOUND$_$TSOUNDMANAGER_$__$$_FREEMUSIC$LONGINT in sdlGameSound.o
  108.   "_Mix_Quit", referenced from:
  109.       _SDLENGINE$_$TENGINE_$__$$_DESTROY in sdlEngine.o
  110.   "_SDL_Delay", referenced from:
  111.       _SDLENGINE$_$TENGINE_$__$$_RUN in sdlEngine.o
  112.   "_SDL_ShowCursor", referenced from:
  113.       _SDLENGINE$_$TENGINE_$__$$_HIDECURSOR in sdlEngine.o
  114.   "_SDL_RenderDrawLine", referenced from:
  115.       _SCNMAINMENU$_$TMAINMENUSCENE_$__$$_DOONRENDER$PSDL_RENDERER in scnMainMenu.o
  116.       _SCNGAMEPLAY$_$TGAMEPLAYSCENE_$__$$_DRAWUI in scnGamePlay.o
  117.       _SCNGAMEPLAY$_$TMENU_$__$$_DRAW in scnGamePlay.o
  118.   "_SDL_CreateWindow", referenced from:
  119.       _SDLENGINE$_$TENGINE_$__$$_INITIALIZE$LONGINT$LONGINT$ANSISTRING in sdlEngine.o
  120.   "_SDL_CreateRenderer", referenced from:
  121.       _SDLENGINE$_$TENGINE_$__$$_INITIALIZE$LONGINT$LONGINT$ANSISTRING in sdlEngine.o
  122.   "_IMG_Quit", referenced from:
  123.       _SDLENGINE$_$TENGINE_$__$$_DESTROY in sdlEngine.o
  124.   "_SDL_SetWindowTitle", referenced from:
  125.       _SDLENGINE$_$TENGINE_$__$$_ONFPSCOUNTERUPDATED$TFPSCOUNTER$WORD in sdlEngine.o
  126.   "_SDL_RenderFillRect", referenced from:
  127.       _SCNMAINMENU$_$TMAINMENUSCENE_$__$$_DOONRENDER$PSDL_RENDERER in scnMainMenu.o
  128.       _SCNGAMEPLAY$_$TGAMEPLAYSCENE_$__$$_DRAWUI in scnGamePlay.o
  129.       _SCNGAMEPLAY$_$TMENU_$__$$_DRAW in scnGamePlay.o
  130.       _STARTFIELD$_$TSTARFIELD_$__$$_DRAW in StartField.o
  131.       _SDLPARTICLES$_$TEMITTER_$__$$_DRAW in sdlParticles.o
  132.   "_SDL_Quit", referenced from:
  133.       _SDLENGINE$_$TENGINE_$__$$_DESTROY in sdlEngine.o
  134.   "_SDL_RenderClear", referenced from:
  135.       _SDLENGINE$_$TENGINE_$__$$_DORENDER in sdlEngine.o
  136.   "_SDL_Init", referenced from:
  137.       _SDLENGINE$_$TENGINE_$__$$_INITIALIZE$LONGINT$LONGINT$ANSISTRING in sdlEngine.o
  138.   "_Mix_OpenAudio", referenced from:
  139.       _SDLENGINE$_$TENGINE_$__$$_INITIALIZE$LONGINT$LONGINT$ANSISTRING in sdlEngine.o
  140.   "_SDL_DestroyRenderer", referenced from:
  141.       _SDLENGINE$_$TENGINE_$__$$_DESTROY in sdlEngine.o
  142.   "_TTF_Init", referenced from:
  143.       _SDLENGINE$_$TENGINE_$__$$_INITIALIZE$LONGINT$LONGINT$ANSISTRING in sdlEngine.o
  144.   "_SDL_DestroyWindow", referenced from:
  145.       _SDLENGINE$_$TENGINE_$__$$_DESTROY in sdlEngine.o
  146.   "_SDL_HasIntersection", referenced from:
  147.       _SDLGAMEOBJECTS$_$TGAMEOBJECT_$__$$_CHECKCOLLISIONS$TGAMEOBJECTLIST in sdlGameObjects.o
  148.       _SDLGAMEOBJECTS$_$TGAMEOBJECT_$__$$_CHECKCOLLISIONS$TGAMEOBJECT in sdlGameObjects.o
  149.   "_SDL_NumJoysticks", referenced from:
  150.       _SDLENGINE$_$TENGINE_$__$$_DOCHECKDEVICES in sdlEngine.o
  151.   "_SDL_JoystickNumButtons", referenced from:
  152.       _SDLENGINE$_$TENGINE_$__$$_DOCHECKDEVICES in sdlEngine.o
  153.   "_TTF_CloseFont", referenced from:
  154.       _SDLGAMETEXT$_$TFONTS_$__$$_DESTROY in sdlGameText.o
  155.   "_SDL_JoystickClose", referenced from:
  156.       _SDLENGINE$_$TENGINE_$__$$_DOCHECKDEVICES in sdlEngine.o
  157.   "_SDL_SetRenderDrawColor", referenced from:
  158.       _SDLENGINE$_$TENGINE_$__$$_DORENDER in sdlEngine.o
  159.       _SCNMAINMENU$_$TMAINMENUSCENE_$__$$_DOONRENDER$PSDL_RENDERER in scnMainMenu.o
  160.       _SCNGAMEPLAY$_$TGAMEPLAYSCENE_$__$$_DRAWUI in scnGamePlay.o
  161.       _SCNGAMEPLAY$_$TMENU_$__$$_DRAW in scnGamePlay.o
  162.       _STARTFIELD$_$TSTARFIELD_$__$$_DRAW in StartField.o
  163.       _SDLPARTICLES$_$TEMITTER_$__$$_DRAW in sdlParticles.o
  164.       _SDLGAMEENEMIES$_$TENEMY_$__$$_DRAW in sdlGameEnemies.o
  165.       ...
  166.   "_SDL_PollEvent", referenced from:
  167.       _SDLENGINE$_$TENGINE_$__$$_DOHANDLEEVENTS in sdlEngine.o
  168.   "_SDL_JoystickNumBalls", referenced from:
  169.       _SDLENGINE$_$TENGINE_$__$$_DOCHECKDEVICES in sdlEngine.o
  170. ld: symbol(s) not found for architecture x86_64
  171. An error occurred while linking
  172. Error: (9013) Error while linking
  173. Fatal: (10026) There were 1 errors compiling module, stopping
  174. Fatal: (1018) Compilation aborted
  175. Error: /fpcupdeluxe/installazioni/20210424_stabile/fpc/bin/x86_64-darwin/ppcx64 returned an error exitcode
  176.  

Why?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: SDL2 on mac
« Reply #1 on: December 26, 2021, 12:44:32 pm »
In your .lpr do you have something like the following?
Code: Pascal  [Select][+][-]
  1. {$ifdef darwin}
  2. {$linkframework SDL2}
  3. {$linkframework SDL2_mixer}// add these and others as required by the routines you use
  4. // e.g. {$linkframework SDL2_ttf}
  5. // e.g. {$linkframework SDL2_image}
  6. {$endif}

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: SDL2 on mac
« Reply #2 on: December 30, 2021, 07:32:13 pm »
Thanks for the tip. Now when I compile it tells me:

ld: framework not found SDL2

But as I said above, I'm sure I have the framework on my mac.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2023
  • Former Delphi 1-7, 10.2 user
Re: SDL2 on mac
« Reply #3 on: December 30, 2021, 10:23:05 pm »
You need to tell the linker where to look for the SDL2 framework.

On the fpc command line add: OPT="-XR/path/to/sdl2_framework"

Or in an .fpc.cfg file in your home directory:


#include /private/etc/fpc.cfg
-XR/path/to/sdl2_framework
« Last Edit: January 04, 2022, 01:59:59 am by trev »

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: SDL2 on mac
« Reply #4 on: January 03, 2022, 09:37:20 pm »
Ok, I created .fp.cfg file

Code: Pascal  [Select][+][-]
  1. #include /private/etc/fpc.cfg
  2. -XR/Library/Frameworks/SDL2.framework

In "Project options"->"Configuration and target"-> check "Use other configuration files to compilator (@) " + "/Users/ngit/.fp.cfg"

When I compile return this

Code: Pascal  [Select][+][-]
  1. Compila il progetto, Destinazione: /Users/ngit/Downloads/TrustInvaders/bin/x86_64-darwin/trustInvaders: Codice di uscita 1, Errori: 1, suggerimenti: 6
  2. Hint: Start of reading config file /fpcupdeluxe/installazioni/20210424_stabile/fpc/bin/x86_64-darwin/fpc.cfg
  3. Hint: End of reading config file /fpcupdeluxe/installazioni/20210424_stabile/fpc/bin/x86_64-darwin/fpc.cfg
  4. Hint: Start of reading config file /Users/ngit/.fp.cfg
  5. Hint: Start of reading config file /private/etc/fpc.cfg
  6. Hint: End of reading config file /private/etc/fpc.cfg
  7. Hint: End of reading config file /Users/ngit/.fp.cfg
  8. Verbose: Free Pascal Compiler version 3.2.0-r45643 [2021/04/24] for x86_64
  9. Verbose: Copyright (c) 1993-2020 by Florian Klaempfl and others
  10. Verbose: Target OS: Darwin for x86_64
  11. Verbose: Compiling trustInvaders.lpr
  12. Verbose: Assembling (pipe) /Users/ngit/Downloads/TrustInvaders/lib/x86_64-darwin/trustInvaders.s
  13. Verbose: Linking /Users/ngit/Downloads/TrustInvaders/bin/x86_64-darwin/trustInvaders
  14. Debug: ld: library not found for -lobjc
  15. An error occurred while linking
  16. Error: Error while linking
  17. Verbose: There were 1 errors compiling module, stopping
  18. Verbose: Compilation aborted
  19. Verbose: /fpcupdeluxe/installazioni/20210424_stabile/fpc/bin/x86_64-darwin/ppcx64 returned an error exitcode
  20.  
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2023
  • Former Delphi 1-7, 10.2 user
Re: SDL2 on mac
« Reply #5 on: January 03, 2022, 10:04:52 pm »
.fp.cfg should have been .fpc.cfg, but I sent you down the wrong path anyway. Sorry.

Try this: In the Lazarus Project Options > Tools > Options - Compilation and Linking, add -F/path/to/sdl_framework to the "Pass options to linker..." (do not include the -k it is included automatically). The linker should then find the SDL framework.
« Last Edit: January 03, 2022, 10:16:31 pm by trev »

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: SDL2 on mac
« Reply #6 on: January 09, 2022, 05:14:25 pm »
.fp.cfg should have been .fpc.cfg, but I sent you down the wrong path anyway. Sorry.

Try this: In the Lazarus Project Options > Tools > Options - Compilation and Linking, add -F/path/to/sdl_framework to the "Pass options to linker..." (do not include the -k it is included automatically). The linker should then find the SDL framework.
did not solve. any other ideas ?!
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2023
  • Former Delphi 1-7, 10.2 user
Re: SDL2 on mac
« Reply #7 on: January 09, 2022, 10:31:26 pm »
did not solve. any other ideas ?!

I tested it (not for SDL but for something else) so it should work.

Compile with -va (Project Options > Tools > Options - Verbosity) and copy the log from the messages window into TextEdit and check where it is looking for the SDL framework and compare that to where the SDL framework is located.

 

TinyPortal © 2005-2018