How to build a library using cmake in windows - cmake

I've tried to build a library (called libiec61850) using cmake in windows. I have installed cmake and configured the "path" environment with the directory where I have installed the cmake. Then,
1-I created a subfolder called "build" in my library's directory
2- I copy the subfolder directory in the command line and type
cmake -G "Visual Studio 14 2015" and got many errors as follows:
- la génération a démarré
- echec de la build
- Cmakeoutput.log : "The system is: Windows - 6.1.7601 - AMD64"
See the attached file.
Please, you help will be precious.error_cmake_windows

I just looked up the library and tried it out myself, and I got it to work.
I normally use NMake to compile Visual Studios programs. If you'd like to use the same, you need to make sure that the MSVC environment is set up properly before using it. I normally run vcvarsall.bat in cmd first like so:
D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat
You could do the same wherever your vcvarsall.bat file is in your Visual Studio 2015 folders (I used Visual Studio 2017, but it should work fine with Visual Studio 2015 as well).
Next, these were the commands that I used and their respective outputs:
D:\Users\patrick\src\vs2017>cd libiec61850
D:\Users\patrick\src\vs2017\libiec61850>mkdir build
D:\Users\patrick\src\vs2017\libiec61850>cd build
D:\Users\patrick\src\vs2017\libiec61850\build>cmake .. -G "NMake Makefiles"
-- The C compiler identification is MSVC 19.11.25547.0
-- The CXX compiler identification is MSVC 19.11.25547.0
-- Check for working C compiler: D:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503
/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: D:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503
/bin/Hostx64/x64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: D:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.255
03/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: D:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.255
03/bin/Hostx64/x64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for clock_gettime in rt
-- Looking for clock_gettime in rt - not found
-- Check if the system is big endian
-- Searching 16 bit integer
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of unsigned short
-- Check size of unsigned short - done
-- Using unsigned short
-- Check if the system is big endian - little endian
server-example-logging: sqlite not found
-- Generating RC file : D:/Users/patrick/src/vs2017/libiec61850/build/src/version.rc
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Failed
-- Performing Test COMPILER_HAS_DEPRECATED
-- Performing Test COMPILER_HAS_DEPRECATED - Success
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Users/patrick/src/vs2017/libiec61850/build
D:\Users\patrick\src\vs2017\libiec61850\build>nmake
Microsoft (R) Program Maintenance Utility Version 14.11.25547.0
Copyright (C) Microsoft Corporation. All rights reserved.
Scanning dependencies of target iec61850
[ 0%] Building CXX object src/CMakeFiles/iec61850.dir/common/string_map.c.obj
string_map.c
It then continued compiling.
Try all of that out. If you make a build directory, you probably need to 'cd' into it, and then run cmake with a '..' to indicate that the CMakeLists.txt directory is one directory up. Let me know if you can't use NMake or if it doesn't work.

Related

cmake and clang++ windows build instead of MSVC

I am trying to create a build environment using cmake and i have both MSVC and clang installed on my system.
When I run cmake with the default settings it detectts MSVC as my cxx compiler.
However, I would like to use clang++ instead.
I tried specifying clang like this: cmake -DCMAKE_CXX_COMPILER=clang++
but even after that it still uses MSVC..
How can I tell it to use clang instead?
You should provide the complete path of the clang compiler. E.g.,
cmake -DCMAKE_CXX_COMPILER=/path/to/clang++ -DCMAKE_C_COMPILER=/path/to/clang
First of all you need to ensure that CLANG is visible through a regular command prompt window. If not then you need to put the CLANG installed directory path to your PATH environment variable.
In my case I had clang-cl installed through Visual Studio but it was still not visible through a regular command prompt window.
Regular command prompt window output:
>clang-cl -v
'clang++' is not recognized as an internal or external command,
operable program or batch file.
Developer command prompt window output:
>clang-cl -v
clang version 12.0.0
Target: i686-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\Llvm\bin
Moreover, I simply use the following command: cmake -T ClangCL to generate the project on a Windows 10 PC with Visual Studio 2019 Professional Edition.
This is the output I get:
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
-- The C compiler identification is Clang 12.0.0 with MSVC-like command-line
-- The CXX compiler identification is Clang 12.0.0 with MSVC-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/Llvm/x64/bin/clang-cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/Llvm/x64/bin/clang-cl.exe - skipped
I have tested the same on another Windows 10 PC with Visual Studio 2022 Community Edition and it works fine too.

