5

I am developing executables from source code of llvm. So I downloaded the llvm source code from github.

I am trying everything from command line on Windows OS

I am following the link for libtooling in clang

http://clang.llvm.org/docs/LibASTMatchersTutorial.html

I tried with 2 options

Option First: I ran the below command
cmake -G Ninja "C:\Users\amith.ks\Desktop\Clang-llvm\llvm-project\llvm" -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DLLVM_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release

Everything Worked..

Second option: I wan to set cmake_c_compiler and cmake_cxx_compiler from command line.
I dont want to use cmake-gui so I run the below command
cmake -G Ninja "C:\Users\amith.ks\Desktop\Clang-llvm\llvm-project\llvm" -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DLLVM_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++

From out of no where error was thrown

CMake Error at cmake/modules/CheckAtomic.cmake:53 (message):
  Host compiler appears to require libatomic, but cannot find it.
Call Stack (most recent call first):
  cmake/config-ix.cmake:343 (include)
  CMakeLists.txt:617 (include)

When I saw the cmake error log It was saying this

LINK : fatal error LNK1104: cannot open file 'atomic.lib'

clang: error: linker command failed with exit code 1104 (use -v to see invocation)

ninja: build stopped: subcommand failed.

I searched my whole pc atomic.lib no where to be found.

How to solve this issue on windows? Please help me with answers.

5 Answers 5

4

I know why it fails. It's a bug in the LLVM's cmake files. In order to check if atomic.lib is required CheckAtomic.cmake tries compiling and linking a piece of code with atomic.lib. When it fails (because atomic.lib is not required and thus is not present) it falsely concludes that atomic.lib is needed. LLVM's cmake files is a hot mess with rarely fixed bugs. There are bugs staying there for years. I guess this is because nobody understands anymore how LLVM build system works.

Long story short, I couldn't find why CheckAtomic.cmake inserts atomic.lib while checking that it is not required. As a workaround I just unconditionally set HAVE_CXX_ATOMICS64_WITHOUT_LIB and HAVE_CXX_ATOMICS_WITHOUT_LIB to True in CheckAtomic.cmake:

set(HAVE_CXX_ATOMICS64_WITHOUT_LIB True)
set(HAVE_CXX_ATOMICS_WITHOUT_LIB True)
Sign up to request clarification or add additional context in comments.

2 Comments

These two Cmake settings helped me to solve llvm build on macOS11.3. My issue - github.com/vgorloff/swift-everywhere-toolchain/issues/111
Thanks for quoting this post in the commit! :)
2

Use clang-cl (or MSVC cl), they dont require lib atomic.

Comments

2

I'm trying to use Clang 11 (with MSVC ABI) to compile Clang 11. However, MSVC's headers won't compile in C++11 mode, which CheckAtomic.cmake uses:

set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11")

results in:

C:\Users\nyanpasu\code\llvm-project>clang  -Werror=unguarded-availability-new -std=c++11 uwu.cpp
In file included from uwu.cpp:1:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\atomic:19:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\xatomic.h:13:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\type_traits:11:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include\xstddef:283:22: error: 'auto' return
      without trailing return type; deduced return types are a C++14 extension
_NODISCARD constexpr auto _Unfancy(_Ptrty _Ptr) noexcept { // converts from a fancy pointer to a plain pointer
                     ^
1 error generated.

I don't know if this is a MSVC bug where it ships an header incompatible with C++11, or a Clang bug where it's using MSVC headers instead of its own.

In any case, changing c++11 to c++14 fixes this error.

Comments

0

As lulle mentioned, you need to use the right tools to compile. If you have installed Visual Studio, use the Developer Command prompt for Visual Studio instead of a regular cmd and you'll have the environment variables you need. It is located in your Visual Studio installation directory, under the Tools subdirectory.

For example:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat

Comments

0

I encountered the same error in macOS. Adding the CPP Libraries to the path solved it for me. You can try executing the following commands.

export SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"

export CPLUS_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.