massung / r-cade

Retro Game Engine for Racket
https://r-cade.io
Other
273 stars 13 forks source link

Couldn't get "sfText_getLineSpacing" from "libcsfml-graphics.so" #5

Closed GrazHero closed 4 years ago

GrazHero commented 4 years ago

Hey there. I'm having trouble getting things working on Arch Linux. I'm running the latest version of Racket from the Arch repositories (7.5). I've followed the setup instructions from the r-cade site. raco pkg install r-cade as well as double checking that the racket csfml bindings are installed raco pkg install csfml as well as the other dependencies pacman -Sy csfml openal libsndfile

However, attempting to run the program

#lang racket 
(require r-cade)

restults in the following error

../../usr/share/racket/collects/racket/private/more-scheme.rkt:261:28: ffi-obj: couldn't get "sfText_getLineSpacing" from "libcsfml-graphics.so" (/usr/lib/libcsfml-graphics.so: undefined symbol: sfText_getLineSpacing)

Any idea what might be causing this? csfml is version 2.5 libsndfile is version 1.0.28 openal is version 1.20.1

massung commented 4 years ago

Hmm, given that sfText_getLineSpacing is pretty deep into the csfml code, it means the libraries are being found and loading everything else (at least to that point) properly.

My guess is that the Linux .so file either has a typo for the name or maybe it's a slightly older version of CSFML that doesn't have that function?

Are you able to run the following and see if it's there?

$ nm -gD /usr/lib/libcsfml-graphics.so | grep sfText_

If nm doesn't work, perhaps objdump -TC?

Also, are you able to confirm that you're using CSFML 2.5? I ask only because when I download the CSFML sources for 2.5, I see this in src/graphics/Text.cpp:

float sfText_getLineSpacing(const sfText* text)
{
    CSFML_CALL_RETURN(text, getLineSpacing(), 1);
}

But, when I look at the sources for 2.4, that function does not exist. If your installation installed sources, then try to find Config.h (e.g. /usr/local/include/csfml/Config.h?) and see what is defined for the version. Mine shows:

#define CSFML_VERSION_MAJOR 2
#define CSFML_VERSION_MINOR 5
#define CSFML_VERSION_PATCH 0
GrazHero commented 4 years ago

Output of nm -gD /usr/lib/libcsfml-graphics.so | grep sfText_:

000000000001ae60 T sfText_copy
000000000001ae00 T sfText_create
000000000001b340 T sfText_destroy
000000000001bc40 T sfText_findCharacterPos
000000000001bba0 T sfText_getCharacterSize
000000000001bc00 T sfText_getColor
000000000001bbe0 T sfText_getFillColor
000000000001bb90 T sfText_getFont
000000000001bc60 T sfText_getGlobalBounds
000000000001b690 T sfText_getInverseTransform
000000000001bbb0 T sfText_getLetterSpacing
000000000001bc50 T sfText_getLocalBounds
000000000001b530 T sfText_getOrigin
000000000001bc10 T sfText_getOutlineColor
000000000001bc30 T sfText_getOutlineThickness
000000000001b4c0 T sfText_getPosition
000000000001b4f0 T sfText_getRotation
000000000001b500 T sfText_getScale
000000000001b9c0 T sfText_getString
000000000001bbd0 T sfText_getStyle
000000000001b5d0 T sfText_getTransform
000000000001bb70 T sfText_getUnicodeString
000000000001b560 T sfText_move
000000000001b590 T sfText_rotate
000000000001b5a0 T sfText_scale
000000000001b880 T sfText_setCharacterSize
000000000001b930 T sfText_setColor
000000000001b8c0 T sfText_setFillColor
000000000001b860 T sfText_setFont
000000000001b8a0 T sfText_setLetterSpacing
000000000001b890 T sfText_setLineSpacing
000000000001b490 T sfText_setOrigin
000000000001b940 T sfText_setOutlineColor
000000000001b9b0 T sfText_setOutlineThickness
000000000001b420 T sfText_setPosition
000000000001b450 T sfText_setRotation
000000000001b460 T sfText_setScale
000000000001b750 T sfText_setString
000000000001b8b0 T sfText_setStyle
000000000001b7f0 T sfText_setUnicodeString

Very odd, It's missing. My package didn't come with sources, but Config.h does indeed say it's version 2.5. The sfText_getLineSpacing function declaration is also present in the Text.h. Just to confirm this symbol is supposed to exist, I compiled CSFML from the same sources ostensibly being used by the package, and indeed the sfText_getLineSpacing symbol is present. Clearly the package maintainer screwed up somehow. I'll report this problem to him. Thanks!

Perhaps it might be helpful to add a troubleshooting section to the documentation that mentions this?

massung commented 4 years ago

Good idea, and thank you for checking. I'll close this issue after I have a FAQ/troubleshooting section of the webpage in place.

massung commented 4 years ago

Okay, the website now has a FAQ/Troubleshooting section. Thanks for the idea!

wu-lee commented 4 years ago

I've just run into this on Ubuntu (Focal Fossa). That seems to package SFML 2.5.0, whereas this has been fixed in SFML 2.5.1 (although the CSFML version is 2.5 in both cases)

I've filed a bug on Launchpad for it:

https://bugs.launchpad.net/ubuntu/+source/libcsfml/+bug/1877632

In the mean time, here is a work-around. I'm partly posting here for my own records, but maybe it could help others. I've managed to re-package and install libcsfml for Ubuntu, using FPM (doing it by tweaking offical .deb src is surprisingly difficult I find).

Thanks also to Oleh Prypin who has published a guide to building libcsfml:

https://pryp.in/blog/12/build-sfml-and-csfml-on-linux.html

This script is only lightly tested, but sums up the process on my system. If it succeeds, you should then have a .deb package for libcsfml (or possibly another type, if you change the target), which you can install normally.

#!/bin/bash

# Turn on rudimentary fatal errors
set -e -o pipefail
# Show executed commands
set -x

# Check the tags defined here and set these accordingly
# https://github.com/SFML/SFML
# https://github.com/SFML/CSFML
SFML_TAG=2.5.1
CSFML_TAG=2.5

# From https://pryp.in/blog/12/build-sfml-and-csfml-on-linux.html
# With supplements for this script
sudo apt-get install \
     build-essential cmake git \
     libx11-dev freeglut3-dev libxcb-image0-dev \
     libudev-dev libjpeg8-dev libopenal-dev libsndfile1-dev libfreetype6-dev \
     libxrandr-dev \
     ruby

# Uses FPM to package the library
# https://github.com/jordansissel/fpm
command -v fpm || {
    export PATH="$(ruby -r rubygems -e 'puts Gem.user_dir')/bin:$PATH"
    command -v fpm || {
    gem install --user-install --no-document fpm
    }
}

# Get the source
rm -rf SFML CSFML
git clone -b $SFML_TAG --depth 1 https://github.com/SFML/SFML SFML
git clone -b $CSFML_TAG --depth 1 https://github.com/SFML/CSFML CSFML 

# Build in here
mkdir -p staging
( cd SFML
  cmake .
  make
  make install DESTDIR=$PWD/../staging )
( cd CSFML
  export SFML_DIR="$(realpath ../SFML)"
  cmake .
  make
  make install DESTDIR=$PWD/../staging )

# This does the packaging... 
#
# Note, `-t deb` outputs .deb, but FPM supports other packages too:
# https://fpm.readthedocs.io/en/latest/
#
# Note, to prevent this from overwriting previously created packages, remove the -f flag
# The exact details here may need to be tweaked for other distros/releases
fpm \
    -f \
    -s dir \
    -t deb \
    -n libcsfml \
    -v $SFML_TAG \
    -C staging \
    -p libcsfml_VERSION_ARCH.deb \
    -d  "libgl1-mesa-dev | libgl-dev" \
    -d "libglu1-mesa-dev | libglu-dev" \
    --conflicts libcsfml-system2.5 \
    --description 'C bindings for SFML, a cross platform multimedia library' \
    usr/local/include=/usr \
    usr/local/lib=/usr \
    usr/local/share=/usr