SFML community forums

Help => Graphics => Topic started by: Garwin on August 05, 2023, 02:45:19 pm

Title: Error compiling with gcc++
Post by: Garwin on August 05, 2023, 02:45:19 pm
I use sf::CircleShape with SFML 2.6 and GCC 13.1.

So far till now I only build debug version and without errors. However for the first time I created release version and I get error. Do you have idea where can be problem?

`_ZThn8_N2sf11CircleShapeD1Ev' referenced in section `.rdata$_ZTVN2sf11CircleShapeE[_ZTVN2sf11CircleShapeE]' of C:\C++\_LIB\SFML-2.6.0\lib\libsfml-graphics-s.a(CircleShape.cpp.obj): defined in discarded section `.gnu.linkonce.t._ZN2sf11CircleShapeD1Ev[_ZThn8_N2sf11CircleShapeD1Ev]' of obj\Release\Voronoi\Voronoi.o (symbol from plugin)
collect2.exe: error: ld returned 1 exit status


info:
[ 33.3%] gcc.exe -std=c++20 -m64 -Wsign-conversion -std=c++23 -DSFML_STATIC -DTGUI_STATIC -fomit-frame-pointer -fexpensive-optimizations -flto -O3 -pedantic -Wextra -Wall -std=c++20 -m64 -DSFML_STATIC -IC:\C++\_LIB\SFML-2.6.0\include -IC:\C++\_LIB\TGUI-1.0\include -Iscr -Iscr\Voronoi -ITest -IVoronoi -c C:\C++\TEST\TEST_Voronoi_1\main.cpp -o obj\Release\main.o
[ 66.7%] gcc.exe -std=c++20 -m64 -Wsign-conversion -std=c++23 -DSFML_STATIC -DTGUI_STATIC -fomit-frame-pointer -fexpensive-optimizations -flto -O3 -pedantic -Wextra -Wall -std=c++20 -m64 -DSFML_STATIC -IC:\C++\_LIB\SFML-2.6.0\include -IC:\C++\_LIB\TGUI-1.0\include -Iscr -Iscr\Voronoi -ITest -IVoronoi -c C:\C++\TEST\TEST_Voronoi_1\Voronoi\Voronoi.cpp -o obj\Release\Voronoi\Voronoi.o
[100.0%] g++.exe -LC:\C++\_LIB\SFML-2.6.0\lib -LC:\C++\_LIB\TGUI-1.0\lib -o bin\Release\Voronoi.exe obj\Release\main.o obj\Release\Voronoi\Voronoi.o  -static-libstdc++ -static-libgcc -static -m64 -O3 -flto -s -static-libstdc++ -static-libgcc -static -m64 -lsfml-graphics-s -lsfml-window-s -lsfml-audio-s -lsfml-network-s -lsfml-system-s -lfreetype -lglu32 -lopengl32 -lopenal32 -logg -lflac -lvorbis -lvorbisfile -lvorbisenc -lgdi32 -lwinmm -lws2_32   -mwindows

note: TGUI is not needed now but I will use it later.
Title: Re: Error compiling with gcc++
Post by: Thrasher on August 06, 2023, 08:53:58 am
What OS are you using and what build commands did you run?
Title: Re: Error compiling with gcc++
Post by: Garwin on August 06, 2023, 09:03:48 am
Win11, using Codeblocks with gcc 13.1

Using Codeblocks project file.
What do you mean by builds command?

Project is set with these commands.
Release:
gcc.exe -std=c++20 -m64 -Wsign-conversion -std=c++23 -DSFML_STATIC -DTGUI_STATIC -fomit-frame-pointer -fexpensive-optimizations -flto -O3 -pedantic -Wextra -Wall -std=c++20 -m64 -DSFML_STATIC

Debug:
gcc.exe -std=c++20 -m64 -Wsign-conversion -std=c++23 -DSFML_STATIC -DTGUI_STATIC -Wnon-virtual-dtor -Wshadow -Winit-self -Wredundant-decls -Wcast-align -Wundef -Wfloat-equal -Wunreachable-code -Wmissing-declarations -Wswitch-enum -Wswitch-default -Wzero-as-null-pointer-constant -Wmain -pedantic-errors -pedantic -Wextra -Wall -std=c++20 -pg -m64 -Og -g
Title: Re: Error compiling with gcc++
Post by: Garwin on August 06, 2023, 11:14:40 am
I have tried new blank project in Codeblocks and with
#include <SFML/Grahpics/CircleShape.hpp>
and just declaring sf::CircleShape and there is no problem.

As soon as I put 2 new files into the project, there is a problem.

I have attached both files but I cannot see any issue with it.

There is not many usage of sf::CircleShape in the files:
Voronoi.hpp
using Circles = std::vector<sf::CircleShape>;
Circles inputPoints;
Circles vorPoints;
Circles newPoints;
void addPoints (const Points& inputPoints, Visualisation::Circles& outputPoints, const sf::Color& color);
 
