简体   繁体   English

“架构 arm64 的未定义符号”使用 g++-12 在 M1 mac 上构建基本 SFML 项目

[英]"Undefined symbols for architecture arm64" building basic SFML project on M1 mac with g++-12

i've been having some trouble trying to compile a very basic SFML project on an M1 mac.我在尝试在 M1 mac 上编译一个非常基本的 SFML 项目时遇到了一些麻烦。 the exact error i've been getting is as follows:我得到的确切错误如下:

Undefined symbols for architecture arm64: "__ZN2sf6StringC1EPKcRKSt6locale", referenced from: _main in cczblZnn.o ld: symbol(s) not found for architecture arm64 collect2: error: ld returned 1 exit status架构 arm64 的未定义符号:“__ZN2sf6StringC1EPKcRKSt6locale”,引用自:cczblZnn.o 中的 _main ld:未找到架构 arm64 collect2 的符号:错误:ld 返回 1 退出状态

when running跑步时

g++-12 -std=c++20 src/main.cpp -I/Users/rooster/SFML/include -o Ghost -L/Users/rooster/SFML/build/lib -lsfml-audio -lsfml-network -lsfml-graphics -lsfml-window -lsfml-system

so far, nothing i've tried has worked;到目前为止,我尝试过的任何方法都没有奏效; i've already compiled the libs myself from the source using cmake, i've rearranged the order of the libraries in the build command, among other seemingly inconsequential tweaks in VSCode.我已经使用 cmake 从源代码自己编译了这些库,我在构建命令中重新排列了库的顺序,以及 VSCode 中其他看似无关紧要的调整。

here's what i'm using:这是我正在使用的:

  • VSCode VSCode
  • g++-12 g++-12
  • library files compiled by me with cmake (using unix makefiles)我用 cmake 编译的库文件(使用 unix 生成文件)
  • c++20 c++20
  • SFML 2.5.1_2 SFML 2.5.1_2

and here's my main.cpp:这是我的 main.cpp:

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(sf::Vector2u(200, 200)), "SFML");
    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;
}

i'm relatively confident that i'm making some simple mistake.我相对有信心我犯了一些简单的错误。 any help is greatly appreciated, and thank you for your time!!非常感谢任何帮助,感谢您的宝贵时间!!

fixed by scrubbing all references to SFML from my computer, installing it again with brew, and then using clang++ instead of compiling with g++:)通过从我的计算机中清除所有对 SFML 的引用,使用 brew 再次安装它,然后使用 clang++ 而不是使用 g++ 编译来修复 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM