diff --git a/README.md b/README.md index 0de6d8d5d4..2684b76055 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,6 @@ readable, safe, optimal, and concise code to solve any computing problem. * Math expression * Export .so library - * Export .o file * Multiple files * inline assembly and syscalls * running code at compile time diff --git a/src/codegen.cpp b/src/codegen.cpp index 3f0860a702..c79796c0f3 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -994,7 +994,10 @@ void code_gen_link(CodeGen *g, const char *out_file) { Buf out_file_o = BUF_INIT; buf_init_from_str(&out_file_o, out_file); - buf_append_str(&out_file_o, ".o"); + + if (g->out_type != OutTypeObj) { + buf_append_str(&out_file_o, ".o"); + } char *err_msg = nullptr; if (LLVMZigTargetMachineEmitToFile(g->target_machine, g->module, buf_ptr(&out_file_o), @@ -1003,6 +1006,17 @@ void code_gen_link(CodeGen *g, const char *out_file) { zig_panic("unable to write object file: %s", err_msg); } + if (g->out_type == OutTypeObj) { + return; + } + + if (g->out_type == OutTypeLib && g->is_static) { + // invoke `ar` + zig_panic("TODO invoke ar"); + return; + } + + // invoke `ld` ZigList args = {0}; if (g->is_static) { args.append("-static"); diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp index 89d0563b97..cde28c13b5 100644 --- a/src/zig_llvm.cpp +++ b/src/zig_llvm.cpp @@ -156,7 +156,7 @@ static LLVMBool LLVMZigTargetMachineEmit(LLVMTargetMachineRef targ_machine_ref, } LLVMBool LLVMZigTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref, - char* filename, LLVMCodeGenFileType codegen, char** err_msg) + const char* filename, LLVMCodeGenFileType codegen, char** err_msg) { std::error_code error_code; raw_fd_ostream dest(filename, error_code, sys::fs::F_None); diff --git a/src/zig_llvm.hpp b/src/zig_llvm.hpp index fda8e371ec..be1bf64d9a 100644 --- a/src/zig_llvm.hpp +++ b/src/zig_llvm.hpp @@ -22,7 +22,7 @@ char *LLVMZigGetHostCPUName(void); char *LLVMZigGetNativeFeatures(void); LLVMBool LLVMZigTargetMachineEmitToFile(LLVMTargetMachineRef target_machine, LLVMModuleRef module, - char* filename, LLVMCodeGenFileType codegen, char** error_msg); + const char* filename, LLVMCodeGenFileType codegen, char** error_msg); void LLVMZigOptimizeModule(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref);