sf::Rect<float>::Rect<float>(void) already defined linker error

Started by kiwon0905, 28 November 2017, 06:17:36

kiwon0905

Test.h
Code (cpp) Select
#pragma once

struct Test
{
void test();
};


Test.cpp
Code (cpp) Select
#include "Test.h"
#include <SFML/Graphics.hpp>

void Test::test()
{
sf::FloatRect r;
}


main.cpp
Code (cpp) Select
#include <SFML/Graphics.hpp>
#include <TGUI/TGUI.hpp>
int main()
{
sf::FloatRect r;
return 0;
}


Hi I'm trying to compile the above code on Visual studio 2017 and I get "error LNK2005: "public: __thiscall sf::Rect<float>::Rect<float>(void)" (??0?$Rect@M@sf@@QAE@XZ) already defined in Test.obj"

The error is gone when I comment out the #include <TGUI/TGUI.hpp>
Is this a problem with TGUI?

texus

Since Rect is a template class, it shouldn't even be possible to have it defined twice, so the error makes little sense to me.
Since this is a linking error, could you try not linking to tgui? That will of course give a lot of undefined reference linking errors, but the question is whether this error remains or is gone. If the error disappears then maybe the SFML libraries you are using don't match the ones that were used to build TGUI.

Edit: The tgui::FloatRect class might be the reason why it can be defined twice (because it inherits from sf::Rect). I'm guessing you are linking dynamically? You could also try editing the TGUI/include/TGUI/FloatRect.hpp file and remove the TGUI_API on top (so change "class TGUI_API FloatRect" to "class FloatRect"). You don't have to recompile TGUI to test whether this worked, although I can't guarantee that you don't get other linking errors about this class if TGUI isn't recompiled.