SFML community forums

Help => General => Topic started by: bokoblin on January 25, 2017, 07:30:50 pm

Title: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: bokoblin on January 25, 2017, 07:30:50 pm
Hello,

I'm trying for some time to draw french text with sf::Text.
This works using setString(L"français");
But it obviously can't work with text contained in variable/parsed from elsewhere
because you can't do
string test = "français";
setString(Ltest); or setString(L\"test\"); or setString(test); (the latter returns strange characters)

I just tried using sf::String but while the official tuto says I can draw this because it is inherited from sf::Drawable, my compiler says that sf::String is not compatible with class sf::Drawable.

So what can I do to draw UTF-8 parsed text ?


I'm on Windows 10 with SFML 2.3.2 on CLion IDE
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: Laurent on January 25, 2017, 08:48:58 pm
std::string utf8_string = <extracted from file>;

sf::Text text;
text.setString(sf::String::fromUtf8(utf8_string.begin(), utf8_string.end()));
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: bokoblin on January 25, 2017, 10:23:34 pm
Merci, ça fonctionne, je commençais à désespérer de trouver une solution !
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: Laurent on January 26, 2017, 06:29:51 am
In english please :P
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: bokoblin on February 02, 2017, 03:49:33 pm
I know, but it was because you are french ^^

Anyway, It works great on Windows, but when I try compiling my project on linux I have the following error :

In member function ‘virtual void Button::sync(DataBase*)’:
158:27: error: ‘fromUtf8’ is not a member of ‘sf::String’
m_label.setString(sf::String::fromUtf8(utf8_string.begin(), utf8_string.end()));
make[2]: *** [CMakeFiles/runner.dir/src/view/Button.cpp.o]
Erreur 1
make[1]: *** [CMakeFiles/runner.dir/all] Erreur 2
make: *** [all] Erreur 2

I'm using SFML 2.3.2, located in <project directory>/libs/SFML-2.3.2
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: Laurent on February 02, 2017, 06:50:10 pm
You must include a old header, sf::String::fromUtf8 was added in SFML 2.2.
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: bokoblin on February 02, 2017, 06:57:07 pm
What do you mean by including an old header ? I tried
#include <SFML/System/String.hpp> because it is in this header where fromUtf8 is, but it doesn't work
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: Laurent on February 02, 2017, 07:05:14 pm
What I say is that the version of <SFML/System/String.hpp> that gets included in your code (which is often not the one we expect) is older than SFML 2.2. Make sure that your version is up-to-date, and that you don't have other older versions of SFML installed elsewhere.
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: bokoblin on February 02, 2017, 07:27:08 pm
I had indeed an old version on my system. I understood "you must" as what I should do
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: bokoblin on February 02, 2017, 09:05:24 pm
Cmake is working by replacing :
FIND_PACKAGE(SFML 2 COMPONENTS system window graphics audio REQUIRED )
by
FIND_PACKAGE(SFML 2.3 COMPONENTS system window graphics audio REQUIRED )

but "make" have undefined references for sf::color and sf::renderstate only

here is attached the command that make executes for linking into an executable
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: eXpl0it3r on February 02, 2017, 10:18:28 pm
The order of the libraries to link is wrong.

FIND_PACKAGE(SFML 2.3 COMPONENTS audio graphics window system REQUIRED )
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: bokoblin on February 02, 2017, 10:27:43 pm
Hello, thanks but same issue with your proposition :/ I did thought about it this afternoon (and had forgotten it just after, though)
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: eXpl0it3r on February 02, 2017, 10:31:53 pm
Make sure you do clean CMake's cache and run CMake again.
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: bokoblin on February 02, 2017, 10:40:31 pm
Yes it's what I do each time by deleting build folder, just checked again and it fails at "linking CXX executable"
Title: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: eXpl0it3r on February 03, 2017, 01:01:57 am
So what's the exact error message?
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: bokoblin on February 03, 2017, 08:13:22 am
So what's the exact error message?

Here is the log of command make
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: Laurent on February 03, 2017, 08:33:58 am
Can you show the verbose log ("export VERBOSE=1" in console before running make)?
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: bokoblin on February 03, 2017, 08:51:09 am
Can you show the verbose log ("export VERBOSE=1" in console before running make)?
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: bokoblin on February 04, 2017, 03:47:53 pm
Hello,


You want more files or the github repo to understand my issue on linux ?
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: Laurent on February 04, 2017, 04:11:41 pm
On Linux, .a libraries are static libraries. And if you linke SFML statically, you must define the SFML_STATIC preprocessor symbol.
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: bokoblin on February 04, 2017, 04:18:02 pm
On Linux, .a libraries are static libraries. And if you linke SFML statically, you must define the SFML_STATIC preprocessor symbol.

Well I'm defining SFML like this (linked CMakeList.txt),
with this hierarchy :
PROJECT FOLDER > libs > SFML-2.3.2 > include (with the .hpp and .inl) && lib (with  .a/ -d.a / -s.a files ).

I'm not defining them static (I checked with SFML_STATIC_LIBRARIES and it was false)
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: Laurent on February 04, 2017, 05:00:10 pm
Where did you get these .a files anyway? The Linux release only contains dynamic libraries (.so files).
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: bokoblin on February 04, 2017, 05:02:32 pm
Where did you get these .a files anyway? The Linux release only contains dynamic libraries (.so files).

I mainly develop on Windows, so I installed SFML for CodeBlocks on Windows a year ago,
in the meantime I worked at University with QT Creator and Qmake and its .pro file.
But since October, I work with CLion on Windows which works with Cmake. Currently, I have to use Travis-CI for another project for school, so I'm trying to make this SFML project benefits from Travis-CI by compiling it with just "cmake .. && make".
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: Laurent on February 05, 2017, 09:48:22 am
Quote
[... lot of irrelevant stuff ...] compiling it with just "cmake .. && make"
;D
Ok, this is not enough to figure out how SFML is really compiled. Can you please give the full set of CMake options that you use when you configure the build?
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: bokoblin on February 05, 2017, 11:24:03 am
Quote
[... lot of irrelevant stuff ...] compiling it with just "cmake .. && make"
;D
Ok, this is not enough to figure out how SFML is really compiled. Can you please give the full set of CMake options that you use when you configure the build?

"[... lot of irrelevant stuff ...] " lol
I just do :
mkdir build
cd build
cmake ..
make

The only " full set of CMake options..." are in the CMakeList.txt that is in attachment at reply #20,
I do these command on Ubuntu 14.04  (I know that there are options to add after cmake, but my teacher did only "cmake .." the other day -- that wasn't a SFML project, though)
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: Laurent on February 05, 2017, 01:33:43 pm
Default configuration (ie. just "cmake" without arguments) should produce the same build as official SFML releases, so I still don't understand how you got these .a files.

Can you show the verbose log of compiling SFML?
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: bokoblin on February 05, 2017, 01:43:26 pm
Default configuration (ie. just "cmake" without arguments) whouls produce the same build as official SFML releases, so I still don't understand how you got these .a files.

Can you show the verbose log of compiling SFML?

The .a are already there, I had downloaded a zip, sometime ago, where  there were already .hpp, .inl, .a (-s / -d) in it. Here is the log for cmake and make commands
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: Laurent on February 05, 2017, 02:53:36 pm
Quote
The .a are already there, I had downloaded a zip, sometime ago
Why didn't you say that the first time I asked? ...
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: bokoblin on February 05, 2017, 03:02:49 pm
Quote
The .a are already there, I had downloaded a zip, sometime ago
Why didn't you say that the first time I asked? ...

I thought you understood at reply#20 when I indicated that sfml .a are in libs/ (library folder) and not in build/ (compilation folder), sorry.


Ok, I understood concerning the .so and .a, so what I just did is getting the GCCx64 release of SFML 2.3.2 on your site, and I put all the .so/.so2.3/.so2.3.2 in my folder PROJECT FOLDER > libs > SFML-2.3.2 > lib.

Now there is only one error (no more undefined ref) :
PROJECT FOLDER/libs/SFML-2.3.2/lib/libsfml-audio.so :
fichier non reconnu : Fichier tronqué
collect2: error: ld returned 1 exit status
make[2]: *** [runner] Erreur 1
make[1]: *** [CMakeFiles/runner.dir/all] Erreur 2
make: *** [all] Erreur 2

I know I shouldn't take the 3 : .so / .so2.3 / .so2.3.2 but I don't know which one(s) I should take only.

Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: bokoblin on February 05, 2017, 03:54:10 pm
I replaced the file using "tar -xzf" instead of unzipping it with z-zip.
I had libxcb-image0 missing, I downloaded it via apt-get and now I have the following error :

../libs/SFML-2.3.2/lib/libsfml-audio.so : référence indéfinie vers « std::__throw_out_of_range_fmt(char const*, ...)@GLIBCXX_3.4.20 »
collect2: error: ld returned 1 exit status
make[2]: *** [runner] Erreur 1
make[1]: *** [CMakeFiles/runner.dir/all] Erreur 2
make: *** [all] Erreur 2
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: bokoblin on February 05, 2017, 07:42:43 pm
I replaced the file using "tar -xzf" instead of unzipping it with z-zip.
I had libxcb-image0 missing, I downloaded it via apt-get and now I have the following error :

../libs/SFML-2.3.2/lib/libsfml-audio.so : référence indéfinie vers « std::__throw_out_of_range_fmt(char const*, ...)@GLIBCXX_3.4.20 »
collect2: error: ld returned 1 exit status
make[2]: *** [runner] Erreur 1
make[1]: *** [CMakeFiles/runner.dir/all] Erreur 2
make: *** [all] Erreur 2

I fixed this last issue by updating from gcc-4.8 to gcc-4.9. Compilation succeeded in local  ;D

Still,  I have to fix travis-ci having undefined ref with "udev" (installed udev0 but it needs udev1 that doesn't exist)
Title: Re: Drawing UTF-8 string extracted from variable/xml with sf::Text
Post by: bokoblin on February 05, 2017, 09:32:42 pm
The issue in Travis-ci comes from SFML which needs libudev.so1 whereas apt-get can only install libudev.so0. I tried symlinking it but it doesn't work. Here is the message :

/usr/bin/ld: warning: libudev.so.1, needed by ../libs/SFML-2.3.2/lib/libsfml-window.so, not found (try using -rpath or -rpath-link)
../libs/SFML-2.3.2/lib/libsfml-window.so: undefined reference to `udev_device_get_action@LIBUDEV_183'
../libs/SFML-2.3.2/lib/libsfml-window.so: undefined reference to `udev_list_entry_get_next@LIBUDEV_183'
[...]
collect2: error: ld returned 1 exit status
make[2]: *** [runner] Error 1
make[1]: *** [CMakeFiles/runner.dir/all] Error 2
make: *** [all] Error 2