0

I want to use clion to develop the SDL project on the mac of my M1 chip. I have carried out the following steps

  1. Install the SDL library through Homebrew: brew install sdl2

  2. Configure SDL in CLion: CLion project Add a reference to SDL in the CMakeLists.txt file. At the bottom of the file, add the following lines: find_package(SDL2 REQUIRED) include_directories (${SDL2_INCLUDE_DIRS}) target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES})

  3. Test SDL #include <SDL.h>

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

type here

(SDL_INIT_VIDEO); // Initialize the video system of SDL

 SDL_Window* window = SDL_CreateWindow(
     "An SDL2 window", // window title
     SDL_WINDOWPOS_UNDEFINED, // initial X position
     SDL_WINDOWPOS_UNDEFINED, // initial Y position
     640, // width in pixels
     480, // height in pixels
     0 // Flag, can be set to 0
 );

 if (window == NULL) {
     // Handle errors creating the window here
     printf("Could not create window: %s\n", SDL_GetError());
     return 1;
 }

 SDL_Delay(3000); // wait three seconds

 SDL_DestroyWindow(window); // Destroy the window

 SDL_Quit(); // clean up and exit

 return 0;

}

Unfortunately: when I run the code I get Error log,: "ld: warning: ignoring file /opt/homebrew/lib/libSDL2.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64".

I know this error is caused by the incompatibility between the Mac's M1 chip and the x86_64 architecture.

But how should I fix it?

this error is caused by the incompatibility between the Mac's M1 chip and the x86_64 architecture.

But how should I fix it?

  • 2
    That error tells you *your project* is being built for x86_64 instead of the native m1 architecture. How did you end up in this situation? Do you have special compiler flags hanging around in your environment? – Botje Jun 23 '23 at 14:07
  • I don't know why this is the case, but when I re-installed CLion and reset the cMakeLists.txt file, the project can run. . . Of course I re-installed and uninstalled sdl2 many times in the process. . . – Hongbin BAO Jun 23 '23 at 22:54

0 Answers0