Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Linking static SFML with Premake & MingW drives me nuts  (Read 1561 times)

0 Members and 1 Guest are viewing this topic.

MarbleXeno

  • Guest
Linking static SFML with Premake & MingW drives me nuts
« on: March 12, 2022, 10:39:13 pm »
Some background:
For more than 2 hours im sitting in front of my desk trying to resolve this stupid thing. It literally drives me nuts as I'm literally crying while banging my head against the keyboard in hope that it helps. Please, help me...

I want to link SFML libs into "FarfocelEngine" (a static library in itself) and then link "FarfocelEngine" into my final application project "Sandbox".
I thought that it would be easy and I still think that it is, yet somehow I can't properly link SFML using Premake.
As you can see I'm trying to develop (or rather port, since I have a good chunk of it done but in Visual Studio) a small SFML engine.

The problem is that when I compile it via mingw32-make it throws these errors:
"==== Building FarfocelEngine (release) ===="
"==== Building Sandbox (release) ===="
Linking Sandbox
bin-obj/Release/Sandbox.o:Sandbox.cpp:(.text.startup+0x7d): undefined reference to `sf::String::String(char const*, std::locale const&)'
bin-obj/Release/Sandbox.o:Sandbox.cpp:(.text.startup+0x9b): undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
bin-obj/Release/Sandbox.o:Sandbox.cpp:(.text.startup+0xd5): undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
bin-obj/Release/Sandbox.o:Sandbox.cpp:(.text.startup+0x10a): undefined reference to `sf::CircleShape::CircleShape(float, unsigned long long)'
bin-obj/Release/Sandbox.o:Sandbox.cpp:(.text.startup+0x119): undefined reference to `sf::Shape::setFillColor(sf::Color const&)'
bin-obj/Release/Sandbox.o:Sandbox.cpp:(.text.startup+0x134): undefined reference to `sf::Window::isOpen() const'
bin-obj/Release/Sandbox.o:Sandbox.cpp:(.text.startup+0x14f): undefined reference to `sf::Window::pollEvent(sf::Event&)'
bin-obj/Release/Sandbox.o:Sandbox.cpp:(.text.startup+0x16b): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
bin-obj/Release/Sandbox.o:Sandbox.cpp:(.text.startup+0x176): undefined reference to `sf::RenderTarget::clear(sf::Color const&)'
bin-obj/Release/Sandbox.o:Sandbox.cpp:(.text.startup+0x184): undefined reference to `sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'
bin-obj/Release/Sandbox.o:Sandbox.cpp:(.text.startup+0x18c): undefined reference to `sf::Window::display()'
bin-obj/Release/Sandbox.o:Sandbox.cpp:(.text.startup+0x196): undefined reference to `sf::Window::close()'
bin-obj/Release/Sandbox.o:Sandbox.cpp:(.text.startup+0x1bf): undefined reference to `sf::Shape::~Shape()'
bin-obj/Release/Sandbox.o:Sandbox.cpp:(.text.startup+0x1c7): undefined reference to `sf::RenderWindow::~RenderWindow()'
bin-obj/Release/Sandbox.o:Sandbox.cpp:(.text.startup+0x216): undefined reference to `sf::Shape::~Shape()'
bin-obj/Release/Sandbox.o:Sandbox.cpp:(.text.startup+0x21e): undefined reference to `sf::RenderWindow::~RenderWindow()'
bin-obj/Release/Sandbox.o:Sandbox.cpp:(.rdata$.refptr._ZTVN2sf11CircleShapeE[.refptr._ZTVN2sf11CircleShapeE]+0x0): undefined reference to `vtable for sf::CircleShape'
bin-obj/Release/Sandbox.o:Sandbox.cpp:(.rdata$.refptr._ZN2sf12RenderStates7DefaultE[.refptr._ZN2sf12RenderStates7DefaultE]+0x0): undefined reference to `sf::RenderStates::Default'
bin-obj/Release/Sandbox.o:Sandbox.cpp:(.rdata$.refptr._ZN2sf5Color5GreenE[.refptr._ZN2sf5Color5GreenE]+0x0): undefined reference to `sf::Color::Green'
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [Makefile:65: bin/Release/Sandbox.exe] Error 1
mingw32-make: *** [Makefile:34: Sandbox] Error 2
 

My project structure looks like this:
https://imgur.com/a/wi25pmw

My FarfocelEngine premake5.lua:
(click to show/hide)

My Sandbox premake5.lua:
(click to show/hide)

My root's directory premake5.lua:
(click to show/hide)

Farfocel.cpp and Farfocel.hpp files are empty.

My Sandbox.cpp file:
(click to show/hide)

It's worth noting that I compiled the SFML library myself, from the source code.
Here are the CMake settings:
https://imgur.com/a/ZjFkBVc

After successful compilation I copied include (from the source code directory) and lib (from the CMAKE_INSTALL_PREFIX directory) folders and pasted them into my project's SFML directory.

I have similar project set up and working but using the Visual Studio compiled SFML libs and it doesn't work when using MingW, hence I'm trying to port it and use Mingw.

EDIT: I use Windows 11, so maybe that's the problem?
« Last Edit: March 12, 2022, 11:06:12 pm by MarbleXeno »

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: Linking static SFML with Premake & MingW drives me nuts
« Reply #1 on: March 12, 2022, 11:55:14 pm »
From what I've read here: https://github.com/premake/premake-core/issues/627
the issue is Premake doesn't carry over dependencies for static libraries.
FarfocelEngine is linking with sfml, but since both are static it isn't actually merging them there. When Sandbox is linked with FarfocelEngine, the sfml parts are missing.

This works in Visual Studio because it explicitly fixes this, but MingW is just doing what it's told.

So you'd need to link Sandbox with all of FarfocelEngine's dependencies too.

At least that's how it looks, been a while since I used premake, static sfml or anything other than visual studio.

MarbleXeno

  • Guest
Re: Linking static SFML with Premake & MingW drives me nuts
« Reply #2 on: March 13, 2022, 12:18:43 am »
Thank you isn't really enough to express how grateful I'm right now! Thank you very much, you made my day.
Yes, that was the problem. I have no idea why I didn't tried doing it this way before. Also, I fixed some smaller errors in my premakes, now they work. Thanks!