How to use cmake on windows with vs2019 and custom installed llvm?

I found someone mentioned to use such command line to use cmake with vs2019 and llvm toolset:
cmake -G "Visual Studio 2019" -T ClangCL
However, this would use the llvm version, which is 11.0 for now, was installed by the visual studio instanller.
I want to use a new version, thus 12.0, of llvm which I already installed somewhere else but I don't know how to make cmake and vs to use that.
UPDATE:
What I tried to set the compiler via command line:
E:\my_proj>cmake -G "Visual Studio 16 2019" -A x64 -T "ClangCL" -DCMAKE_C_COMPILER="C:\Program Files\LLVM\bin\clang.exe" -DCMAKE_CXX_COMPILER="C:\Program Files\LLVM\bin\clang++.exe" .
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19042.
-- The C compiler identification is Clang 11.0.0 with MSVC-like command-line
-- The CXX compiler identification is Clang 11.0.0 with MSVC-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/Llvm/x64/bin/clang-cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/Llvm/x64/bin/clang-cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
As you could see the cmake picked the clang from the vs installed location and ignored the command line.
As described below, setting CMAKE flags explicitly has no effect when using VS generator. Thus choosing the default compiler installed by Visual Studio installer.
The VS generator produces .vcxproj files and uses MSBuild to actually
drive the build. The values of CMAKE_{C,CXX}_COMPILER are computed
automatically from the compiler MSBuild chooses so setting them has no
effect.

Qt-Cretor + CMake insists on using MSVC when I want to use MinGW

