From 0ac714f0d6a23ea1810c8a6327dc6048c2df14c5 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 31 Jan 2016 18:32:07 -0700 Subject: add --library-path cli option --- src/codegen.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/codegen.cpp') diff --git a/src/codegen.cpp b/src/codegen.cpp index 36f34e5b54..a5a91b55d2 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -73,6 +73,10 @@ void codegen_set_libc_path(CodeGen *g, Buf *libc_path) { g->libc_path = libc_path; } +void codegen_add_lib_dir(CodeGen *g, const char *dir) { + g->lib_dirs.append(dir); +} + static LLVMValueRef gen_expr(CodeGen *g, AstNode *expr_node); static LLVMValueRef gen_lvalue(CodeGen *g, AstNode *expr_node, AstNode *node, TypeTableEntry **out_type_entry); static LLVMValueRef gen_field_access_expr(CodeGen *g, AstNode *node, bool is_lvalue); @@ -3648,6 +3652,12 @@ void codegen_link(CodeGen *g, const char *out_file) { args.append(get_libc_file(g, "crtn.o")); } + for (int i = 0; i < g->lib_dirs.length; i += 1) { + const char *lib_dir = g->lib_dirs.at(i); + args.append("-L"); + args.append(lib_dir); + } + auto it = g->link_table.entry_iterator(); for (;;) { auto *entry = it.next(); @@ -3673,7 +3683,11 @@ void codegen_link(CodeGen *g, const char *out_file) { if (return_code != 0) { fprintf(stderr, "ld failed with return code %d\n", return_code); - fprintf(stderr, "%s\n", buf_ptr(&ld_stderr)); + fprintf(stderr, "ld "); + for (int i = 0; i < args.length; i += 1) { + fprintf(stderr, "%s ", args.at(i)); + } + fprintf(stderr, "\n%s\n", buf_ptr(&ld_stderr)); exit(1); } else if (buf_len(&ld_stderr)) { fprintf(stderr, "%s\n", buf_ptr(&ld_stderr)); -- cgit v1.2.3