diff --git a/src/build.c b/src/build.c index 2024f7a37..b8cbfa7a6 100644 --- a/src/build.c +++ b/src/build.c @@ -330,8 +330,15 @@ void init_build_context(BuildContext *bc) { #define linker_flag_x86 "" #else // Linux, but also BSDs and the like. - #define linker_flag_x64 "-m elf_x86_64" - #define linker_flag_x86 "-m elf_i386" + // NOTE(zangent): When clang is swapped out with ld as the linker, + // the commented flags here should be used. Until then, we'll have + // to use alternative build flags made for clang. + /* + #define linker_flag_x64 "-m elf_x86_64" + #define linker_flag_x86 "-m elf_i386" + */ + #define linker_flag_x64 "-arch x86-64" + #define linker_flag_x86 "-arch x86" #endif if (str_eq(bc->ODIN_ARCH, str_lit("amd64"))) { diff --git a/src/main.c b/src/main.c index 48833225e..679dfaec9 100644 --- a/src/main.c +++ b/src/main.c @@ -383,14 +383,15 @@ int main(int argc, char **argv) { // Unlike the Win32 linker code, the output_ext includes the dot, because // typically executable files on *NIX systems don't have extensions. - char *output_ext = ".bin"; + char *output_ext = ""; char *link_settings = ""; + char *linker; if (build_context.is_dll) { // Shared libraries are .dylib on MacOS and .so on Linux. #if defined(GB_SYSTEM_OSX) - output_ext = ".dylib"; + output_ext = ".dylib"; #else - output_ext = ".so"; + output_ext = ".so"; #endif link_settings = "-shared"; @@ -399,16 +400,26 @@ int main(int argc, char **argv) { link_settings = ""; } + #if defined(GB_SYSTEM_OSX) + linker = "ld"; + #else + // TODO(zangent): Figure out how to make ld work on Linux. + // It probably has to do with including the entire CRT, but + // that's quite a complicated issue to solve while remaining distro-agnostic. + // Clang can figure out linker flags for us, and that's good enough _for now_. + linker = "clang"; + #endif + printf("Libs: %s\n", lib_str); // TODO(zangent): I'm not sure what to do with lib_str. // I'll have to look at the format that the libraries are listed to determine what to do. lib_str = ""; - + exit_code = system_exec_command_line_app("ld-link", true, - "ld \"%.*s\".o -o \"%.*s%s\" %s " + "%s \"%.*s\".o -o \"%.*s%s\" %s " "-lc " " %.*s " " %s " @@ -416,11 +427,8 @@ int main(int argc, char **argv) { // This sets a requirement of Mountain Lion and up, but the compiler doesn't work without this limit. " -macosx_version_min 10.8.0 " " -e _main " - #else - " -e main -dynamic-linker /lib64/ld-linux-x86-64.so.2 " #endif - , - LIT(output), LIT(output), output_ext, + , linker, LIT(output), LIT(output), output_ext, lib_str, LIT(build_context.link_flags), link_settings );