No video device found when compiling SDL's castholm on linux

I am trying to build my oscilloscope project using build.zig and cmake. I can compile and run using cmake:

cmake_minimum_required(VERSION 3.16)

# set the output directory for built objects.
# This makes sure that the dynamic library goes into the build directory automatically.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")

# prevent installing to system directories. 
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE INTERNAL "")

# Declare the project
project(sdl-synth)

set(SDL_SHARED ON)

add_executable(v1)

# Add your sources to the target
target_sources(v1 
PRIVATE 
    v1/main.cpp

    imgui/imgui.cpp
    imgui/imgui_demo.cpp
    imgui/imgui_draw.cpp
    imgui/imgui_tables.cpp
    imgui/imgui_widgets.cpp

    imgui/backends/imgui_impl_sdl3.cpp
    imgui/backends/imgui_impl_sdlrenderer3.cpp

    implot/implot.cpp
    implot/implot.h
    implot/implot_internal.h
    implot/implot_demo.cpp
    implot/implot_items.cpp
)

target_include_directories(v1 PRIVATE imgui/ imgui/backends/ implot/ v1/ )

target_compile_definitions(v1 PRIVATE SDL_MAIN_USE_CALLBACKS)

# Configure SDL by calling its CMake file.
# we use EXCLUDE_FROM_ALL so that its install targets and configs don't
# pollute upwards into our configuration.
add_subdirectory(SDL)

# Link SDL to our executable. This also makes its include directory available to us. 
target_link_libraries(v1 PUBLIC 
    SDL3::SDL3              # If using satelite libraries, SDL must be the last item in the list. 
)

But when I run my app built with build.zig it errors out saying no video driver are availlable:

const builtin = @import("builtin");
const std = @import("std");

pub fn build(b: *std.Build) anyerror!void {
    // Get the default optimization level.
    const optimize = b.standardOptimizeOption(.{});

    // Get the default target, this is the host computer and os.
    const target = b.standardTargetOptions(.{
        .default_target = std.Target.Query{
            .os_tag = builtin.target.os.tag,
        },
    });

    const run = b.step("run", "Run v1");

    const sdl_dep = b.dependency("sdl", .{
        .target = target,
        .optimize = optimize,
    });
    const sdl_lib = sdl_dep.artifact("SDL3");

    const v1_zig_module = b.addModule("v_1_z", .{
        .root_source_file = b.path("v1/generator.zig"),
        .target = target,
        .optimize = optimize,
    });

    const v1_zig_lib = b.addObject(.{
        .root_module = v1_zig_module,
        .name = "v_1_z_lib",
    });

    const v1_cpp_module = b.addModule("v_1", .{
        .target = target,
        .optimize = optimize,
        .link_libcpp = true,
    });
    v1_cpp_module.addObject(v1_zig_lib);
    v1_cpp_module.linkLibrary(sdl_lib);

    const files: []const []const u8 = &.{
        // Main application code
        "v1/main.cpp",

        // Imgui
        "imgui/imgui.cpp",
        "imgui/imgui_demo.cpp",
        "imgui/imgui_draw.cpp",
        "imgui/imgui_tables.cpp",
        "imgui/imgui_widgets.cpp",

        // Imgui backends
        "imgui/backends/imgui_impl_sdl3.cpp",
        "imgui/backends/imgui_impl_sdlrenderer3.cpp",

        // Implot
        "implot/implot.cpp",
        "implot/implot_demo.cpp",
        "implot/implot_items.cpp",
    };

    const flags: []const []const u8 = &.{
        "-DSDL_MAIN_USE_CALLBACKS=1",
    };

    v1_cpp_module.addCSourceFiles(.{
        .files = files,
        .flags = flags,
        .language = .cpp,
        .root = null,
    });

    v1_cpp_module.addIncludePath(b.path("v1/"));
    v1_cpp_module.addIncludePath(b.path("imgui/"));
    v1_cpp_module.addIncludePath(b.path("imgui/backends/"));
    v1_cpp_module.addIncludePath(b.path("implot/"));

    const v1_exe = b.addExecutable(.{
        .root_module = v1_cpp_module,
        .name = "v_1",
    });

    b.installArtifact(v1_exe);

    const runExe = b.addRunArtifact(v1_exe);
    run.dependOn(&runExe.step);
}

I am on ubuntu Noble, using zig 0.15.2.

I’d remove this part completely.
Are you sure it’s compiling to your native os, that is x86_64-linux-gnu and not x86_64-linux-musl?

2 Likes

Funny that S.D.L can compile with musl, but you don’t get any video drivers ! there should be a warning for that.

There would be if you were running a OS that has mesa compiled for musl and you were using a GPU that has mesa drivers. :slight_smile:

1 Like