SmallBASIC
SmallBASIC copied to clipboard
SDL Build fails on Arch Linux
Hi there!
Trying to build the SDL version on Arch Linux (updated as of today). All steps go well until the linking step, where it spits out pages and pages of undefined reference errors in relation to SDL, such as /usr/bin/ld: /home/amr/sources/SmallBASIC/src/platform/sdl/main.cpp:363: undefined reference to 'SDL_CreateWindow'
The ./configure
step does successfully find SDL libs (though it does seem to erroneously display the output of sdl2-config
during the configure step instead of redirecting that output to null or something). Looking at the generated Makefile, on like 260 at PACKAGE_LIBS, I don't see -lSDL2
and for some reason -lfreetype
is duplicated:
PACKAGE_LIBS = -static-libgcc -ldl -no-pie -lfontconfig -lfreetype -lfreetype -lpcre
Trying to manually add -lSDL2
there doesn't work for some reason, I can see the -lSDL2
isn't being included in the generated command by make. I have no experience with autotools, so I'm really not sure what it does. However, pkg-config --cflags --libs sdl2
correctly returns -I/usr/include/SDL2 -D_REENTRANT -lSDL2
so again I'm not sure what's happening there. I suspect it's something to do with the fact that Arch is always using the latest packages, including the latest gcc/binutils/pkg-config/sdl2-libs/autotools etc. In the linked full make log below, you can see that the --cflags
part of pkg-config
is being correctly passed to GCC, so I'm not sure why -lSDL2
fails to get parsed.
I'm more than happy to help debug this or provide any additional logs/output if it will help!
I'm using Manjaro Linux and I had the same issue. This link helped to find the problem in my case: github
When building the SmallBASIC SDL version, you will use ./configure --enable-sdl
. The configure script will run at some point the command sdl2-config --static-libs
. Unfortunately this leads to an error, because the parameter --static-libs
is commented in the sdl2-config script. For me it help to edit the file /usr/bin/sdl2-config
and uncomment that part of the script. I also had to change that part of the script in a way, that it will return only the libs without .a
Maybe it will help. At the weekend (when I have access to my Linux machine) I can post the changes I made to that file.
You can test by running in a console /usr/bin/sdl2-config --static-libs
and see what it will output. It should return the libs needed to compile.
here my sdl2-config file:
# Get the canonical path of the folder containing this script
bindir=$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)")
# Calculate the canonical path of the prefix, relative to the folder of this script
prefix=$(cd -P -- "$bindir/../" && printf '%s\n' "$(pwd -P)")
exec_prefix=${prefix}
exec_prefix_set=no
libdir=${exec_prefix}/lib
#usage="\
#Usage: $0 [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs]"
usage="\
Usage: $0 [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs] [--static-libs]"
if test $# -eq 0; then
echo "${usage}" 1>&2
exit 1
fi
while test $# -gt 0; do
case "$1" in
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg= ;;
esac
case $1 in
--prefix=*)
prefix=$optarg
if test $exec_prefix_set = no ; then
exec_prefix=$optarg
fi
;;
--prefix)
echo $prefix
;;
--exec-prefix=*)
exec_prefix=$optarg
exec_prefix_set=yes
;;
--exec-prefix)
echo $exec_prefix
;;
--version)
echo 2.26.2
;;
--cflags)
echo -I${prefix}/include/SDL2 -D_REENTRANT
;;
--libs)
echo -L${exec_prefix}/lib -lSDL2
;;
--static-libs)
# --libs|--static-libs)
sdl_static_libs=$(echo " -lSDL2 -pthread -lm -lrt")
echo -L${exec_prefix}/lib $sdl_static_libs
;;
*)
echo "${usage}" 1>&2
exit 1
;;
esac
shift
done
see: https://github.com/libsdl-org/SDL/blob/SDL2/sdl2-config.in
It looks like the SDL2 build on these distros intentionaly removes static support with something like:
./configure --enable-static=false
The SmallBASIC configure script should be updated to detect this so it can fallback to a non-static build. The place for this is in function buildSDL()
.
Sorry, I don't log in to GitHub nearly as much as I should, as I do most of my dev work on GitLab. Awesome to see the workaround and fix being implemented! Thanks for your quick replies and attention to detail 😄
And yeah, Arch and similar distros follow a "statically link only when absolutely, totally necessary" and dynamically link everything by default. I guess that has bled into the way the tools work here as well!
I'll test that new commit on my system and see if it all goes well.
EDIT: Unfortunately still having the same issue. During the ./configure stage, I can see that it runs sdl2-config but sdl2-config returns an error message per the original comment.
config.log configure printed output
EDIT 2: Also tried editing sdl2-config per @Joe7M suggestion, but there doesn't appear to be a libSDL2.a in my /lib folder, only libSDL2main.a
and libSDL2_test.a
. Editing sdl2-config to include libSDL2main.a doesn't work, I still get a ton of undefined reference errors during linking.
Hey, did anyone ever find a solution to this? Editing the sdl2-config file didn't work for me either :(
I'm using Manjaro Linux and the fix provided by Chris works well. The SDL-version builds without problems.
A work around could be to force the configure script to use an additional library:
export PACKAGE_LIBS=-lSDL2
./configure --enable-sdl
The third last line of the configure output looks like this:
PACKAGE_LIBS=-static-libgcc -lSDL2 -ldl -no-pie -lfontconfig -lfreetype -lfreetype -lpcre
Without the export command, -lSDL2
should be missing.