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/wi25pmwMy FarfocelEngine premake5.lua:
project "FarfocelEngine"
kind "StaticLib"
language "C++"
cppdialect "C++17"
staticruntime "on"
targetdir ("bin/%{cfg.buildcfg}")
objdir ("bin-obj/%{cfg.buildcfg}")
files
{
"src/**.hpp",
"src/**.cpp"
}
includedirs
{
"../SFML/include"
}
defines
{
"SFML_STATIC"
}
libdirs
{
"../SFML/lib"
}
links
{
-- perhaps i don't include all the libs correctly or some libs are simply missing??
"opengl32",
"openal32",
"freetype",
"winmm",
"gdi32",
"flac",
"vorbisenc",
"vorbisfile",
"vorbis",
"ogg",
"ws2_32",
"sfml-graphics-s",
"sfml-window-s",
"sfml-system-s",
"sfml-audio-s"
}
filter "configurations:Debug"
defines {"DEBUG"}
defines "FR_DEBUG"
symbols "On"
filter "configurations:Release"
defines {"NDEBUG"}
defines "FR_RELEASE"
optimize "On"
My Sandbox premake5.lua:
project "Sandbox"
kind "ConsoleApp"
language "C++"
cppdialect "C++17"
targetdir ("bin/%{cfg.buildcfg}")
objdir ("bin-obj/%{cfg.buildcfg}")
files
{
"src/**.hpp",
"src/**.cpp"
}
includedirs
{
"../FarfocelEngine/src",
"../SFML/include"
}
links
{
"FarfocelEngine"
}
filter "configurations:Debug"
defines {"DEBUG"}
defines "FR_DEBUG"
symbols "on"
filter "configurations:Release"
defines {"NDEBUG"}
defines "FR_RELEASE"
optimize "on"
My root's directory premake5.lua:
workspace "Farfocel Application"
startproject "Sandbox"
architecture "x64"
configurations
{
"Release"
}
filter{"platforms:Win64"}
system "Windows"
include "FarfocelEngine"
include "Sandbox"
Farfocel.cpp and Farfocel.hpp files are empty.
My Sandbox.cpp file:
#include "Farfocel.hpp"
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
It's worth noting that I compiled the SFML library myself, from the source code.
Here are the CMake settings:
https://imgur.com/a/ZjFkBVcAfter 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?