I am trying to use CMake on Windows 10. I create a Hello world project:
CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
add_executable(simple-program main.cpp)
main.cpp
#include <iostream>
int main()
{
std::cout << "Hello, World!\n";
}
Then I open the project with CMake gui, choose Visual Studio 10 2010 Win64 generator and get this error when trying to generate the project:
testCCompiler.c : fatal error C1033: cannot open program database 'c:\work\prj\simple-program\build\cmakefiles\cmaketmp\cmtc_983e7.dir\debug\vc100.pdb'
Full output.
As I understood the problem, due to Zi option and no Fd, which cmake sets for the sample project, the project is trying to find vc100.pdb database and there is no one because the generator didn't make it.
I've tried the x86 generator. Other cmake versions (3.6, 3.13, 3.12). And I get the same result when using the console. My VS 2010 should be ok - it generates the PDB when I create the project from it.
Thank you!
https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/fatal-error-c1033?view=vs-2017
Fatal Error C1033
This error can be caused by a disk error, a temporary lock created by an anti-virus program, a previous debugger instance that has not fully shut down, or parallel build mspdbsrv.exe processes that attempt to access the same file, among other possible causes.
NOTE:
I couldn't find the error codes for VS2010 on the Microsoft website. I don't think VS2010 is supported anymore and may not make working programs on Windows 10.
The problem was because I created build folder in WSL console. So it can be caused by any kind emulators like Cygwin, etc. Hope it will help someone.
Just build your generated project in Debug mode:
MSBuild ALL_BUILD.vcxproj /p:Configuration=Debug
If you want to create a Release and install it with PDB files just all:
list(APPEND INSTALL_TARGETS simple-program)
list(APPEND INSTALL_TARGETS_PDB simple-program)
# Install
install(TARGETS ${INSTALL_TARGETS}
RUNTIME DESTINATION "${PROJECT_SOURCE_DIR}/bin"
LIBRARY DESTINATION "${PROJECT_SOURCE_DIR}/bin"
ARCHIVE DESTINATION "${PROJECT_SOURCE_DIR}/bin")
# Install *.pdb files
if(MSVC)
foreach(INSTALL_TARGET_PDB ${INSTALL_TARGETS_PDB})
install(FILES $<TARGET_PDB_FILE:${INSTALL_TARGET_PDB}> DESTINATION "${PROJECT_SOURCE_DIR}/bin")
endforeach()
endif()
Finall run CMake and build in RelWithDebInfo mode:
cmake -G "Visual Studio 10 2010 Win64"
MSBuild ALL_BUILD.vcxproj /p:Configuration=RelWithDebInfo
MSBuild INSTALL.vcxproj /p:Configuration=RelWithDebInfo
This will create simple-program.exe and simple-program.pdb files in your install dir.
Related
I was having this issue with a much larger project but I reproduced it with a quickly throw together example. Visual Studio correctly generates everything using CMake, and if I then go to the toolbar and select Build -> Build All it will successfully compile and link everything, and I can run the resulting executables from powershell... The Output from CMake is shown to be this:
According to the Visual Studio CMake documentation I should see an additional line stating: Target info extraction done.. I believe that is the core of my issue, but I am unsure why it is not occurring as everything else seems to work fine.
If I try to run (or debug) anything from Visual Studio itself, it simply says I need to select a "Startup Item", but none are available:
Looking at Visual Studio CMake documentation here, I should be able to simply go to the CMake Targets View in the solution explorer, and see all of my targets, but I do not see any:
While I should see (in this very simply example) a target for hello, given I have the following CMake structure:
Root CMakeLsits.txt file:
cmake_minimum_required(VERSION 3.9)
project(vira LANGUAGES CXX VERSION 0.9)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
add_subdirectory(src)
src/CMakeLists.txt:
add_executable(hello hello.cpp)
src/hello.cpp:
#include <iostream>
int main()
{
std::cout << "hello world!\n";
return 0;
}
I have been driven crazy by this as the people I've asked about it have simply reiterated what the Visual Studio documentation says, yet neither for this simple project, nor the larger actual project I've been working on, do any CMake targets ever show up. Meaning I'm unable to use any of the debugging features of Visual Studio, since I cannot select a startup item.
Am I doing anything incorrectly? Visual Studio clearly at least recognizes the CMakeLists.txt as it automatically generates everything, and will Build the project if I manually go to Build -> Build All. That has me even more confused as to why I'm experiencing this.
I have attempted even reinstalling Visual Studio from scratch, yet nothing has helped.
I am very new to CMake and try to build a minimum CMake file on Windows where I have installed Visual Studio 17 and 19. The C++ code is the bare minimum main.cpp:
#include<iostream>
int main()
{
std::cout << "Hello" << std::endl;
return 0;
}
The CMakeLists.txt file is also the minimum:
cmake_minimum_required(VERSION 3.1)
project(hello)
add_executable(${PROJECT_NAME} main.cpp)
When I run the CMake on the command line, I get this error and I do not know how to resolve it:
C:\SampleProject\build>cmake ./../src
-- Building for: Visual Studio 15 2017
CMake Error at CMakeLists.txt:3 (project):
Failed to run MSBuild command:
MSBuild.exe
to get the value of VCTargetsPath:
The system cannot find the file specified
By default VC++ tools aren't on the PATH, they are added to the PATH by the vcvarsall.bat script.
Run cmake from a "x64 Native Tools Command Prompt for VS 2019" (it's a shortcut to vcvarsall.bat that Visual Studio installs in the Start Menu).
Bonus note:
When not using Visual Studio integration, you might want to consider Ninja as the alternative build system to MSBuild. It's more CMake-friendly because it doesn't require the Debug/Release duality of configuration (which is the source of headache when working with CMake).
Download ninja.exe, add it to the PATH
Use the Ninja CMake generator: cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ..
Enjoy easy and fast builds using the ninja command.
To build a Release version, re-run cmake with -DCMAKE_BUILD_TYPE=Release (so this works very much the same as on other platforms, e.g. Linux).
Ninja also integrates well with the VSCode CMake extension (note: VSCode != VS).
I have a simple project where the file structure looks like this:
- CMakeLists.txt
- main.cpp
The CMakeLists.txtlooks like this:
# Project initialization
cmake_minimum_required (VERSION 2.6)
project (Tutorial)
add_executable(Tutorial main.cpp)
When I run the Cmake GUI I get:
CMake Error at CMakeLists.txt:3 (project):
No CMAKE_CXX_COMPILER could be found.
I have Microsoft Visual Studio 2017 installed. I have compiled and run apps from it. The basic example from the CMAKE tutorial does not work.
Can anyone tell me why?
I'm not sure what is going wrong but you might want to take a look at:
https://learn.microsoft.com/en-us/cpp/ide/cmake-tools-for-visual-cpp?view=vs-2017
Visual Studio 2017 is able to open cmake files directly (should do the generator step for you behind the scenes) which may avoid the problem you have.
Use the integrated Visual Studio CMAKE.
The error reporting in the VS build/output/error window has become somewhat complex, and many errors are delegated between the toolchains, etc. (i.e. the whole VS has become modularized lately)
Universal truth: log files are your best friend.
In my case,
CMakeError.log has been constantly complaining it can't find kernel32.lib
Guess what? I forgot to install Windows SDK.
Basically, for any serious work, you need at least MSVS and Windows SDK, if you want to build for Windows. (Windows SDK is also now known as "Windows Kits", which is what you'll get in the StartMenu).
Essentially, your problem might simply be you don't have proper dev libs installed.
I am trying to compile GDCM 2.8.4 for Windows. Can anybody describe how to compile it with Visual Studio 2013 Professional? The GDCM wiki is out of date. Thanks a lot.
First of all, you will have to install CMake. Then
Start CMake GUI.
I guess you already have the gdcm-2.8.4 directory (in a directory X:\XXXXX\ ) containing
Applications
Source
Testing
Utilities
and other subdirs. So set the in the CMake GUI "source dir" to X:\XXXXX\gdcm-2.8.4 . (NOT to its Source subdir!).
Then you create a new directory, where CMake will create the VS projects, let's call it X:\XXXXXX\GDCM-VSProjects. In the CMake GUI set "Where to build the binaries" to X:\XXXXXX\GDCM-VSProjects.
Then, in the CMake GUI press "Configure".
After configuring CMake offers you some options; choose at least GDCM_BUILD_APPLICATIONS, GDCM_BUILD_EXAMPLES, GDCM_BUILD_SHARED_LIBS. For documentation you will need doxygen, latex and possibly more.
Then, in the CMake GUI press "Generate". Now a lengthy calculation is performed and finally VS solution and VS subprojects are generated into your new X:\XXXXXX\GDCM-VSProjects subdirectory.
Now you can open GDCM.sln in VisualStudio and BuildAll in 64 bit Release mode.
After the build, you will find libs, dlls and exes in the bin/Release subdirectory of your X:\XXXXXX\GDCM-VSProjects.
Thats it.
I'm currently trying dlib 19.1 for a project.
I build all the example using cmake, and I also build dlib with VS 2013 to obtain the static lib. So I have my Install folder where the dlib are created. I compile in Release and also in Debug using the same .sln created with the cmake. So until now, no problem.
Next to that, I went in my project (a console project), and I pointed to header and lib (release and debug). Note that this project only contain a Main.cpp that call different function from my own other project libs and that main also call the face landmarks detection from dlib.
So, I have no issue to compile my project in Release with the dlib.lib that I created. But when using the debug dlib.lib and try to launch my own project in debug mode, I obtain the following error :
error LNK2001: unresolved external symbol
_USER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives_
Is there anything done wrong ? When I'm looking to my preprocessor in cmake .sln in debug I have the _DEBUG and also in my own project.
The possible solution is to build dlib not from .sln files, but directly by cmake:
mkdir build
cd build
cmake .. -G"Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=c:\prj\dlib_build_release
cmake --build . --target install --config Release
cmake .. -G"Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=c:\prj\dlib_build_debug
cmake --build . --target install --config Debug
This will compile and install dlib binaries and headers into c:\prj\dlib_build_release and c:\prj\dlib_build_debug directories
After that you can use dlib compiled library from this directories