[英]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.