How to solve libatomic issue in windows? - c

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.

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)

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

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.

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

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

Related

compile putty 0.78 for windows

in the new version of putty there is no Makefile.vc or project file for visual studio. How can I compile putty under visual studio 2019? can someone help me?
link to zipped source
I tried to open the windows folder in visual studio with the following error:
Severity Code Description Project File Line Suppression State
Error CMake Error at C:\Usersuser\Downloads\Compressed\putty-src\windows\CMakeLists.txt:3 (add_sources_from_current_dir):
Unknown CMake command "add_sources_from_current_dir". C:\Users\user\Downloads\Compressed\putty-src\windows\CMakeLists.txt 3
You don't need to open Visual Studio or any IDE to compile the executables.
Download cmake and make sure Visual C compiler is installed.
Unzip the .zip file, open a command prompt where the readme and CMakeLists.txt reside
Then, as the readme states:
run these commands in the source directory:
cmake .
cmake --build .
In the Debug directory, you'll find a lot of .exe files.
Then, to install in the simplest way on Linux or Mac:
cmake --build . --target install
I didn't need that part. I suppose that it copies the executables & other files somewhere in the path.
Problem with creating a distro using Microsoft compiler is that the executables then require a lot of Microsoft runtime DLLs. For instance if you deploy the executables on other machines it may not work.
An alternative is to use gcc and make to build the executables.
First:
install a recent gcc for windows
install make
Installing a recent MinGW distribution should do it. Personally I used another gcc distribution so I had to grab make too.
Now, I followed Setting default compiler in CMake, the key part being to enable mingw makefiles: -G "MinGW Makefiles", else cmake ignores your compiler requirements and keeps on using Microsoft compiler.
cmake -DCMAKE_MAKE_PROGRAM=/path/to/make/make.exe -DCMAKE_C_COMPILER=/path/to/gcc/gcc.exe -G "MinGW Makefiles" .
Note that specifying full paths require that / are used. Backslashes conflict with escaping in cmake/make files.
Then
cmake --build .

How to use VC++ compiler in command line(Windows)?

I tried to use VC++ commandline, instead of MinGW compiler for windows system programming. I wrote a simple hello world program and tried to compile it, then i got this error message.
test2.c(1): fatal error C1083:'stdio.h': No such file or directory
I also added "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\Hostx86\x86" directory (where c1.dll lives) to the System Envionment Variable(PATH).
How can I fix this issue? Other tutorials don't give much information about VC++. (A lot of MinGW compiler tutorial out there btw)
You should use visual studio command line if you want to compile or run program with the help of vc++ compiler.
Else all information related to setting environment variables ETC. resides in this MSDN document.

Unable to set compiler in CMake

Can someone help me set up compiler for CMake and thus help me understand how all this works? I intend to use point cloud library, but I'll use more simple example here (which is also not working) so I could explain my problem better.
I have next components:
Visual Studio 10 (C:\Program Files (x86)\Microsoft Visual Studio 10.0)
CMake 3.7.2 (C:\Program Files\CMake)
"hellocmake" project - complete file structure as presented here (C:\Users\my_name\Documents\Visual Studio 2010\Projects\hellocmake)
I tried to run CMake Gui, pointed to a source and build folders, configured for "Visual Studio 10 2010 Win 64" and run out as expected with:
"The C compiler identification is unknown
The CXX compiler identification is unknown"
I understand I need to setup compiler, but I'm not sure at this point what should I do. I tried so far:
From visual studio open command prompt, navigate to CMake and run "cmake -D CMAKE_CXX_COMPILER="g++" CMAKE_CC_COMPILER="gcc"
Output: "The C compiler identification is unknown. The CXX compiler identification is unknown. No CMAKE_C_COMPILER could be found"
g++ was not a full path and was not found in PATH
I added C:\Program Files\CMake\bin and C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\cl.exe to Environment Variables -> PATH and tried all again. I have the same output as above.
Putted these lines in CMakeLists.txt inside C:\Program Files\CMake:
SET(CMAKE_C_COMPILER C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/cl.exe)
SET(CMAKE_CXX_COMPILER C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/cl.exe)
and ended up with the same "No CMAKE_C_COMPILER could be found" output.
Also tried to put a quotes for CMAKE_C_COMPILER path, to use CMAKE_CXX_COMPILER:PATH in command prompt, to run CMake Gui as admin and nothing works.
I really don't know what to try more now. Also, I'm not sure how all this work after so many unsuccessful trials.
Any help will be highly appreciated. Thanks!
EDIT:

