【问题标题】:Manually link and compile C++ program with SFML (macOS)使用 SFML (macOS) 手动链接和编译 C++ 程序
【发布时间】:2021-09-10 17:27:06
【问题描述】:

我正在尝试使用 SFML 创建小型 C++ 程序,但我不想使用 Xcode 模板。 我正在使用 VSCode。

我为 Mac 下载了 SFML,并将标头和 dylib 复制到我的项目目录中,如下所示:

  • include/

  • lib/

main.cpp 看起来像这样:

#include "include/SFML/Graphics.hpp"
int main()
{
    return EXIT_SUCCESS;
}

我用来编译的命令(成功): g++ main.cpp -o main -I include -L lib -l sfml-graphics -l sfml-window -l sfml-system

在运行应用程序时出现以下错误:

dyld: Library not loaded: @rpath/libsfml-graphics.2.5.dylib
  Referenced from: /Users/mikal/code/cpp/sfml-box2d/./main
  Reason: image not found
zsh: abort      ./main

【问题讨论】:

    标签: c++ macos g++ sfml


    【解决方案1】:

    我需要通过添加这些链接器选项来告诉链接器在运行时在哪里查找动态库:

    -Wl,-rpath ./lib

    更多信息在这里: https://gcc.gnu.org/legacy-ml/gcc-help/2005-12/msg00017.html

    所以编译例如 hello SFML 代码的完整命令是: g++ main.cpp -o main -I include -L lib -l sfml-system -l sfml-window -l sfml-graphics -l sfml-audio -l sfml-network -Wl,-rpath ./lib

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-18
      • 2023-04-02
      • 2021-10-12
      • 2023-03-19
      • 2014-01-18
      相关资源
      最近更新 更多