Add SFML (third party library) to C++ project on Xcode

  c++, sfml, xcode

I’m learning how to build a simple UI in C++ on my Mac (OS 11.6) using Xcode.
As first step I’m compiling the "Hello world" program, my problem is that the build on Xcode fails but write my own command from terminal, instead, works.

This is the program, I’m using SFML :

#include <iostream>
#include "SFML/Graphics.hpp"

int main(int argc, const char * argv[]) {
    // insert code here...
    std::cout << "Hello, World!n";
    return 0;
}

I have no error here but when launching Run from Xcode this is the output, in Graphics.hpp file :

#include <SFML/Window.hpp>.  //'SFML/Window.hpp' file not found
#include <SFML/Graphics/BlendMode.hpp>
#include <SFML/Graphics/CircleShape.hpp
//other header files

This is how the project is structured ("TestGui" is the project name) :

-TestGui.xcodeproj
-TestGui(folder)
--SFML(directory with all headers file available
-- main.cpp

SFML source code here

So I tried to compile it with my own hands from terminal with :

g++ main.cpp -I ./SFML -o main

and

clang++ main.cpp -I ./SFML -o main 

In both cases it compiled, also run worked.

Since the error is linked to a file not found I tried to tell it where libraries are located, so in Xcode from Product->Scheme->Edit Scheme->Run->Arguments->Arguments passed on launch : added -I ./SFML. But the error is still alive.

Added SFML folder to targets from Xcode, didn’t copy-pasted but maybe I did it wrong, this is my first time.

EDIT : SFML folder:

--SFML
--- many .hpp files
--- 5 folders (Audio, Graphic, Network, System and Window)

I tried to add also this argument : -L ./SFML but nothing.

Source: Windows Questions C++

LEAVE A COMMENT