Windows 10: Clang, "stdio.h" not found [duplicate]

This question already has answers here:
clang/clang++ doesn't find C/C++ headers in windows?
(3 answers)
Closed 6 years ago.
I have installed LLVM and Clang-3.9.0 on Win10. I have MinGW installed as well.
I have put my C code in 'D:' drive.
I can use gcc and g++ to compile my code. But when I use clang I get:
clang -cc1 version 3.9.0 based upon LLVM 3.9.0 default target x86_64-pc-windows-msvc
ignoring duplicate directory "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A"
ignoring duplicate directory "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A"
#include "..." search starts here:
#include <...> search starts here:
C:\Program Files\LLVM\bin\..\lib\clang\3.9.0\include
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A
End of search list.
hello.c:1:10: fatal error: 'stdio.h' file not found
#include "stdio.h"
^
1 error generated.
As I can use gcc and g++, my environment variable settings are right. But then I am not able to force clang to look into C:\MinGW.
I tried copy pasting the whole MinGW folder manually in C:\Program Files\LLVM\bin\ and \lib\clang\3.9.0\include separately, but it did not work. I wanted to try this, but in 3.9.0 I cannot find, clang/lib/Frontend/InitHeaderSearch.cpp.
Anyway, is there a work around?
Note: I have tried <stdio.h> and "stdio.h" both, and I still get the same error.
Okay, so until now things with Clang/LLVM in Windows. Starting 3.7 or so things have changed: Clang/LLVM binaries are built with Visual Studio and for Visual Studio. No need for MinGW, as far as I understand.
So now install LLVM via the binary files available. Make sure that you have VS2015 (or 2013 and more) previously installed. When LLVM is being installed add it in the path when prompted.
Now after all that has been done, start the developer commander prompt for VS2015 (got to start -> Visual Studio 2015 -> Developer Commander Prompt for VS2015. I guess, you will choose whatever suits for your requirements). Now from here try using the clang commands listed on LLVM website.
However commands like lli, llvm-dis and llc still cannot be ran.
Also, LLVM website still says that GNU tools for windows are needed. But I do not know what for!

CMake Error at 3rdparty/libtiff/CMakeLists.txt:27 (ocv_include_directories): Unknown CMake command "ocv_include_directories"

Right, so I'm trying to build a project in VS2012 and I've been chasing down various errors for the past 2 days...I'm coming in on a lot of legacy code, and it deals with OpenCV2.1
So after chasing down all the 3rd party files I needed, I now get the following error:
error C1021: invalid preprocessor command 'cmakedefine' c:\opencv2.1\3rdparty\libtiff\tif_config.h
Line:
/* Define to 1 if you have the <assert.h> header file. */
#cmakedefine HAVE_ASSERT_H
Which the only help I found here:
cannot compile allegro using visual c++
suggesting that I need to rebuild OpenCV with cmake. At which point I get the error:
CMake Error at 3rdparty/libtiff/CMakeLists.txt:27 (ocv_include_directories): Unknown CMake command "ocv_include_directories".
In the visual editor. So I traced that to here.
So I run it in command line as:
cmake C:/OpenCV2.1 -DBUILD_SAMPLES=ON
Which spits out more errors:
CMake Error at 3rdparty/libtiff/CMakeLists.txt:5 (project):
project PROJECT called with incorrect number of arguments
CMake Error at 3rdparty/libtiff/CMakeLists.txt:27 (ocv_include_directories):
Unknown CMake command "ocv_include_directories".
I can't find any documentation for ocv_include_directories. I've tried following multiple OpenCV cmake tutorials, but haven't had any success.
It turns out the problem was actually that I had visual studio 2012, and the codebase I was working in was visual studio 2008 built. There was no possibility to ever track down all of these errors. Solution was to uninstall 2012 and install 2008.

Resources