Linking a third party library using GNU

My question is, how do I link a third party library with my project using g++?

The specific library I'm trying to use is SFML.

I've seen countless of tutorials on how to do this using an IDE, but I'm solely using notepad++. I have the package containing SFML's object code, header files, etc. I've tried using -L and -I in compilation to direct the compiler to the object code and inclusions respectively, but no luck.
What are the error messages that you get when you run g++?
C:\Users\thmir\OneDrive\Desktop>
Command I'm running: g++ -o main main.cpp -lstdc++ -LSMFL-2.5.1/lib -ISFML-2.5.1/include/SFML -Wall

Error:
main.cpp:1:27: fatal error: SFML/System.hpp: No such file or directory
#include "SFML/System.hpp"

Here is the copy pasted directory of System.hpp: C:\Users\thmir\OneDrive\Desktop\SFML-2.5.1\include\SFML
you can set up another env variable like your 'path' variable but with these folders, and the name of the variable is CPATH . g++ should see it.
or on the command line I think you want 'I' and path whihc looks like what you have tried already. Have you tried the 'I' with WINDOWS looking paths, like -IC:\foo\ ? the slash format... maybe I am confusing myself again.. is /folder only ok for a subfolder of current location?
Regardless .. I suspect fully qualified win paths will work, and I suspect you have a subtle error in your paths is the issue, so either fully qualify, use the env var, or try to fix the issue ( I just don't see it tonight) ... one of those should get you rolling
Last edited on
Is your main.cpp on the Desktop?
First, you have a typo: -LSMFL-2.5.1/lib

But that's the linker settings. The second problem is that it can't find the header folder.

Instead of
#include "SFML/System.hpp"
do
#include <SFML/System.hpp>

Third, since the "SFML" is part of your individual #include, don't put "SFML" in the compiler flag. Just make it be -ISFML-2.5.1/include

If those three things don't work, try using a global path instead. So instead of -ISFML-2.5.1/include/SFML try -IC:/Users/thmir/OneDrive/Desktop/SFML-2.5.1/include

For brevity, I usually have a folder like C:\libraries that I put all my third-party libraries in instead of cluttering the Desktop with it.
Last edited on
Thank you.

Following everyone's advice, I eventually got it to work using this command:

g++ -o main main.cpp -Wall -ISFML-2.5.1/include -LSFML-2.5.1/lib -lsfml-graphics -lsfml-system
Topic archived. No new replies allowed.