I am trying to build a CMake project with MinGW. I have installed MinGW 8.1 through the Qt installer. The CMakeList is unchanged from how Qt Creator created it when creating the project.
When running CMake, I can see how Qt Creator passes the compiler and linker's paths to CMake and how CMake completely ignores them.
Führe C:\Program Files\CMake\bin\cmake.exe -S [snip] -B [snip] "-DCMAKE_BUILD_TYPE:String=Debug" "-DQT_QMAKE_EXECUTABLE:STRING=C:/Qt/5.15.1/mingw81_64/bin/qmake.exe" "-DCMAKE_PREFIX_PATH:STRING=C:/Qt/5.15.1/mingw81_64" "-DCMAKE_C_COMPILER:STRING=C:/Qt/Tools/mingw810_64/bin/gcc.exe" "-DCMAKE_CXX_COMPILER:STRING=C:/Qt/Tools/mingw810_64/bin/g++.exe" in [snip] aus.
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19041.
-- The CXX compiler identification is MSVC 19.24.28314.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
CMAKE_BUILD_TYPE
CMAKE_C_COMPILER
QT_QMAKE_EXECUTABLE
Here I am using a system install of CMake, but the output is unchanged when using the CMake installed with Qt Creator. The CMake generator for the selected kit is set to MinGW Makefiles in the Qt Creator settings. Running CMake manually, without Qt Creator, allows me to configure the project. (although it still doesn't compile because of a linker error, that I expect to be independent of this problem)
It seems there is a caching issue. The caching is done by CMake (CMakeCache.txt) and by QtCreator (CMakeLists.txt.user) itself.
Maybe this helps:
Close QtCreator (by closing QtCreator the CMakeLists.txt.user file is saved or generated if the file don't exist)
delete QtCreator's CMakeLists.txt.user
the build folder
Open the project again and select the desired kit.

Assimp compilation errors Win10 + Visual studio 2017 community

I can't get assimp compiled on my laptop (Windows 10, Visual studio 2017 community). Everything compiles nice on my work PC.
I just clone repo:
git clone https://github.com/assimp/assimp.git
cd assimp
mkdir build
cd build
cmake ..
here out of cmake command
-- Building for: Visual Studio 15 2017
-- The C compiler identification is MSVC 19.14.26428.1
-- The CXX compiler identification is MSVC 19.14.26428.1
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x86/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x86/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x86/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x86/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Shared libraries enabled
-- Looking for DirectX...
-- DirectX_PREFIX_PATH changed.
-- Could not locate DirectX
-- Looking for ZLIB...
-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
-- Could not locate ZLIB
-- compiling zlib from souces
CMake Deprecation Warning at contrib/zlib/CMakeLists.txt:8 (cmake_policy):
The OLD behavior for policy CMP0048 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of off64_t
-- Check size of off64_t - failed
-- Looking for fseeko
-- Looking for fseeko - not found
-- Looking for unistd.h
-- Looking for unistd.h - not found
-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
-- Could NOT find rt (missing: RT_LIBRARY)
-- Enabled formats: AMF 3DS AC ASE ASSBIN ASSXML B3D BVH COLLADA DXF CSM HMP IRRMESH IRR LWO LWS MD2 MD3 MD5 MDC MDL NFF NDO OFF OBJ OGRE OPENGEX PLY MS3D COB BLEND IFC XGL FBX Q3D Q3BSP RAW SIB SMD STL TERRAGEN 3D X X3D GLTF 3MF MMD
-- Disabled formats:
-- Could NOT find IL (missing: IL_LIBRARIES IL_INCLUDE_DIR)
CMake Warning at CMakeLists.txt:439 (MESSAGE):
Build of assimp_qt_viewer is disabled. Unsatisfied dendencies: Qt5 DevIL
-- Configuring done
-- Generating done
-- Build files have been written to:
this makes solution for my Visual studio, which I'm trying to build using Build All menu. I get following errors:
Severity Code Description Project File Line Suppression State
Error C2065 'AI_IMPORT_IFC_DEFAULT_SMOOTHING_ANGLE': undeclared identifier assimp
Error (active) E0020 identifier "AI_CONFIG_GLOBAL_SCALE_FACTOR_KEY" is undefined assimp
Error C2065 'AI_CONFIG_GLOBAL_SCALE_FACTOR_KEY': undeclared identifier assimp
But if I try to navigate to this define - Intellisense allow me to do this. I see this defines. What am I doing wrong, please help?

Errors when building TensorFlow with CMake on Windows 10

I am attempting a TensorFlow CMake build on Windows, but I'm running into problems.
First, I run
C:\work\tensorflow\tensorflow\contrib\cmake\build>cmake .. -A x64 -DCMAKE_BUILD_TYPE=Release ^
More? -DSWIG_EXECUTABLE=C:/Program1/swigwin-3.0.12/swig.exe ^
More? -DPYTHON_EXECUTABLE=C:/Python3.5/python.exe ^
More? -DPYTHON_LIBRARIES=C:/Python3.5/libs/python35.lib ^
More? -Dtensorflow_ENABLE_GPU=ON ^
More? -DCUDNN_HOME="C:\Program1\cudnn\cuda"
and get the output
-- Building for: Visual Studio 14 2015
-- The C compiler identification is MSVC 19.0.24215.1
-- The CXX compiler identification is MSVC 19.0.24215.1
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test COMPILER_OPT_ARCH_NATIVE_SUPPORTED
-- Performing Test COMPILER_OPT_ARCH_NATIVE_SUPPORTED - Failed
-- Found CUDA: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0 (found suitable version "8.0", minimum required is "8.0")
-- Found PythonInterp: C:/Python3.5/python.exe (found version "3.5")
-- Found PythonLibs: C:/Python3.5/libs/python35.lib (found version "3.5.0")
-- Found SWIG: C:/Program1/swigwin-3.0.12/swig.exe (found version "3.0.12")
-- Configuring done
-- Generating done
-- Build files have been written to: C:/work/tensorflow/tensorflow/contrib/cmake/build
The only troubling line here is -- Performing Test COMPILER_OPT_ARCH_NATIVE_SUPPORTED - Failed, which I don't really know what it means or whether it's a serious problem. (Is it?)
Second, I run
MSBuild /p:Configuration=Release tf_tutorials_example_trainer.vcxproj
and this gives me several errors:
"C:\work\tensorflow\tensorflow\contrib\cmake\build\tf_tutorials_example_trainer.vcxproj" (default target) (1) ->
"C:\work\tensorflow\tensorflow\contrib\cmake\build\tf_core_gpu_kernels.vcxproj" (default target) (90) ->
(CustomBuild target) ->
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(171,5): error MSB6006: "cmd.exe" exited with code 1. [C:\work\tensorflow\tensorflow\contrib\cmake\build\tf_core_gpu_kernels.vcxproj]
"C:\work\tensorflow\tensorflow\contrib\cmake\build\tf_tutorials_example_trainer.vcxproj" (default target) (1) ->
"C:\work\tensorflow\tensorflow\contrib\cmake\build\tf_core_kernels.vcxproj" (default target) (91) ->
(ClCompile target) ->
c:\work\tensorflow\tensorflow\core\kernels\cuda_solvers.h(24): fatal error C1083: Cannot open include file: 'cuda/include/cusolverDn.h': No such file or directory (compiling source file C:\work\tensorflow\tensorflow\core\kernels\cholesky_op.cc) [C:\work\tensorflow\tensorflow\contrib\cmake\build\tf_core_kernels.vcxproj]
c:\work\tensorflow\tensorflow\core\kernels\cuda_solvers.h(24): fatal error C1083: Cannot open include file: 'cuda/include/cusolverDn.h': No such file or directory (compiling source file C:\work\tensorflow\tensorflow\core\kernels\cuda_solvers.cc) [C:\work\tensorflow\tensorflow\contrib\cmake\build\tf_core_kernels.vcxproj]
c:\work\tensorflow\tensorflow\contrib\cmake\build\external\eigen_archive\eigen\src\core\coreevaluators.h(1052): fatal error C1060: compiler is out of heap space (compiling source file C:\work\tensorflow\tensorflow\core\kernels\svd_op_float.cc) [C:\work\tensorflow\tensorflow\contrib\cmake\build\tf_core_kernels.vcxproj]
696 Warning(s)
4 Error(s)
I don't know relative to which folder MSBuild is looking for cuda/include/cusolverDn.h. I don't have any folder called cuda in c:\work\tensorflow\tensorflow\core\kernels, and no file named cusolverDn.h exists anywhere in the tensorflow repository. (I do have the file cusolverDn.h in my CUDA install directory, though.) So,
What can I do to make MSBuild find cusolverDn.h? And what can I do to prevent the compiler from running out of heap space?
In a previous attempt to run the last command I also received the message
nvcc fatal : Microsoft Visual Studio configuration file 'vcvars64.bat' could not be found for installation at 'C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/../..'
Some recommend renaming a folder and a file in that folder. I can't really verify that this works right now since the problem temporarily seems to have disappeared (maybe masked by the "compiler is out of heap space" problem, which I didn't have before...).
Is renaming this file and this folder the correct solution?
As per tensorflow instructions check the following:
you must be running a 64 bit enabled Command Prompt for Visual Studio; you should run your msbuild.exe commands from such a prompt;
install CUDNN's Nvidia zio file and append its /bin/ directory to your PATH environment variable, it should contains two entries similar to the following:
D:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin
D:\YOURCUDNNPATH\cuda\bin
check whether both git and cmake command are available in the PATH; check whether you could run those commands from your prompt;