Apple Mach-O 链接器 (id) 错误 - 链接器命令失败,退出代码为 1(使用 -v 查看调用)C++ SFML

Apple Mach-O Linker (id) Error - Linker command failed with exit code 1 (use -v to see invocation) C++ SFML

好的,所以我首先尝试检查其他解决方案,但其中 none 有效,是的......有两个错误,即使我直接按照文档中的代码进行操作。我认为这可能是文件的问题,但我认为不会,因为文件都是 .hpp 除非他们 bad.I 是新手所以这可能是我错过的愚蠢的事情。

#include <iostream>
#include <SFML/Graphics.hpp>
int main()
{
    // create the window
    sf::RenderWindow window(sf::VideoMode(800, 600), "My window");

    // run the program as long as the window is open
    while (window.isOpen())
    {
        // check all the window's events that were triggered since the last iteration of the loop
        sf::Event event;
        while (window.pollEvent(event))
        {
            // "close requested" event: we close the window
            if (event.type == sf::Event::Closed)
                window.close();
        }

        // clear the window with black color
        window.clear(sf::Color::Black);

        // draw everything here...
        // window.draw(...);

        // end the current frame
        window.display();
    }

    return 0;
}

语法没有错误,一定是某种库错误。

更新找到答案。仍在回答和提问以帮助其他人,以防他们 运行 遇到我遇到的同样问题,因为堆栈溢出的所有解决方案并不是针对这个特定问题的真正解决方案

好的,问题不在你的语法中,因为它完全没问题。问题是您可能忘记为 sfml 添加系统文件,这就是它不起作用的原因。添加您需要的所有库,包括用于 sfml 的系统库。 该文件应类似于

libsfml-system.2.4.2.dylib

你需要它,否则它不会工作。确保你添加了那个和你需要的其他文件然后它应该工作(它确实如此。这是 OP 顺便说一句。)。