Voronoi.cpp
sf::CircleShape point (s_circleRadius, s_circleRadius/4 + 6);
void VoronoiCut::addPoints (const Points& inputPoints, Visualisation::Circles& outputPoints, const sf::Color& color)
{ // .....
}
 

I have tried to replace sf::CircleShape and using sf::RectangleShape and get same error.
`_ZThn8_N2sf14RectangleShapeD1Ev' referenced in section `.rdata$_ZTVN2sf14RectangleShapeE[_ZTVN2sf14RectangleShapeE]' of C:\C++\_LIB\SFML-2.6.0\lib\libsfml-graphics-s.a(RectangleShape.cpp.obj): defined in discarded section `.gnu.linkonce.t._ZN2sf14RectangleShapeD1Ev[_ZThn8_N2sf14RectangleShapeD1Ev]' of obj\Release\Voronoi\Voronoi.o (symbol from plugin)
Title: Re: Error compiling with gcc++
Post by: Garwin on August 07, 2023, 07:42:43 pm
I have found what causes the problem in Codeblocks but do not know what is wrong with the wrong definitions.

This is how it looks working for release version ==> this works
Linker settings in release version:
(https://i.imgur.com/AN6usoU.png)
Other linker options in release version:
(https://i.imgur.com/UKWGeqO.png)
Variables in whole project:
(https://i.imgur.com/pbzqMdH.png)

This is how I would like to use it be more automatic:
Linker settings in release version: none
Other linker options in release version:
(https://i.imgur.com/73Zq3vF.png)
Variables in whole project:
(https://i.imgur.com/xcZi29h.png)

But for whatever reasons it just does not work and only for release version.

Has anybody any idea?

Title: Re: Error compiling with gcc++
Post by: Garwin on August 08, 2023, 05:48:03 pm
I find out that the issue is "-flto" link optimization with SFML.
But the reasons for this are completely unknown to me.
Title: Re: Error compiling with gcc++
Post by: eXpl0it3r on August 10, 2023, 10:56:49 am
If you use pre-built SFML or TGUI libraries, you have to make sure, that they match 100% with the compiler used to build those and the compiler you use.
See the links to the compiler used on the SFML download page.
Title: Re: Error compiling with gcc++
Post by: Garwin on August 10, 2023, 11:51:58 am
Thanks for the information. I use exactly the same version of MinGW and GCC that are described in the tutorial.

For time being I just switch off -flto.
Title: Re: Error compiling with gcc++
Post by: Garwin on December 09, 2023, 07:35:29 pm
I find what is doing the issue. But I do not understand why.
If somebody has any clue, it would be helpful.


Simple example code with MinGW 13.1 (version used by SFML) on Codeblocks - Windows 11.
#include <SFML/System/Vector2.hpp>
#include "SFML/Graphics.hpp"

#include <vector>

int main ()
{
    std::vector<sf::Vector2f> inputPoints;
    std::vector<sf::RectangleShape> circles;

    return 0;
}
 

As soon as I add this:
std::vector<sf::RectangleShape> circles;
I get the error:
error: ld returned 1 exit status
without any additional information.

So why just declaring vector of RectangleShape can cause such error.

But if I switch off "-flto" for gcc, it compiles without any issue.
Title: Re: Error compiling with gcc++
Post by: eXpl0it3r on December 11, 2023, 12:14:08 am
Sounds like an linker issue/bug. If it just silently crashes when using link time optimization (lto). If you don't get any information from the linker, there isn't really much I can help you with.
Try to see if there's some verbose option for the linker, so you see internal failures or whatever is happening.
Title: Re: Error compiling with gcc++
Post by: Garwin on December 11, 2023, 08:28:23 pm
I get more detailed error but so far do not know what to do with it ....

`_ZThn8_N2sf11CircleShapeD1Ev' referenced in section `.rdata$_ZTVN2sf11CircleShapeE[_ZTVN2sf11CircleShapeE]' of ...\_LIB\SFML-2.6.1\lib\libsfml-graphics-s.a(CircleShape.cpp.obj): defined in discarded section `.gnu.linkonce.t._ZN2sf11CircleShapeD1Ev[_ZThn8_N2sf11CircleShapeD1Ev]' of obj\Release\Test.o (symbol from plugin)
Title: Re: Error compiling with gcc++
Post by: eXpl0it3r on December 12, 2023, 12:22:20 am
Any specific reason you want LTO?

I can find a bunch of reports for ld with MinGW when searching for "mingw defined in discarded section". Maybe you can try some of the suggested work arounds to narrow it down further.
Title: Re: Error compiling with gcc++
Post by: Garwin on December 13, 2023, 07:08:43 pm
Not exactly. I used same setting from beginning finding that it optimalize functions calls between compilation units.
But I got this error with new version of SMFL, which is strange.

I disable it for time being but have not found anything useful on internet, usually some very old reports of gcc bugs, but it was about version gcc 4.