authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-25 20:09:18-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-02-25 20:09:18-05:00
log152db27146e8b219af118abae8d235831aad2153
tree91f94e66e9757620cc21a06afbff78720509fec3
parent3ca861c7dd048a8bc15b6776a3b56fdc790750f7
signaturelock-open Commit is signed but in an unrecognized format.

better error message when forgetting to link against libc

closes #1698

3 files changed, 19 insertions(+), 0 deletions(-)

src/all_types.hpp+1
......@@ -1808,6 +1808,7 @@ struct CodeGen {
18081808 bool enable_cache;
18091809 bool enable_time_report;
18101810 bool system_linker_hack;
1811 bool reported_bad_link_libc_error;
18111812
18121813 //////////////////////////// Participates in Input Parameter Cache Hash
18131814 /////// Note: there is a separate cache hash for builtin.zig, when adding fields,
src/ir.cpp+8
......@@ -15520,6 +15520,14 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1552015520}
1552115521
1552215522static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name, AstNode *source_node) {
15523 if (buf_eql_str(lib_name, "c") && ira->codegen->libc_link_lib == nullptr &&
15524 !ira->codegen->reported_bad_link_libc_error)
15525 {
15526 ir_add_error_node(ira, source_node,
15527 buf_sprintf("dependency on library c must be explicitly specified in the build command"));
15528 ira->codegen->reported_bad_link_libc_error = true;
15529 }
15530
1552315531 LinkLib *link_lib = add_link_lib(ira->codegen, lib_name);
1552415532 for (size_t i = 0; i < link_lib->symbols.length; i += 1) {
1552515533 Buf *existing_symbol_name = link_lib->symbols.at(i);
test/compile_errors.zig+10
......@@ -1,6 +1,16 @@
11const tests = @import("tests.zig");
22
33pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.addTest(
5 "implicit dependency on libc",
6 \\extern "c" fn exit(u8) void;
7 \\export fn entry() void {
8 \\ exit(0);
9 \\}
10 ,
11 ".tmp_source.zig:3:5: error: dependency on library c must be explicitly specified in the build command",
12 );
13
414 cases.addTest(
515 "libc headers note",
616 \\const c = @cImport(@cInclude("stdio.h"));