1

I am using Windows 10 and Strawberry Perl. I found this nice tutorial on building a 3D engine in Perl. Which requires SDL. For a couple of days I've been trying to install it, but it doesn't work. First I tried via CPAN, no success. No I am trying manually, but I am getting error messages when using "make". If I type "perl -V:make" it says I should use "dmake". If I do so, there's a dmake warning, telling me to use gmake instead. If I do that, there's the following message:

"to undefined at C:/Perl64/site/lib/ExtUtils/Install.pm line 1199. gmake: *** [Makefile:942: pm_to_blib] Error 2"

Any suggestions how to fix this? Or is there an easy (easier) way to install SDL?

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • Which `perl` version are you using? – Håkon Hægland Mar 30 '20 at 11:04
  • ActivePerl5.26.3. My mistake. Not Strawberry. Although I installed Strawberry also I think... – Christoph Barth Mar 30 '20 at 11:16
  • How did you install the [SDL library](https://wiki.libsdl.org/Installation) on Windows? – Håkon Hægland Mar 30 '20 at 11:21
  • First I tried via CPAN which didn't work. So I downloaded SDL. Unzipped the files, now I have a Build.PL File, if I run that, it says I may need to install the Alien::SDL module. So I downloaded that, ..., another Build.PL File. Then my only option is to quit installation. checking SDL_INST_DIR env var... no. checking for config script... no. checking for prebuilt binaries... no. – Christoph Barth Mar 30 '20 at 11:50
  • If you're using ActiveState, did you try `ppm install SDL`? – jimtut Mar 30 '20 at 12:48
  • It seems like the Perl SDL module uses SDL version 1.2.14, whereas the [documentation](http://wiki.libsdl.org/SourceCode) says *"The best course of action is to move to SDL 2.0 or later as quickly as possible"*. I would recommend looking at the Python bindings [PySDL2](https://pypi.org/project/PySDL2/) instead – Håkon Hægland Mar 30 '20 at 13:08
  • I just did: "Can't find any package that provides SDL". Although I downlaoded a SDL-....ppmx File from Activestate... – Christoph Barth Mar 30 '20 at 13:12
  • Tried to install PySDL2 via pip. "Can't locate pip.pm in@INC (you may need to install the pip module)" What does pip have to do with Perl? Cause the error message says something about Perl64 and Dwimperl... – Christoph Barth Mar 30 '20 at 13:46
  • Ok, so I finally managed to install PySDL2 manually. But how do use it in my Perl-Script? Originally it says: use SDL::App; and use SDL::OpenGL;. – Christoph Barth Mar 30 '20 at 16:20

1 Answers1

-1

It seems like the Perl SDL module uses SDL version 1.2.14, whereas the documentation says

The best course of action is to move to SDL 2.0 or later as quickly as possible

So, I would recommend looking at the Python bindings PySDL2 instead. The following worked for me on Windows 10:

Downloaded Python 3.8 from here:

https://www.python.org/ftp/python/3.8.2/python-3.8.2-amd64.exe

Then added the following to the User enviroment variables for "Path" (NOTE: at the beginning, not at the end):

%USERPROFILE%\AppData\Local\Programs\Python\Python38
%USERPROFILE%\AppData\Local\Programs\Python\Python38\Scripts

Then, from the command prompt install pysdl2:

>pip install pysdl2
Collecting pysdl2
  Downloading https://files.pythonhosted.org/packages/60/ba/ddb48261848874eeb3d54963edbf3c74fff86499746aeb23151f123953bb/PySDL2-0.9.7-py3-none-any.whl (541kB)
     |████████████████████████████████| 542kB 2.2MB/s
Installing collected packages: pysdl2
Successfully installed pysdl2-0.9.7

>pip install pysdl2-dll
Collecting pysdl2-dll
  Downloading https://files.pythonhosted.org/packages/01/37/f9aa5472fb85ce94507c69110916133ad29b650d2bf277de2cce37d7ad7d/pysdl2_dll-2.0.12-py2.py3-none-win_amd64.whl (2.5MB)
     |████████████████████████████████| 2.5MB 3.2MB/s
Installing collected packages: pysdl2-dll
Successfully installed pysdl2-dll-2.0.12

Then, add a new User environment variable PYTHONPATH with value:

%USERPROFILE%\AppData\Local\Programs\Python\Python38\Lib\site-packages

Close the command prompt, and reopen a new one to update the environment variables. Then I created a test Python script:

import sys
import sdl2.ext
resource_dir=r'C:\Users\hakon\AppData\Local\Programs\Python\Python38\Lib\site-packages\sdl2\examples'
RESOURCES = sdl2.ext.Resources(resource_dir, "resources")
sdl2.ext.init()

window = sdl2.ext.Window("Hello World!", size=(640, 480))
window.show()

factory = sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE)
sprite = factory.from_image(RESOURCES.get_path("hello.bmp"))

spriterenderer = factory.create_sprite_render_system(window)
spriterenderer.render(sprite)

processor = sdl2.ext.TestEventProcessor()
processor.run(window)

sdl2.ext.quit()

and finally run it from the command prompt:

> python test.py
HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174
  • Thanks so much. The script didn't work... "ImportError: could not find any library for SDL2 (PYSDL2_DLL_PATH: unset)". – Christoph Barth Mar 30 '20 at 17:08
  • But apart from that (I think I installed PYSDL2 properly) - how do I use it in my Perl - Script? "use SDL:App; and use SDL:OpenGL;" is what I am supposed to type... But now? – Christoph Barth Mar 30 '20 at 17:11
  • You cannot use it from a Perl script, it is a Python module so you need to create a Python script. Regarding the import error, where did you install the dll libraries? I had them installed to `C:\Users\hakon\AppData\Local\Programs\Python\Python38\Lib\site-packages\sdl2dll` – Håkon Hægland Mar 30 '20 at 17:18
  • Alright, it works now, thank you. But the main reason I posted here today, is that I want to learn Perl. And as I said in the beginning, there's this tutorial, where I need to use SDL in Perl. So it's really cool, that this works for Python, but it's not really helping on my Perl journey.... But thanks anyways for your time and effort. Really appreciate it – Christoph Barth Mar 30 '20 at 17:51