Glfw-3.3.5 - Nedefinované symboly pro architekturu arm64

0

Otázka

Mít propojené všechny knihovny v cmake a wrtten kód, který otevře okno s GLFW, běh vybudovat s make příkaz vrátí jako výstup:

[main] Building folder: game 
[build] Starting build
[proc] Executing command: /opt/homebrew/bin/cmake --build /Users/matt/projects/game/build --config Debug --target all -j 10 --
[build] Consolidate compiler generated dependencies of target game
[build] [ 50%] Building CXX object CMakeFiles/game.dir/main.cpp.o
[build] [100%] Linking CXX executable game
[build] Undefined symbols for architecture arm64:
[build]   "_glClear", referenced from:
[build]       _main in main.cpp.o
[build]   "_glewExperimental", referenced from:
[build]       _main in main.cpp.o
[build]   "_glewInit", referenced from:
[build]       _main in main.cpp.o
[build]   "_glfwCreateWindow", referenced from:
[build]       _main in main.cpp.o
[build]   "_glfwGetKey", referenced from:
[build]       _main in main.cpp.o
[build]   "_glfwInit", referenced from:
[build]       _main in main.cpp.o
[build]   "_glfwMakeContextCurrent", referenced from:
[build]       _main in main.cpp.o
[build]   "_glfwPollEvents", referenced from:
[build]       _main in main.cpp.o
[build]   "_glfwSetInputMode", referenced from:
[build]       _main in main.cpp.o
[build]   "_glfwSwapBuffers", referenced from:
[build]       _main in main.cpp.o
[build]   "_glfwTerminate", referenced from:
[build]       _main in main.cpp.o
[build]   "_glfwWindowHint", referenced from:
[build]       _main in main.cpp.o
[build]   "_glfwWindowShouldClose", referenced from:
[build]       _main in main.cpp.o
[build] ld: symbol(s) not found for architecture arm64
[build] collect2: error: ld returned 1 exit status
[build] make[2]: *** [game] Error 1
[build] make[1]: *** [CMakeFiles/game.dir/all] Error 2
[build] make: *** [all] Error 2

Něco poznamenat, je, že to staví úspěšně se pouze dovoz, ale ne kód zodpovědný za otevření GLFW okno, tak se to nezdá být problém s linkerem.

Můj CMakeLists.txt vypadá takto:

cmake_minimum_required(VERSION 3.12)
project(Game VERSION 1.0.0)
include_directories(${PROJECT_SOURCE_DIR}/deps/glfw-3.3.5/include/GLFW)
#---------------Configure dependency directories--------------------------------------------------------------
SET (PROJECT_DEPS "${PROJECT_SOURCE_DIR}/deps")
SET (glew_inc "${PROJECT_DEPS}/glew-2.1.0/include/GL/")
SET (glew_src "${PROJECT_DEPS}/glew-2.1.0/src/")
SET (glfw_inc "${PROJECT_DEPS}/glfw-3.3.5/include/GLFW/")
SET (glfw_src "${PROJECT_DEPS}/glfw-3.3.5/src/")
SET (glm "${PROJECT_DEPS}/glm/glm/")
#---------------Configure libraries----------------------------------------------------------------------------
include_directories(
    ${PROJECT_SOURCE_DIR}
    ${PROJECT_BINARY_DIR}
    ${glm}
    ${glew_inc}
    ${glew_src}
    ${glfw_inc}
    ${glfw_src}
    ${PROJECT_SOURCE_DIR}
    )
#---------------Add executable---------------------------------------------------------------------------------
add_executable(game ${PROJECT_SOURCE_DIR}/main.cpp)
link_libraries(Game PRIVATE glfw-3.3.5)
link_libraries(Game PRIVATE glew-2.1.0)
link_libraries(Game PRIVATE glm)

A můj main.cpp projekt soubor s příponou root, z nichž spustitelný soubor je postaven vypadá takto:

#include <stdio.h>
#include <stdlib.h>
#include <glew.h>
#include <glfw3native.h>
#include <glfw3.h>
#include <glm.hpp>

int main () {
  glewExperimental = true; // Needed for core profile
  if (!glfwInit()) {
      fprintf(stderr, "Failed to initialize GLFW\n");
      return -1;
  }

  glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing
  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // We want OpenGL 3.3
  glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
  glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
  glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // We don't want the old OpenGL 

  GLFWwindow* window; // (In the accompanying source code, this variable is global for simplicity)
  window = glfwCreateWindow( 1024, 768, "Tutorial 01", NULL, NULL);
  if( window == NULL ){
      fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
      glfwTerminate();
      return -1;
  }
  glfwMakeContextCurrent(window); // Initialize GLEW
  glewExperimental=true; // Needed in core profile
  if (glewInit() != GLEW_OK) {
      fprintf(stderr, "Failed to initialize GLEW\n");
      return -1;
  }

  glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);

  do {
      glClear( GL_COLOR_BUFFER_BIT );
      glfwSwapBuffers(window);
      glfwPollEvents();

  } while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(window) == 0);

  return 0;  
}

Já používám MacBook Pro 2020 s M1 čip.

apple-m1 arm64 c++ cmake
2021-11-19 20:44:01
1

Nejlepší odpověď

0

link_libraries by měla být target_link_libraries. link_libraries se vztahuje pouze na cíle definované po

2021-11-19 21:04:17

Díky!!! Zdá se, že jsem na to přišel.
MattC

V jiných jazycích

Tato stránka je v jiných jazycích

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................