Reputation: 1
I am getting this "symbol(s) not found in architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)." Actually, these messages didn't appear until I upgraded to macOS Mojave.
The complete message I got is:
g++ -Wall -fexceptions -g -c /Users/suraj/Desktop/sfm/main.cpp -o obj/Debug/main.o
g++ -o bin/Debug/sfm obj/Debug/main.o
Undefined symbols for architecture x86_64:
"sf::CircleShape::CircleShape(float, unsigned long)", referenced from:
_main in main.o
"sf::RenderStates::Default", referenced from:
_main in main.o
"sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)",
referenced from:
_main in main.o
"sf::RenderTarget::clear(sf::Color const&)", referenced from:
_main in main.o
"sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&,
unsigned int, sf::ContextSettings const&)", referenced from:
_main in main.o
"sf::RenderWindow::~RenderWindow()", referenced from:
_main in main.o
"sf::Color::Green", referenced from:
_main in main.o
"sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned
char)", referenced from:
_main in main.o
"sf::Shape::setFillColor(sf::Color const&)", referenced from:
_main in main.o
"sf::Shape::~Shape()", referenced from:
sf::CircleShape::~CircleShape() in main.o
"sf::String::String(char const*, std::__1::locale const&)", referenced
from:
_main in main.o
"sf::Window::close()", referenced from:
_main in main.o
"sf::Window::display()", referenced from:
_main in main.o
"sf::Window::pollEvent(sf::Event&)", referenced from:
_main in main.o
"sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)",
referenced from:
_main in main.o
"sf::Window::isOpen() const", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The code is:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(400, 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;
}
Please help.
Upvotes: 0
Views: 3325
Reputation: 207335
Updated Answer - May 2019
It seems that the openal
package is no longer in homebrew and that causes the instructions below to fail. I don't know the background behind it. Here is another approach.
You can find all the pkg-config
related parts of sfml
like this:
find /usr/local/Cellar/sfml -name \*pc
/usr/local/Cellar/sfml/2.5.1/lib/pkgconfig/sfml-network.pc
/usr/local/Cellar/sfml/2.5.1/lib/pkgconfig/sfml-all.pc
/usr/local/Cellar/sfml/2.5.1/lib/pkgconfig/sfml-graphics.pc
/usr/local/Cellar/sfml/2.5.1/lib/pkgconfig/sfml-audio.pc
/usr/local/Cellar/sfml/2.5.1/lib/pkgconfig/sfml-system.pc
/usr/local/Cellar/sfml/2.5.1/lib/pkgconfig/sfml-window.pc
It seems you cannot use sfml-all
nor sfml-audio
in the above list, so you will need to pick which parts you want to use and grab them individually, so if you want graphics
, window
and system
:
pkg-config --libs --cflags sfml-graphics
-I/usr/local/Cellar/sfml/2.5.1/include
-I/usr/local/opt/freetype/include/freetype2
-I/usr/local/Cellar/sfml/2.5.1/include
-L/usr/local/Cellar/sfml/2.5.1/lib -lsfml-graphics -lsfml-window -lsfml-system
pkg-config --libs --cflags sfml-system
-I/usr/local/Cellar/sfml/2.5.1/include
-L/usr/local/Cellar/sfml/2.5.1/lib -lsfml-system
pkg-config --libs --cflags sfml-window
-I/usr/local/Cellar/sfml/2.5.1/include
-L/usr/local/Cellar/sfml/2.5.1/lib -lsfml-window -lsfml-system
So, you would compile with:
g++ main.cpp $(pkg-config --libs --cflags sfml-window sfml-system sfml-graphics) -o main
Original Answer
If you installed sfml via homebrew, I would suggest you also install pkg-config
like this:
brew install pkg-config
Then you can get the switches needed to compile with:
pkg-config --libs --cflags sfml-all
Sample Output
-I/usr/local/Cellar/sfml/2.4.2_1/include -L/usr/local/Cellar/sfml/2.4.2_1/lib -lsfml-graphics -lsfml-window -lsfml-audio -lsfml-network -lsfml-system
So you can compile with:
g++ main.cpp $(pkg-config --libs --cflags sfml-all) -o main
Upvotes: 2