arm64 Mac 上未定义的 SDL2 符号?

问题描述 投票:0回答:0

我设置了 SDL2 并尝试使用示例代码运行它:

// On linux compile with:
// g++ -std=c++17 main.cpp -o prog -lSDL2

// C++ Standard Libraries
#include <iostream>

// Third-party library
#include <SDL2/SDL.h>

int main(int argc, char* argv[]){

    // Create a window data type
    // This pointer will point to the 
    // window that is allocated from SDL_CreateWindow
    SDL_Window* window=nullptr;

    // Initialize the video subsystem.
    // If it returns less than 1, then an
    // error code will be received.
    if(SDL_Init(SDL_INIT_VIDEO) < 0){
        std::cout << "SDL could not be initialized: " <<
                  SDL_GetError();
    }else{
        std::cout << "SDL video system is ready to go\n";
    }

    // Request a window to be created for our platform
    // The parameters are for the title, x and y position,
    // and the width and height of the window.
    window = SDL_CreateWindow("C++ SDL2 Window",
            0,
            2500,
            640,
            480,
            SDL_WINDOW_SHOWN);

    // We add a delay in order to see that our window
    // has successfully popped up.
    SDL_Delay(3000);

    // We destroy our window. We are passing in the pointer
    // that points to the memory allocated by the 
    // 'SDL_CreateWindow' function. Remember, this is
    // a 'C-style' API, we don't have destructors.
    SDL_DestroyWindow(window);
    
    // We safely uninitialize SDL2, that is, we are
    // taking down the subsystems here before we exit
    // our program.
    SDL_Quit();
    return 0;
}

...但是我得到一个错误:

Undefined symbols for architecture arm64:
  "_SDL_CreateWindow", referenced from:
      _main in gui-67ced6.o
  "_SDL_Delay", referenced from:
      _main in gui-67ced6.o
  "_SDL_DestroyWindow", referenced from:
      _main in gui-67ced6.o
  "_SDL_GetError", referenced from:
      _main in gui-67ced6.o
  "_SDL_Init", referenced from:
      _main in gui-67ced6.o
  "_SDL_Quit", referenced from:
      _main in gui-67ced6.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我在 Apple 的 M1 Pro 上运行这个

我一直看到这个错误,到处都是我得到的唯一解决方案是在 Xcode 上。我正在尝试使用 VS Code 运行它。

c++ macos sdl-2 apple-m1 undefined-symbol
© www.soinside.com 2019 - 2024. All rights reserved.