Skip to content

Instantly share code, notes, and snippets.

@mikdusan
Created April 12, 2020 04:48
Show Gist options
  • Save mikdusan/4c0728cec0e25db705b2e293170e7b3a to your computer and use it in GitHub Desktop.
Save mikdusan/4c0728cec0e25db705b2e293170e7b3a to your computer and use it in GitHub Desktop.
andrew's c++ / stdc++ patch
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 5214d49a3..23ab2a130 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -9252,6 +9252,9 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa
}
args.append("-nostdinc");
+ if (source_kind == FileExtCpp) {
+ args.append("-nostdinc++");
+ }
args.append("-fno-spell-checking");
if (g->function_sections) {
diff --git a/src/main.cpp b/src/main.cpp
index 8805382f3..b682aa69b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -632,11 +632,17 @@ static int main0(int argc, char **argv) {
break;
}
case Stage2ClangArgL: // -l
- if (strcmp(it.only_arg, "c") == 0)
+ if (strcmp(it.only_arg, "c") == 0) {
have_libc = true;
- if (strcmp(it.only_arg, "c++") == 0)
+ link_libs.append("c");
+ } else if (strcmp(it.only_arg, "c++") == 0 ||
+ strcmp(it.only_arg, "stdc++") == 0)
+ {
have_libcpp = true;
- link_libs.append(it.only_arg);
+ link_libs.append("c++");
+ } else {
+ link_libs.append(it.only_arg);
+ }
break;
case Stage2ClangArgIgnore:
break;
@@ -1016,11 +1022,15 @@ static int main0(int argc, char **argv) {
} else if (arg[1] == 'l' && arg[2] != 0) {
// alias for --library
const char *l = &arg[2];
- if (strcmp(l, "c") == 0)
+ if (strcmp(l, "c") == 0) {
have_libc = true;
- if (strcmp(l, "c++") == 0)
+ link_libs.append("c");
+ } else if (strcmp(l, "c++") == 0 || strcmp(l, "stdc++") == 0) {
have_libcpp = true;
- link_libs.append(l);
+ link_libs.append("c++");
+ } else {
+ link_libs.append(l);
+ }
} else if (arg[1] == 'I' && arg[2] != 0) {
clang_argv.append("-I");
clang_argv.append(&arg[2]);
@@ -1159,11 +1169,15 @@ static int main0(int argc, char **argv) {
} else if (strcmp(arg, "-F") == 0) {
framework_dirs.append(argv[i]);
} else if (strcmp(arg, "--library") == 0 || strcmp(arg, "-l") == 0) {
- if (strcmp(argv[i], "c") == 0)
+ if (strcmp(argv[i], "c") == 0) {
have_libc = true;
- if (strcmp(argv[i], "c++") == 0)
+ link_libs.append("c");
+ } else if (strcmp(argv[i], "c++") == 0 || strcmp(argv[i], "stdc++") == 0) {
have_libcpp = true;
- link_libs.append(argv[i]);
+ link_libs.append("c++");
+ } else {
+ link_libs.append(argv[i]);
+ }
} else if (strcmp(arg, "--forbid-library") == 0) {
forbidden_link_libs.append(argv[i]);
} else if (strcmp(arg, "--object") == 0) {
@mikdusan
Copy link
Author

mikdusan commented Apr 12, 2020

put conditional around -nostdinc++ to avoid following warnings:

[master⋅0-0] archlinux▸ zig build-exe --name bar --c-source bar.cpp -lc++ -lc
zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
Build Dependencies...unwind [2] Compile C Objects [3/8] Unwind-seh.cpp...zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
Build Dependencies...unwind [2] Compile C Objects [4/8] UnwindLevel1.c...zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
Build Dependencies...unwind [2] Compile C Objects [5/8] UnwindLevel1-gcc-ext.c.....zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
Build Dependencies...unwind [2] Compile C Objects [7/8] UnwindRegistersRestore.S...zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
Build Dependencies...util [2] Semantic Analysis [15/26] zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
Build Dependencies...atexit [2] Compile C Objects [1/1] atexit.c...zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
Build Dependencies...fstat [2] Compile C Objects [1/1] fstat.c...zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
Build Dependencies...stat64 [2] Compile C Objects [1/1] stat64.c...zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
Build Dependencies...fstatat [2] Compile C Objects [1/1] fstatat.c...zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
Build Dependencies...mknod [2] Compile C Objects [1/1] mknod.c...zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
Build Dependencies...stack_chk_fail_local [2] Compile C Objects [1/1] stack_chk_...zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment