Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better error message when building an exe, not linking libc, and exporting libc main #558

Closed
dimenus opened this Issue Oct 23, 2017 · 8 comments

Comments

Projects
None yet
2 participants
@dimenus
Copy link
Contributor

commented Oct 23, 2017

Seems to fail on x86_64, i386 in both GNU and MSVC.

MRE code:

const c = @cImport(@cInclude("stdio.h"));
export fn entry() void {
    c.printf("hello, world!\n");
}

compiler call:
zig build-exe load.zig

output:
C:\msys64\home\ryan\load.zig:3:6: error: no member named 'printf' in '(C import)' c.printf("hello\n");

@andrewrk

This comment has been minimized.

Copy link
Member

commented Oct 23, 2017

Were you looking at ziglang.org? I updated the example there to match what was in the examples/ folder. Tell me if that didn't fix it.

@andrewrk andrewrk closed this Oct 23, 2017

@andrewrk

This comment has been minimized.

Copy link
Member

commented Oct 23, 2017

We'll be able to support this smaller example on windows, but first we have to solve #515.

@dimenus

This comment has been minimized.

Copy link
Contributor Author

commented Oct 23, 2017

Yes, I was. Will refresh.

As for the sample from examples/ bootstrap.zig appears to get in the way:

F:\code\tools\zig\build-w64-debug\lib\zig\std\special\bootstrap.zig:66:8: error: exported symbol collision: 'main'
export fn main(c_argc: i32, c_argv: &&u8, c_envp: &?&u8) -> i32 {
       ^
F:\code\tools\zig\build-w64-debug\load.zig:10:8: note: other symbol is here
export fn main(argc: c_int, argv: &&u8) -> c_int {
       ^
F:\code\tools\zig\build-w64-debug\lib\zig\std\special\bootstrap.zig:41:34: error: expected type '?fn() -> %void', found 'extern fn(c_int, &&u8) -> c_int'
    std.debug.user_main_fn = root.main;
                                 ^
F:\code\tools\zig\build-w64-debug\lib\zig\std\special\bootstrap.zig:42:14: error: expected 2 arguments, found 0
    root.main() %% std.os.windows.ExitProcess(1);
             ^
F:\code\tools\zig\build-w64-debug\load.zig:10:8: note: declared here
export fn main(argc: c_int, argv: &&u8) -> c_int {

@andrewrk andrewrk reopened this Oct 23, 2017

@andrewrk

This comment has been minimized.

Copy link
Member

commented Oct 23, 2017

I think you need --library c.

This error message could be better, for example we could give the error expected pub main() -> %void, found export fn main...

@andrewrk

This comment has been minimized.

Copy link
Member

commented Oct 23, 2017

Note that you can also use the normal pub fn main() -> %void when you link libc.

@dimenus

This comment has been minimized.

Copy link
Contributor Author

commented Oct 23, 2017

Ok, getting Unable to determine msvc lib path. now but that's to be expected since I'm using VS 2017 w/ the install on a non-standard path. I can look at making that part more robust on my own ( and will submit a pull if/when I come up with something). Thanks for the quick response!

@andrewrk

This comment has been minimized.

Copy link
Member

commented Oct 23, 2017

See #539. Currently we only look for msvc 2015 but we should look for 2017 as well. Also there are command line args for setting the msvc path at runtime. Look for msvc in the --help menu.

@andrewrk andrewrk changed the title @cImport 'Hello World' example fails on 0.1.1 release better error message when building an exe, not linking libc, and exporting libc main Oct 23, 2017

@andrewrk andrewrk added this to the 0.3.0 milestone Oct 23, 2017

@andrewrk andrewrk modified the milestones: 0.3.0, 0.4.0 Feb 28, 2018

@andrewrk andrewrk closed this in 3ca861c Feb 26, 2019

@andrewrk

This comment has been minimized.

Copy link
Member

commented Feb 26, 2019

Example now gives:

/home/andy/dev/zig/build/test.zig:1:11: error: C import failed
const c = @cImport(@cInclude("stdio.h"));
          ^
/home/andy/dev/zig/build/test.zig:1:11: note: libc headers not available; compilation does not link against libc
const c = @cImport(@cInclude("stdio.h"));
          ^
/run/user/1000/T1mB37.h:1:10: note: 'stdio.h' file not found
#include <stdio.h>
         ^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.