Skip to content

[macOS] SDL2::SDL2main target is not defined. #6119

Closed
@FtZPetruska

Description

@FtZPetruska

Starting version 2.24.0, the CMake target SDL2::SDL2main is no longer defined on macOS even when the library itself is present.

I have already seen a few reports of that issue from other macOS users in the discord server and one on the discourse forum.

The error happens when using SDL2 packaged from homebrew (uses autotools and installs a libSDL2main.a file), as well as the official release using the Apple framework.

Here is a sample project to reproduce the issue and the exact error message:

# CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(main VERSION 0.1.0)

add_executable(main main.cpp)

find_package(SDL2 CONFIG REQUIRED)

target_link_libraries(main PRIVATE SDL2::SDL2 SDL2::SDL2main)
/* main.cpp */
#include "SDL.h"

int main(int, char**) {
    SDL_Log("Hello world.\n");
    return 0;
}
CMake Error at CMakeLists.txt:8 (target_link_libraries):
   Target "main" links to:
 
     SDL2::SDL2main
 
   but the target was not found.  Possible reasons include:
 
     * There is a typo in the target name.
     * A find_package call is missing for an IMPORTED target.
     * An ALIAS target is missing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions