【问题标题】:Linkers: file was built for archive which is not the architecture being linked (x86_64) GLFW链接器:文件是为存档而构建的,它不是被链接的架构 (x86_64) GLFW
【发布时间】:2021-09-19 20:59:46
【问题描述】:

你好,这个问题让我发疯了,我需要你的帮助。 我在 IOS High Sierra v10.13.6 上,我正在尝试在没有 XCode 的 mac 上的 VSC 上尝试 OpenGL。 所以我已经为正确的操作系统下载了库 GLFW。 我已经尝试了GLWF website 中的基本示例。

#include "../GLFW/glfw3.h"
// g++ -v main.cpp -o main.o -L/Library/Developer/CommandLineTools/usr/include -lglfw3 -framework OpenGL
// file was built for archive which is not the architecture being linked (x86_64):
int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */
        glClear(GL_COLOR_BUFFER_BIT);

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

我有以下目录:

当我执行这个命令时:

g++ -v main.cpp -o main.o -L/Library/Developer/CommandLineTools/usr/include -lglfw3 -framework OpenGL

我在终端出现以下错误:

Undefined symbols for architecture x86_64:
  "_glfwCreateWindow", referenced from:
      _main in main-ca9141.o
  "_glfwInit", referenced from:
      _main in main-ca9141.o
  "_glfwMakeContextCurrent", referenced from:
      _main in main-ca9141.o
  "_glfwPollEvents", referenced from:
      _main in main-ca9141.o
  "_glfwSwapBuffers", referenced from:
      _main in main-ca9141.o
  "_glfwTerminate", referenced from:
      _main in main-ca9141.o
  "_glfwWindowShouldClose", referenced from:
      _main in main-ca9141.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我知道我来自这个警告:

ld: warning: ignoring file /Library/Developer/CommandLineTools/usr/include/libglfw3.a, file was built for archive which is not the architecture being linked (x86_64): /Library/Developer/CommandLineTools/usr/include/libglfw3.a

我用 lipo 命令检查了库,它说他的架构是 x86_64! 我不知道为什么它不起作用,你能帮帮我吗?

提前致谢。

【问题讨论】:

    标签: c++ macos linker ld glfw


    【解决方案1】:

    我想说我找到了解决问题的方法。 您必须仔细检查库 libglfw3.a 是在 x86_64 的良好架构中编译的。

    在这里官方link 下载正确操作系统中的 GLFW 库

    这里是编译所需的命令:

    你需要确保通过-L指定库的路径

    g++ main.cpp -o main -L/Library/Developer/CommandLineTools/usr/include -lglfw3 -framework Cocoa -framework OpenGL -framework IOKit
    

    希望它对陷入同样问题的未来开发者有所帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      相关资源
      最近更新 更多