简体   繁体   中英

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

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. How do I get it to compile for aarch64?

CMakelists.txt is using C++20, it's a Vulkan proj (Using custom env vars)

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. This is influenced by CMAKE_HOST_SYSTEM_PROCESSOR , so that should be arm64 .

Setting the CMAKE_OSX_ARCHITECTURE should override that default so that it will build your application for arm64:

set(CMAKE_OSX_ARCHITECTURES "arm64")

That will force clang (or whatever compiler you're using) to compile for arm64.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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