Skip to content

figure out how to handle precompiled headers #3495

@slaide

Description

@slaide
use @cImport({
  @cInclude("src/stb_image.h");
});

pub fn main()void{
  var x:c_int=0;
  var y:c_int=0;
  var n:c_int=0;
  var image=stbi_load(c"image.jpg",&x,&y,&n,0);
}

compiled with: zig build-exe test.zig --c-source -std=c17 -DSTB_IMAGE_IMPLEMENTATION src/stb_image.h -lc
produces this error: Build Dependencies...start...compiling C objects [0/1] start.S...lld: error: unclosed comment in a linker script

this code succeeds in c however, with the same std specified and also with clang, so the problem is not within the c-source file.

the define basically differentiates between the file being used as a header file, and the actual definitions.

including the file directly in the zig source via cImport with the defintion fails because the source translation fails to properly translate the code, which is ok, since the header itself works.

link to file: https://github.com/nothings/stb/blob/master/stb_image.h

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions