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

Question: Support for latest LLVM on Mac #59

Open
patrickmay opened this issue Mar 22, 2019 · 11 comments
Open

Question: Support for latest LLVM on Mac #59

patrickmay opened this issue Mar 22, 2019 · 11 comments

Comments

@patrickmay
Copy link

I'm trying to build on Mac OS 10.14.2 (Mojave). I installed LLVM with homebrew and set LLVM_DIR to /usr/local/opt/llvm. When I run "cmake .." in the build directory, I get this error:

CMake Error at CMakeLists.txt:7 (find_package):
Could not find a configuration file for package "LLVM" that is compatible
with requested version "7.0".

The following configuration files were considered but not accepted:

/usr/local/opt/llvm/lib/cmake/llvm/LLVMConfig.cmake, version: 8.0.0
/usr/local/opt/llvm/lib/cmake/llvm/llvm-config.cmake, version: unknown

Do I need to install a different version?

@rpav
Copy link
Owner

rpav commented Mar 22, 2019

Probably change the requested version to 8.0 in CMakeLists.txt. I haven't built LLVM 8 yet though, and some minor updates are usually needed with new major releases.

@patrickmay
Copy link
Author

Thanks. That got me past the cmake stage, but make gives this:

Scanning dependencies of target c2ffi
[ 7%] Building CXX object CMakeFiles/c2ffi.dir/src/AST.cpp.o
[ 15%] Building CXX object CMakeFiles/c2ffi.dir/src/Decl.cpp.o
[ 23%] Building CXX object CMakeFiles/c2ffi.dir/src/Expr.cpp.o
[ 30%] Building CXX object CMakeFiles/c2ffi.dir/src/OutputDriver.cpp.o
[ 38%] Building CXX object CMakeFiles/c2ffi.dir/src/Template.cpp.o
/Users/Patrick/projects/c2ffi/src/Template.cpp:52:33: error: non-const lvalue
reference to type 'clang::Expr::EvalResult' cannot bind to a value of
unrelated type 'llvm::APSInt'
expr->EvaluateAsInt(i, ctx);
^
/usr/local/opt/llvm/include/clang/AST/Expr.h:604:34: note: passing argument to
parameter 'Result' here
bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx,
^
/Users/Patrick/projects/c2ffi/src/Template.cpp:111:37: error: non-const lvalue
reference to type 'clang::Expr::EvalResult' cannot bind to a value of
unrelated type 'llvm::APSInt'
expr->EvaluateAsInt(i, ctx);
^
/usr/local/opt/llvm/include/clang/AST/Expr.h:604:34: note: passing argument to
parameter 'Result' here
bool EvaluateAsInt(EvalResult &Result, const ASTContext &Ctx,
^
2 errors generated.
make[2]: *** [CMakeFiles/c2ffi.dir/src/Template.cpp.o] Error 1
make[1]: *** [CMakeFiles/c2ffi.dir/all] Error 2
make: *** [all] Error 2

Should I drop back to LLVM 7?

@rpav
Copy link
Owner

rpav commented Mar 22, 2019

Probably if you need c2ffi and you don't want to figure out what changed in LLVM 8; I haven't had a chance to build and Arch is still on 7.0.1 at the moment.

@patrickmay
Copy link
Author

Dropping back worked, thanks.

@rpav
Copy link
Owner

rpav commented Apr 1, 2019

Finally got updated to 8.0. ;)

@patrickmay
Copy link
Author

I'll give it a try this week.

@noelbenz
Copy link

Was able to build c2ffi on Mojave 10.14 just with these steps

brew install llvm
git clone https://github.com/rpav/c2ffi.git
cd c2ffi/
mkdir build
cd build/
LLVM_DIR=/usr/local/opt/llvm/ cmake ..
make

Thanks :)

@devxpy
Copy link

devxpy commented Sep 15, 2020

I also had to set LIBRARY_PATH while running make

LIBRARY_PATH=/usr/local/opt/llvm/Toolchains/LLVM10.0.1.xctoolchain/usr/lib/ make

Otherwise, I got the following error -

$ make
[  7%] Linking CXX executable bin/c2ffi
ld: library not found for -lclang-cpp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [bin/c2ffi] Error 1
make[1]: *** [CMakeFiles/c2ffi.dir/all] Error 2
make: *** [all] Error 2
/Users/dev/Tools/c2ffi/b

@rpav
Copy link
Owner

rpav commented Mar 24, 2021

If someone would like to submit macos-specific instructions to include in the README, that might be the best fix here. Alternatively some slightly better detection of the proper clang in cmake, but I have no way to test on mac myself.

@gwerbin
Copy link

gwerbin commented Aug 28, 2021

I tried to get this to build on MacOS 10.14 by pinning to LLVM 11, as per the warning that 12 was not yet stable and 10 was deprecated, but couldn't get it to work. Would love some ideas!

In my case, it looks like Clang is assuming that the linker has a -platform_version option, which doesn't actually appear to exist.

This appears be a known issue with Homebrew: Homebrew/homebrew-core#52461. But I am mentioning it here because I'm probably not the only person to run into this problem! According to the issue (closed as "stale"? huh?) this might not actually be fixable as Mojave proceeds towards EOL. I've been avoiding upgrading to Big Sur out of fear of breaking my work computer, but I might be forced to do it after this.

This is what I ran:

brew update
brew install llvm@11
brew upgrade llvm@11

# Homebrew: For compilers to find llvm you may need to set:
#   export LDFLAGS="-L/usr/local/opt/llvm/lib"
#   export CPPFLAGS="-I/usr/local/opt/llvm/include"
export LDFLAGS="-L/usr/local/opt/llvm@11/lib"
export CPPFLAGS="-I/usr/local/opt/llvm@11/include"

# Do I need or want this?
# Homebrew: To use the bundled libc++ please add the following LDFLAGS:
#   LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"
#export LDFLAGS="${LDFLAGS} -L/usr/local/opt/llvm@11/lib -Wl,-rpath,/usr/local/opt/llvm@11/lib"

# https://github.com/rpav/c2ffi/issues/59#issuecomment-692696371
export LIBRARY_PATH=/usr/local/opt/llvm@11/Toolchains/LLVM11.1.0.xctoolchain/usr/lib

# These options are apparently necessary so that Cmake can find the right
# files.
cmake \
	-DCMAKE_PREFIX_PATH="/usr/local/opt/llvm@11" \
	-DCMAKE_CXX_COMPILER="/usr/local/opt/llvm@11/bin/clang++" \
	-DCMAKE_C_COMPILER="/usr/local/opt/llvm@11/bin/clang" \
	..

And the error output:

-- Config: -Release
-- The C compiler identification is Clang 11.1.0
-- The CXX compiler identification is Clang 11.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /usr/local/opt/llvm@11/bin/clang
-- Check for working C compiler: /usr/local/opt/llvm@11/bin/clang - broken
CMake Error at /usr/local/Cellar/cmake/3.21.1/share/cmake/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    "/usr/local/opt/llvm@11/bin/clang"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /Users/gregwerbin/src/c2ffi/build/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/local/bin/gmake -f Makefile cmTC_841a5/fast && /usr/local/bin/gmake  -f CMakeFiles/cmTC_841a5.dir/build.make CMakeFiles/cmTC_841a5.dir/build
    gmake[1]: Entering directory '/Users/gregwerbin/src/c2ffi/build/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_841a5.dir/testCCompiler.c.o
    /usr/local/opt/llvm@11/bin/clang   -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk -MD -MT CMakeFiles/cmTC_841a5.dir/testCCompiler.c.o -MF CMakeFiles/cmTC_841a5.dir/testCCompiler.c.o.d -o CMakeFiles/cmTC_841a5.dir/testCCompiler.c.o -c /Users/gregwerbin/src/c2ffi/build/CMakeFiles/CMakeTmp/testCCompiler.c
    Linking C executable cmTC_841a5
    /usr/local/Cellar/cmake/3.21.1/bin/cmake -E cmake_link_script CMakeFiles/cmTC_841a5.dir/link.txt --verbose=1
    /usr/local/opt/llvm@11/bin/clang  -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names -L/usr/local/opt/llvm@11/lib  CMakeFiles/cmTC_841a5.dir/testCCompiler.c.o -o cmTC_841a5
    ld: unknown option: -platform_version
    clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
    gmake[1]: *** [CMakeFiles/cmTC_841a5.dir/build.make:100: cmTC_841a5] Error 1
    gmake[1]: Leaving directory '/Users/gregwerbin/src/c2ffi/build/CMakeFiles/CMakeTmp'
    gmake: *** [Makefile:127: cmTC_841a5/fast] Error 2

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:5 (project)

-- Configuring incomplete, errors occurred!
See also "/Users/gregwerbin/src/c2ffi/build/CMakeFiles/CMakeOutput.log".
See also "/Users/gregwerbin/src/c2ffi/build/CMakeFiles/CMakeError.log".

@gwerbin
Copy link

gwerbin commented Sep 29, 2021

Update on the above: it might have been a PEBCAK issue (maybe the wrong Git branch was checked out?), or something wrong with my specific system.

But I got it working on Big Sur, and did not need to set LIBRARY_PATH. See: #100

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

No branches or pull requests

5 participants