zig icon indicating copy to clipboard operation
zig copied to clipboard

fail to run zig build test on example from Export functions, variables, and types for C code to depend on

Open swuecho opened this issue 3 years ago • 4 comments

https://ziglang.org/learn/overview/#integration-with-c-libraries-without-ffibindings

zig build test ./build.zig:8:48: error: array literal requires address-of operator to coerce to slice type '[]const []const u8' exe.addCSourceFile("test.c", [_][]const u8 {"-std=c99"});

seems slice is expected after make the following change.

    const cstr = [_][]const u8{"-std=c99"} ;
    exe.addCSourceFile("test.c", cstr[0..1]);

another problem,

 zig build test
error(compilation): clang failed with stderr: /home/xxx/zig/mathtest_c/test.c:1:10: fatal error: 'mathtest.h' file not found

swuecho avatar May 24 '21 15:05 swuecho

➜ zsh git:(master) ✗ zig version 0.8.0-dev.2629+1c636e256 ➜ zsh git:(master) ✗ uname -a Linux 5.4.0-73-generic #82-Ubuntu SMP Wed Apr 14 17:39:42 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

swuecho avatar May 24 '21 15:05 swuecho

I believe this is caused by emit-h not being enabled in stage1 builds.

g-w1 avatar May 24 '21 17:05 g-w1

seems slice is expected after make the following change.

From the docs, it is

exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"});

I believe this is caused by emit-h not being enabled in stage1 builds.

In that case, should this be marked as a duplicate of GH-6753?

McSinyx avatar Aug 18 '21 17:08 McSinyx

  • +1.
  • https://ziglang.org/learn/overview/#export-functions-variables-and-types-for-c-code-to-depend-on
  • any update?

➤ zig version
0.10.0-dev.2617+47c4d4450

errors:


zig build-lib  src/zigmath.zig -femit-h

warning(compilation): -femit-h is not available in the stage1 backend; no .h file will be produced


hhstore avatar Aug 03 '22 17:08 hhstore