Unable to set compiler in CMake - c

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:

Related

Build curl source code with Visual Studio Developer command line (NMAKE)

I want to use libcurl in my C program. So I have curl-7.87.0 but some errors happen in x64 build.
in x86 build does not have any errors but its have libcurl.lib not libcurl.a in libs.
To build in Visual Studio 2022 Developer command prompt:
cd curl-7.87.0\winbuild
nmake /f Makefile.vc mode=dll VC=10 debug=no machine=x64
I guss "developer command prompt" uses x86 nmake. Like in image:"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\ HostX86\x86 \nmake.exe"
What can I do to solve it?
Thanks for any help.
I Copied all files of HostX64\x64 to HostX86\x86 and build again but again those errors.

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 solve libatomic issue in windows?

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

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!

Reference error while compiling C file in VS2010 command-prompt

I have VS 2010 installed on my system and i was trying to compile a simple hello.c in VS command prompt. The compilation gave an error.
Fatal Error C1083: Cannot open include file: 'stdio.h' no such file, folder exist
Why this error is coming ?? Does VS2010 not include reference files/assemblies for C.
VS 2010 certainly does contain the standard headers. You should check that your command prompt environment is set up correctly. There should be an environment variable named INCLUDE that has a directory similar to the cfollowing (among other directories) in it:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE
that directory (the name may vary slightly, for example depending on if your machine is a 64-bit OS of not) should include stdio.h
If you don't have such a directory in your environment, then you're not setting up the environment correctly. You should use on of the "Visual Studio Command Prompt" shortcuts that VS installs, or simply run
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat
With the appropriate parameter to get the environment you want (x86 or amd64 for example).
If the INCLUDE environment variable does have an entry like that, but the stdio.h file doesn't exist, then you might need to reinstall VS.
I had a similar problem as the OP the VC folder was missing most of the files. I tried both repairing and uninstalling/reinstalling VS 2010 but neither worked.
What worked for me was installing the Microsoft Visual C++ 2010 Redistributable Package (x86).Microsoft Visual C++ 2010 Redistributable Package (x86)
There are so many versions of so much Windows system code that it's easy for a path to become invalid.
In my case:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Include
and
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib
needed to be changed to::
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include
and
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib
i.e. v7.1A -> v7.0A (don't ask why, it just part of the everyday, tiresome task of dealing with Microsoft!).
I had the same problem. The file stdio.h did not exist in folder include. I removed VS 2010 using the Control Panel then reinstalled, but this didn't solve the problem.
I then used the VS 2010 installation CD to remove all of VS 2010, and manually removed anything leftover by Control Panel. I then installed VS 2010 professional again. The problem was solved.

Resources