简体   繁体   English

为 x86_64 构建但从自制软件安装的 glfw 是为 arm64 (aarch64)

[英]Make building for x86_64 but glfw installed from homebrew is for arm64 (aarch64)

My project was building fine with make, until I imported stb, now I get this error我的项目使用 make 构建良好,直到我导入 stb,现在我收到此错误

ld: warning: ignoring file /opt/homebrew/lib/libglfw.3.4.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture x86_64:
  "_glfwCreateWindow", referenced from:
      HelloTriangleApplication::initWindow() in main.cpp.o
  "_glfwCreateWindowSurface", referenced from:
      HelloTriangleApplication::createSurface() in main.cpp.o
  "_glfwDestroyWindow", referenced from:
      HelloTriangleApplication::cleanup() in main.cpp.o
  "_glfwGetFramebufferSize", referenced from:
      HelloTriangleApplication::chooseSwapExtent(VkSurfaceCapabilitiesKHR const&) in main.cpp.o
      HelloTriangleApplication::recreateSwapChain() in main.cpp.o
  "_glfwGetRequiredInstanceExtensions", referenced from:
      HelloTriangleApplication::getRequiredExtensions() in main.cpp.o
  "_glfwGetWindowUserPointer", referenced from:
      HelloTriangleApplication::framebufferResizeCallback(GLFWwindow*, int, int) in main.cpp.o
  "_glfwInit", referenced from:
      HelloTriangleApplication::initWindow() in main.cpp.o
  "_glfwPollEvents", referenced from:
      HelloTriangleApplication::mainLoop() in main.cpp.o
  "_glfwSetFramebufferSizeCallback", referenced from:
      HelloTriangleApplication::initWindow() in main.cpp.o
  "_glfwSetWindowUserPointer", referenced from:
      HelloTriangleApplication::initWindow() in main.cpp.o
  "_glfwTerminate", referenced from:
      HelloTriangleApplication::cleanup() in main.cpp.o
  "_glfwWaitEvents", referenced from:
      HelloTriangleApplication::recreateSwapChain() in main.cpp.o
  "_glfwWindowHint", referenced from:
      HelloTriangleApplication::initWindow() in main.cpp.o
  "_glfwWindowShouldClose", referenced from:
      HelloTriangleApplication::mainLoop() in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [vulkanLearning] Error 1
make[1]: *** [CMakeFiles/vulkanLearning.dir/all] Error 2
make: *** [all] Error 2

It seems like the program is compiling for x86_64, but the libglfw I've installed from homebrew is for aarch64.程序似乎是为 x86_64 编译的,但我从自制软件安装的 libglfw 是为 aarch64 编译的。 How do I get it to compile for aarch64?我如何让它为 aarch64 编译?

CMakelists.txt is using C++20, it's a Vulkan proj (Using custom env vars) CMakelists.txt 使用的是 C++20,它是一个 Vulkan 项目(使用自定义环境变量)

cmake_minimum_required (VERSION 3.12)
project(
    vulkanLearning VERSION 0.1.0
    DESCRIPTION "vulkanLearning"
    LANGUAGES CXX
)

# Specify the C++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS OFF)
# Set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/build)
# Set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

add_executable(${PROJECT_NAME} main.cpp)

find_package(Vulkan REQUIRED)
find_package(glfw3 3.3 REQUIRED)

if (VULKAN_FOUND)
    message(STATUS "Found Vulkan, Including and Linking now")
    include_directories(${Vulkan_INCLUDE_DIRS})
    target_link_libraries (${PROJECT_NAME} ${Vulkan_LIBRARIES} glfw)
endif (VULKAN_FOUND)

It seems as if CMake is building for x86_64 even though your processor runs on arm64.似乎 CMake 正在为 x86_64 构建,即使您的处理器在 arm64 上运行。 This is influenced by CMAKE_HOST_SYSTEM_PROCESSOR , so that should be arm64 .这受CMAKE_HOST_SYSTEM_PROCESSOR的影响,因此应该是arm64

Setting the CMAKE_OSX_ARCHITECTURE should override that default so that it will build your application for arm64:设置 CMAKE_OSX_ARCHITECTURE 应该覆盖该默认值,以便它将为 arm64 构建您的应用程序:

set(CMAKE_OSX_ARCHITECTURES "arm64")

That will force clang (or whatever compiler you're using) to compile for arm64.这将强制 clang(或您使用的任何编译器)为 arm64 编译。

暂无
暂无

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

相关问题 cmake 在 Mac 上使用 ARM M1 正在运行 linker 使用 x86_64 架构而不是 arm64 - cmake on Mac with ARM M1 is running linker with x86_64 architecture instead of arm64 mach-o 文件,但它是一个不兼容的架构(有“arm64”,需要“x86_64”) - mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64') 在 aarch64/arm64 上将浮点数转换为 int - Casting float to int with wrap-around on aarch64/arm64 Tesseract cross-compile aarch64 (arm64-v8a) error this header is for x86 only - Tesseract cross-compile aarch64 (arm64-v8a) error this header is for x86 only 新 Apple 芯片 (arm64) 与 x86_64 上 double 和 int64_t 转换的不同行为 - Different behavior of double and int64_t conversion on new Apple silicon (arm64) vs. x86_64 在构建用于多种架构(x86_64,armv7,armv7s,arm64,i386)的C ++共享库时面临的问题 - Facing issues in building a C++ shared library for multiple architectures (x86_64, armv7, armv7s, arm64, i386) 为什么我在 Apple Silicon 上编译的本机应用程序有时构建为 arm64,有时构建为 x86_64? - Why does my native application compiled on Apple Silicon sometimes build as arm64 and sometimes build as x86_64? GLFW“架构 arm64 的未定义符号” - GLFW "Undefined symbols for architecture arm64" 架构 arm64 的未定义符号:“_glClear”,引用自:main.cpp.o arm64 GLFW3 中的 _main - Undefined symbols for architecture arm64: "_glClear", referenced from: _main in main.cpp.o arm64 GLFW3 Quartz:为x86_64体系结构构建时未定义的符号 - Quartz : Undefined symbols when building for x86_64 architecture
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM