Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build error for lfortran #3

Open
kjelljorner opened this issue Jun 3, 2022 · 14 comments
Open

Build error for lfortran #3

kjelljorner opened this issue Jun 3, 2022 · 14 comments

Comments

@kjelljorner
Copy link

When trying to install lfortran on Mac M1 Monterey I get this error message. Also, seems like lfortran 0.15 is now available so the recipe could be updated as well.

(base) kjelljorner@dhcp-45 lfortran-0.15.0 % brew install lfortran                                             
==> Downloading https://lfortran.github.io/tarballs/release/lfortran-0.14.0.tar.gz
Already downloaded: /Users/kjelljorner/Library/Caches/Homebrew/downloads/a2cafbbe75c0ad045754d066d39f2f76dbaf1edffdf9831bc80f23435d63af5f--lfortran-0.14.0.tar.gz
==> Installing lfortran from fortran-lang/fortran
==> cmake -DCMAKE_CXX_FLAGS_RELEASE=-O3 -funroll-loops -DNDEBUG -DWITH_LLVM=ON -G Ninja -B build
==> cmake --build build
Last 15 lines from /Users/kjelljorner/Library/Logs/Homebrew/lfortran/02.cmake:
  "VTT for std::__1::basic_ofstream<char, std::__1::char_traits<char> >", referenced from:
      LFortran::write_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in liblfortran_lib.a(evaluator.cpp.o)
  "vtable for std::__1::basic_ifstream<char, std::__1::char_traits<char> >", referenced from:
      LFortran::read_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in liblfortran_lib.a(utils.cpp.o)
      LFortran::read_line_from_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned int) in liblfortran_lib.a(stacktrace.cpp.o)
      LFortran::get_local_info_dwarfdump(std::__1::vector<LFortran::StacktraceItem, std::__1::allocator<LFortran::StacktraceItem> >&) in liblfortran_lib.a(stacktrace.cpp.o)
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for std::__1::basic_ofstream<char, std::__1::char_traits<char> >", referenced from:
      LFortran::write_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in liblfortran_lib.a(evaluator.cpp.o)
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[70/86] /opt/homebrew/Library/Homebrew/shims/mac/super/clang++ -DHAVE_TARGET_AARCH64=1 -I/tmp/lfortran-20220603-47415-1fci7r4/lfortran-0.14.0/build/src -I/tmp/lfortran-20220603-47415-1fci7r4/lfortran-0.14.0/src -O3 -funroll-loops -DNDEBUG -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -fPIE -fno-rtti -std=gnu++17 -MD -MT src/bin/CMakeFiles/cpptranslate.dir/cpptranslate.cpp.o -MF src/bin/CMakeFiles/cpptranslate.dir/cpptranslate.cpp.o.d -o src/bin/CMakeFiles/cpptranslate.dir/cpptranslate.cpp.o -c /tmp/lfortran-20220603-47415-1fci7r4/lfortran-0.14.0/src/bin/cpptranslate.cpp
[71/86] /opt/homebrew/Library/Homebrew/shims/mac/super/clang++ -DHAVE_TARGET_AARCH64=1 -I/tmp/lfortran-20220603-47415-1fci7r4/lfortran-0.14.0/src/bin/tpl -I/tmp/lfortran-20220603-47415-1fci7r4/lfortran-0.14.0/build/src -I/tmp/lfortran-20220603-47415-1fci7r4/lfortran-0.14.0/src -O3 -funroll-loops -DNDEBUG -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -fPIE -fno-rtti -std=gnu++17 -MD -MT src/bin/CMakeFiles/lfortran.dir/lfortran.cpp.o -MF src/bin/CMakeFiles/lfortran.dir/lfortran.cpp.o.d -o src/bin/CMakeFiles/lfortran.dir/lfortran.cpp.o -c /tmp/lfortran-20220603-47415-1fci7r4/lfortran-0.14.0/src/bin/lfortran.cpp
ninja: build stopped: subcommand failed.

@certik
Copy link
Member

certik commented Jun 3, 2022

Not sure where this might be coming from. Here is a Spack build that works for me on M1:

The above error looks like some C++ runtime library issue?

@kjelljorner
Copy link
Author

Building with GCC gives similar errors

Last 15 lines from /Users/kjelljorner/Library/Logs/Homebrew/lfortran/02.cmake:
  "__ZTv0_n24_NSt3__114basic_iostreamIcNS_11char_traitsIcEEED0Ev", referenced from:
      __ZTCNSt3__118basic_stringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEEE0_NS_14basic_iostreamIcS2_EE in libLLVMInstrumentation.a(InstrOrderFile.cpp.o)
      __ZTCNSt3__118basic_stringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEEE0_NS_14basic_iostreamIcS2_EE in libLLVMAnalysis.a(InlineAdvisor.cpp.o)
      __ZTCNSt3__118basic_stringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEEE0_NS_14basic_iostreamIcS2_EE in libLLVMTransformUtils.a(ImportedFunctionsInliningStatistics.cpp.o)
      __ZTCNSt3__118basic_stringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEEE0_NS_14basic_iostreamIcS2_EE in libLLVMTextAPI.a(InterfaceFile.cpp.o)
  "__ZTv0_n24_NSt3__114basic_iostreamIcNS_11char_traitsIcEEED1Ev", referenced from:
      __ZTCNSt3__118basic_stringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEEE0_NS_14basic_iostreamIcS2_EE in libLLVMInstrumentation.a(InstrOrderFile.cpp.o)
      __ZTCNSt3__118basic_stringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEEE0_NS_14basic_iostreamIcS2_EE in libLLVMAnalysis.a(InlineAdvisor.cpp.o)
      __ZTCNSt3__118basic_stringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEEE0_NS_14basic_iostreamIcS2_EE in libLLVMTransformUtils.a(ImportedFunctionsInliningStatistics.cpp.o)
      __ZTCNSt3__118basic_stringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEEE0_NS_14basic_iostreamIcS2_EE in libLLVMTextAPI.a(InterfaceFile.cpp.o)
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status

@awvwgk
Copy link
Member

awvwgk commented Jun 3, 2022

For LFortran 0.14.0 there is an error on MacOS/Arm64, which got LFortran rejected from homebrew-core (see Homebrew/homebrew-core#92088). Seems like this is fixed with 0.15.0, so maybe an update of the formula would be the best fix.

@kjelljorner
Copy link
Author

Modifying the recipe to load 0.15.0 with

url "https://lfortran.github.io/tarballs/release/lfortran-0.15.0.tar.gz"
sha256 "8712c1b0c886f08937ff4c277ff3fa5c05e4dead1bafe55e3bd789be96470127"

still gives an error for me

Last 15 lines from /Users/kjelljorner/Library/Logs/Homebrew/lfortran/02.cmake:
      LFortran::read_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in libasr.a(utils2.cpp.o)
      LFortran::read_line_from_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, unsigned int) in libasr.a(stacktrace.cpp.o)
      LFortran::get_local_info_dwarfdump(std::__1::vector<LFortran::StacktraceItem, std::__1::allocator<LFortran::StacktraceItem> >&) in libasr.a(stacktrace.cpp.o)
      LFortran::read_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libasr.a(string_utils.cpp.o)
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for std::__1::basic_ofstream<char, std::__1::char_traits<char> >", referenced from:
      LFortran::X86Assembler::save_asm(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in test_asm.cpp.o
      LFortran::write_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libasr.a(evaluator.cpp.o)
      LFortran::X86Assembler::save_binary(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libasr.a(x86_assembler.cpp.o)
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture arm64

@certik
Copy link
Member

certik commented Jun 3, 2022

I use M1 as my main development machine for LFortran, so everything should work. I've never seen this error. Can you post the full log: the output of cmake and the full ninja build? I am happy to fix it upstream (if this is some bug in LFortran) and make a new release.

@kjelljorner
Copy link
Author

Here's the full stderr and stdout of HOMEBREW_MAKE_JOBS=1 brew install lfortran --verbose > brew.out 2> brew.err. Included are also the logs created by homebrew and mentioned at the end of the output file. Hope that helps.

Logs:
     /Users/kjelljorner/Library/Logs/Homebrew/lfortran/02.cmake.cc
     /Users/kjelljorner/Library/Logs/Homebrew/lfortran/00.options.out
     /Users/kjelljorner/Library/Logs/Homebrew/lfortran/01.cmake.cc
     /Users/kjelljorner/Library/Logs/Homebrew/lfortran/01.cmake
     /Users/kjelljorner/Library/Logs/Homebrew/lfortran/02.cmake
     /Users/kjelljorner/Library/Logs/Homebrew/lfortran/build

Archive.zip

@certik
Copy link
Member

certik commented Jun 3, 2022

Ok, so it seems you are missing a C++ standard library in the Homebrew's own clang. Here is an example of the invocation:

: && /opt/homebrew/Library/Homebrew/shims/mac/super/clang++ -O3 -funroll-loops -DNDEBUG -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names  src/lfortran/tests/CMakeFiles/x.dir/x.cpp.o -o src/lfortran/tests/x  src/lfortran/liblfortran_lib.a  src/runtime/legacy/liblfortran_runtime_static.a  /opt/homebrew/opt/llvm@11/lib/libLLVMMCJIT.a  /opt/homebrew/opt/llvm@11/lib/libLLVMOrcJIT.a  /opt/homebrew/opt/llvm@11/lib/libLLVMExecutionEngine.a  /opt/homebrew/opt/llvm@11/lib/libLLVMRuntimeDyld.a  /opt/homebrew/opt/llvm@11/lib/libLLVMJITLink.a  /opt/homebrew/opt/llvm@11/lib/libLLVMOrcError.a  /opt/homebrew/opt/llvm@11/lib/libLLVMPasses.a  /opt/homebrew/opt/llvm@11/lib/libLLVMCoroutines.a  /opt/homebrew/opt/llvm@11/lib/libLLVMipo.a  /opt/homebrew/opt/llvm@11/lib/libLLVMInstrumentation.a  /opt/homebrew/opt/llvm@11/lib/libLLVMVectorize.a  /opt/homebrew/opt/llvm@11/lib/libLLVMFrontendOpenMP.a  /opt/homebrew/opt/llvm@11/lib/libLLVMIRReader.a  /opt/homebrew/opt/llvm@11/lib/libLLVMLinker.a  /opt/homebrew/opt/llvm@11/lib/libLLVMAsmParser.a  /opt/homebrew/opt/llvm@11/lib/libLLVMAArch64AsmParser.a  /opt/homebrew/opt/llvm@11/lib/libLLVMAArch64CodeGen.a  /opt/homebrew/opt/llvm@11/lib/libLLVMAsmPrinter.a  /opt/homebrew/opt/llvm@11/lib/libLLVMDebugInfoDWARF.a  /opt/homebrew/opt/llvm@11/lib/libLLVMCFGuard.a  /opt/homebrew/opt/llvm@11/lib/libLLVMGlobalISel.a  /opt/homebrew/opt/llvm@11/lib/libLLVMSelectionDAG.a  /opt/homebrew/opt/llvm@11/lib/libLLVMCodeGen.a  /opt/homebrew/opt/llvm@11/lib/libLLVMTarget.a  /opt/homebrew/opt/llvm@11/lib/libLLVMBitWriter.a  /opt/homebrew/opt/llvm@11/lib/libLLVMScalarOpts.a  /opt/homebrew/opt/llvm@11/lib/libLLVMAggressiveInstCombine.a  /opt/homebrew/opt/llvm@11/lib/libLLVMInstCombine.a  /opt/homebrew/opt/llvm@11/lib/libLLVMTransformUtils.a  /opt/homebrew/opt/llvm@11/lib/libLLVMAnalysis.a  /opt/homebrew/opt/llvm@11/lib/libLLVMObject.a  /opt/homebrew/opt/llvm@11/lib/libLLVMBitReader.a  /opt/homebrew/opt/llvm@11/lib/libLLVMMCParser.a  /opt/homebrew/opt/llvm@11/lib/libLLVMTextAPI.a  /opt/homebrew/opt/llvm@11/lib/libLLVMProfileData.a  /opt/hom@@@
Undefined symbols for architecture arm64:^M
  "std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::str(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:^M
      LFortran::get_line(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int) in liblfortran_lib.a(parser.cpp.o)^M
ld: symbol(s) not found for architecture arm64^M
clang: error: linker command failed with exit code 1 (use -v to see invocation)^M

The line looks good to me. For comparison, here is such a line on my M1:

/Library/Developer/CommandLineTools/usr/bin/c++ -Wall -Wextra -g -ggdb -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/lfortran.dir/lfortran.cpp.o -o lfortran  ../lfortran/liblfortran_lib.a ../libasr/libasr.a ../runtime/legacy/liblfortran_runtime_static.a /Users/ondrej/mambaforge/envs/lf/lib/libz.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMMCJIT.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMOrcJIT.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMExecutionEngine.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMRuntimeDyld.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMJITLink.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMOrcError.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMPasses.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMCoroutines.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMipo.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMInstrumentation.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMVectorize.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMFrontendOpenMP.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMIRReader.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMLinker.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMAsmParser.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMAArch64AsmParser.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMAArch64CodeGen.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMAsmPrinter.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMDebugInfoDWARF.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMCFGuard.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMGlobalISel.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMSelectionDAG.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMCodeGen.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMTarget.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMBitWriter.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMScalarOpts.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMAggressiveInstCombine.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMInstCombine.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMTransformUtils.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMAnalysis.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMObject.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMBitReader.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMMCParser.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMTextAPI.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMProfileData.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMCore.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMRemarks.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMBitstreamReader.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMAArch64Disassembler.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMAArch64Desc.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMAArch64Info.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMAArch64Utils.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMMCDisassembler.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMMC.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMBinaryFormat.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMDebugInfoCodeView.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMDebugInfoMSF.a /Users/ondrej/mambaforge/envs/lf/lib/libLLVMSupport.a -lz -lm /Users/ondrej/mambaforge/envs/lf/lib/libLLVMDemangle.a 

They look pretty much the same.

On your computer, can you try to compile this simple program:

#include <iostream>
#include <string>

int main() {
    std::string x;
    x = "123";
    std::cout << x << std::endl;
    return 0;
}

with

/opt/homebrew/Library/Homebrew/shims/mac/super/clang++ a.cpp
./a.out

And see if it works?

@kjelljorner
Copy link
Author

kjelljorner commented Jun 4, 2022

I get this with the homebrew clang

(base) kjelljorner@dhcp-45 c++ % /opt/homebrew/Library/Homebrew/shims/mac/super/clang++ a.cpp
clang++: The build tool has reset ENV; --env=std required.

and this with Apple clang

(base) kjelljorner@dhcp-45 c++ % c++ a.cpp
(base) kjelljorner@dhcp-45 c++ % ls
a.cpp a.out
(base) kjelljorner@dhcp-45 c++ % ./a.out 
123

@certik
Copy link
Member

certik commented Jun 4, 2022

It looks like Homebrew has a modified clang++ compiler, or a wrapper script. It seems it does not link the C++ runtime library correctly. It would have to be investigated by creating a minimal reproducible example by executing the /opt/homebrew/Library/Homebrew/shims/mac/super/clang++ manually (not via cmake) to first compile the above simple file to an object file, then link to a binary and hopefully it fails in the same way. Then we can report it as a bug to Homebrew.

@kjelljorner
Copy link
Author

Might be related to this issue: Homebrew/homebrew-core#96915.

@certik
Copy link
Member

certik commented Jun 4, 2022

Is there a way to install homebrew without sudo? If it is, then I can install and help debug it. I just don't want to install anything that requires sudo for operation. So I use Conda and Spack frequently, both of which (now) work and do not require sudo.

@kjelljorner
Copy link
Author

I haven't tried this myself, but it seems possible: https://www.scivision.dev/macos-homebrew-non-sudo/

@awvwgk awvwgk mentioned this issue Sep 18, 2022
@awvwgk
Copy link
Member

awvwgk commented Sep 18, 2022

Resolved with #11

@awvwgk awvwgk closed this as completed Sep 18, 2022
@awvwgk
Copy link
Member

awvwgk commented Sep 18, 2022

Seems like we cannot build bottles for Monterey due to the linking issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants