我收到此消息“在体系结构 x86_64 clang 中找不到符号:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)。”实际上,这些消息直到我升级到 macOS Mojave 后才出现。
我得到的完整消息是:
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)
代码是:
#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;
}
请帮忙。
最佳答案
更新答案 - 2019 年 5 月
openal
包似乎不再位于 homebrew 中,这导致下面的说明失败。我不知道这背后的背景。这是另一种方法。
您可以像这样找到 sfml
的所有 pkg-config
相关部分:
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
在上面的列表中,你似乎不能使用 sfml-all
或 sfml-audio
,所以你需要选择你想使用的部分并单独获取它们, 所以如果你想要 graphics
, window
和 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
因此,您将编译:
g++ main.cpp $(pkg-config --libs --cflags sfml-window sfml-system sfml-graphics) -o main
原始答案
如果您通过homebrew 安装了sfml,我建议您也像这样安装pkg-config
:
brew install pkg-config
然后您可以获得编译所需的开关:
pkg-config --libs --cflags sfml-all
示例输出
-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
所以你可以编译:
g++ main.cpp $(pkg-config --libs --cflags sfml-all) -o main
关于c++ - 在架构 x86_64 clang : error: linker command failed with exit code 1 (use -v to see invocation) 中找不到符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53510303/