TDA283-compiler-construction / project

Material for TDA283 / DIT300 Compiler Construction
11 stars 27 forks source link

Problem with clang's default directory in Big Sur #32

Open amuricys opened 2 years ago

amuricys commented 2 years ago

Hello, the testing script was not working on Monterey. I was getting the error "ld: library not found for -lSystem". After some googling and experimenting, I found this: https://github.com/ponylang/ponyc/issues/3684. Seems Apple made a breaking change with the default system libraries' locations, and now Homebrew's package (obtained with brew install llvm) is out of sync.

I was able to fix the issue by passing the exact same flag in the question. My link_llvm function inside testing.py now looks like this:

##
## Assemble and link files with LLVM.
##
def link_llvm(path, source_str):
    runtime = os.path.join(path, 'lib', 'runtime.bc')
    fd, tmp = tempfile.mkstemp(
            prefix='test_llvm_', suffix='.bc', dir=os.getcwd())
    try:
        with open(tmp, 'w+') as f:
            run_command("llvm-as", [], source_str, f)
        run_command("llvm-link", [tmp, runtime, "-o=main.bc"])
        new_linker_loc = ""
        if platform.system() == 'Darwin':
            mac_ver, _, _ = platform.mac_ver()
            new_linker_loc = "-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib" if mac_ver > '12.0.0' else ""
        run_command("clang", ["main.bc", new_linker_loc])
    finally:
        os.close(fd)
        clean_files([tmp, "main.bc"])

Maybe someone else is running into this issue as well, so I thought I'd post this suggestion.

oskarabrahamsson commented 2 years ago

How about setting LDFLAGS instead? (Edit: I haven't tried, so does it work?)