Search code examples
c++visual-studiovisual-studio-2015yamlyaml-cpp

How to build yaml-cpp on Visual Studio/cmake by command line?


I built yaml-cpp with vs.bat cmake -G "Visual Studio 14 2015" ../:

$ vs.bat cmake -G "Visual Studio 14 2015" ../
-- The C compiler identification is MSVC 19.0.23506.0
-- The CXX compiler identification is MSVC 19.0.23506.0
-- Check for working C compiler: F:/VisualStudio2015/VC/bin/cl.exe
-- Check for working C compiler: F:/VisualStudio2015/VC/bin/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: F:/VisualStudio2015/VC/bin/cl.exe
-- Check for working CXX compiler: F:/VisualStudio2015/VC/bin/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: D:/Evandro/Documentos/Cygwin64/bin/python (found version "1.4")
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: D:/source/libraries/yaml-cpp/bin_msvs

Where vs.bat is:

@echo off

:: Path to your Visual Studio folder.
::
:: Examples:
::     C:\Program Files\Microsoft Visual Studio 9.0
::     F:\VisualStudio2015
set VISUAL_STUDIO_FOLDER=F:\VisualStudio2015

:: Load compilation environment
call "%VISUAL_STUDIO_FOLDER%\VC\vcvarsall.bat" x64

:: Invoke compiler with any options passed to this batch file
%*

After genereating the project for Visual Studio, I ran vs.bat devenv YAML_CPP.sln /Build:

$ vs.bat devenv YAML_CPP.sln /Build
Microsoft Visual Studio 2015 Version 14.0.24720.0.
Copyright (C) Microsoft Corp. All rights reserved.
1>------ Build started: Project: ZERO_CHECK, Configuration: Debug Win32 ------
1>  Checking Build System
1>  CMake does not need to re-run because D:/source/libraries/yaml-cpp/bin_msvs/CMakeFiles/generate.stamp is up-to-date.
1>  CMake does not need to re-run because D:/source/libraries/yaml-cpp/bin_msvs/test/CMakeFiles/generate.stamp is up-to-date.
1>  CMake does not need to re-run because D:/source/libraries/yaml-cpp/bin_msvs/test/gmock-1.7.0/CMakeFiles/generate.stamp is up-to-date.
1>  CMake does not need to re-run because D:/source/libraries/yaml-cpp/bin_msvs/test/gmock-1.7.0/gtest/CMakeFiles/generate.stamp is up-to-date.
1>  CMake does not need to re-run because D:/source/libraries/yaml-cpp/bin_msvs/util/CMakeFiles/generate.stamp is up-to-date.
2>------ Build started: Project: gmock, Configuration: Debug Win32 ------
3>------ Build started: Project: gtest, Configuration: Debug Win32 ------
4>------ Build started: Project: yaml-cpp static md, Configuration: Debug Win32 ------
5>------ Build started: Project: gmock_main, Configuration: Debug Win32 ------
3>  Building Custom Rule D:/source/libraries/yaml-cpp/test/gmock-1.7.0/gtest/CMakeLists.txt
3>  CMake does not need to re-run because D:/source/libraries/yaml-cpp/bin_msvs/test/gmock-1.7.0/gtest/CMakeFiles/generate.stamp is up-to-date.
3>  gtest-all.cc
2>  Building Custom Rule D:/source/libraries/yaml-cpp/test/gmock-1.7.0/CMakeLists.txt
2>  CMake does not need to re-run because D:/source/libraries/yaml-cpp/bin_msvs/test/gmock-1.7.0/CMakeFiles/generate.stamp is up-to-date.
4>  Building Custom Rule D:/source/libraries/yaml-cpp/CMakeLists.txt
5>  Building Custom Rule D:/source/libraries/yaml-cpp/test/gmock-1.7.0/CMakeLists.txt
4>  CMake does not need to re-run because D:/source/libraries/yaml-cpp/bin_msvs/CMakeFiles/generate.stamp is up-to-date.
2>  gtest-all.cc
5>  CMake does not need to re-run because D:/source/libraries/yaml-cpp/bin_msvs/test/gmock-1.7.0/CMakeFiles/generate.stamp is up-to-date.
5>  gtest-all.cc
4>  binary.cpp
4>  convert.cpp
4>  directives.cpp
2>  gmock-all.cc
5>  gmock-all.cc
3>  gtest.vcxproj -> D:\User\Dropbox\Applications\SoftwareVersioning\SublimeText\Data\Packages\ObjectBeautifier\source\libraries\yaml-cpp\bin_msvs\test\gmock-1.7.0\gtest\Debug\libgtest.lib
6>------ Build started: Project: gtest_main, Configuration: Debug Win32 ------
4>  emit.cpp
6>  Building Custom Rule D:/source/libraries/yaml-cpp/test/gmock-1.7.0/gtest/CMakeLists.txt
6>  CMake does not need to re-run because D:/source/libraries/yaml-cpp/bin_msvs/test/gmock-1.7.0/gtest/CMakeFiles/generate.stamp is up-to-date.
4>  emitfromevents.cpp
5>  gmock_main.cc
4>  emitter.cpp
6>  gtest_main.cc
2>  Generating Code...
2>  gmock.vcxproj -> D:\User\Dropbox\Applications\SoftwareVersioning\SublimeText\Data\Packages\ObjectBeautifier\source\libraries\yaml-cpp\bin_msvs\test\gmock-1.7.0\Debug\libgmock.lib
7>------ Skipped Build: Project: RUN_TESTS, Configuration: Debug Win32 ------
7>Project not selected to build for this solution configuration
8>------ Skipped Build: Project: format, Configuration: Debug Win32 ------
8>Project not selected to build for this solution configuration
6>  gtest_main.vcxproj -> D:\User\Dropbox\Applications\SoftwareVersioning\SublimeText\Data\Packages\ObjectBeautifier\source\libraries\yaml-cpp\bin_msvs\test\gmock-1.7.0\gtest\Debug\libgtest_main.lib
4>  emitterstate.cpp
5>  Generating Code...
4>  emitterutils.cpp
5>  gmock_main.vcxproj -> D:\User\Dropbox\Applications\SoftwareVersioning\SublimeText\Data\Packages\ObjectBeautifier\source\libraries\yaml-cpp\bin_msvs\test\gmock-1.7.0\Debug\libgmock_main.lib
4>  exceptions.cpp
4>  exp.cpp
4>  memory.cpp
4>  node.cpp
4>  node_data.cpp
4>  nodebuilder.cpp
4>  nodeevents.cpp
4>  null.cpp
4>  ostream_wrapper.cpp
4>  parse.cpp
4>  parser.cpp
4>  regex_yaml.cpp
4>  Generating Code...
4>  Compiling...
4>  scanner.cpp
4>  scanscalar.cpp
4>  scantag.cpp
4>  scantoken.cpp
4>  simplekey.cpp
4>  singledocparser.cpp
4>  stream.cpp
4>  tag.cpp
4>  graphbuilder.cpp
4>  graphbuilderadapter.cpp
4>  Generating Code...
4>  yaml-cpp.vcxproj -> D:\User\Dropbox\Applications\SoftwareVersioning\SublimeText\Data\Packages\ObjectBeautifier\source\libraries\yaml-cpp\bin_msvs\Debug\libyaml-cppmdd.lib
9>------ Build started: Project: parse, Configuration: Debug Win32 ------
10>------ Build started: Project: read, Configuration: Debug Win32 ------
11>------ Build started: Project: run-tests, Configuration: Debug Win32 ------
12>------ Build started: Project: sandbox, Configuration: Debug Win32 ------
9>  Building Custom Rule D:/source/libraries/yaml-cpp/util/CMakeLists.txt
12>  Building Custom Rule D:/source/libraries/yaml-cpp/util/CMakeLists.txt
10>  Building Custom Rule D:/source/libraries/yaml-cpp/util/CMakeLists.txt
9>  CMake does not need to re-run because D:/source/libraries/yaml-cpp/bin_msvs/util/CMakeFiles/generate.stamp is up-to-date.
12>  CMake does not need to re-run because D:/source/libraries/yaml-cpp/bin_msvs/util/CMakeFiles/generate.stamp is up-to-date.
10>  CMake does not need to re-run because D:/source/libraries/yaml-cpp/bin_msvs/util/CMakeFiles/generate.stamp is up-to-date.
9>  parse.cpp
12>  sandbox.cpp
10>  read.cpp
11>  Building Custom Rule D:/source/libraries/yaml-cpp/test/CMakeLists.txt
11>  CMake does not need to re-run because D:/source/libraries/yaml-cpp/bin_msvs/test/CMakeFiles/generate.stamp is up-to-date.
11>  main.cpp
11>  ostream_wrapper_test.cpp
12>  sandbox.vcxproj -> D:\User\Dropbox\Applications\SoftwareVersioning\SublimeText\Data\Packages\ObjectBeautifier\source\libraries\yaml-cpp\bin_msvs\util\Debug\sandbox.exe
12>  sandbox.vcxproj -> D:/source/libraries/yaml-cpp/bin_msvs/util/Debug/sandbox.pdb (Full PDB)
10>  read.vcxproj -> D:\User\Dropbox\Applications\SoftwareVersioning\SublimeText\Data\Packages\ObjectBeautifier\source\libraries\yaml-cpp\bin_msvs\util\Debug\read.exe
10>  read.vcxproj -> D:/source/libraries/yaml-cpp/bin_msvs/util/Debug/read.pdb (Full PDB)
9>  parse.vcxproj -> D:\User\Dropbox\Applications\SoftwareVersioning\SublimeText\Data\Packages\ObjectBeautifier\source\libraries\yaml-cpp\bin_msvs\util\Debug\parse.exe
9>  parse.vcxproj -> D:/source/libraries/yaml-cpp/bin_msvs/util/Debug/parse.pdb (Full PDB)
11>  regex_test.cpp
11>  emitter_test.cpp
11>  encoding_test.cpp
11>  gen_emitter_test.cpp
11>  handler_spec_test.cpp
11>  handler_test.cpp
11>  load_node_test.cpp
11>  node_spec_test.cpp
11>  node_test.cpp
11>  Generating Code...
11>  run-tests.vcxproj -> D:\User\Dropbox\Applications\SoftwareVersioning\SublimeText\Data\Packages\ObjectBeautifier\source\libraries\yaml-cpp\bin_msvs\test\Debug\run-tests.exe
11>  run-tests.vcxproj -> D:/source/libraries/yaml-cpp/bin_msvs/test/Debug/run-tests.pdb (Full PDB)
13>------ Build started: Project: ALL_BUILD, Configuration: Debug Win32 ------
13>  Building Custom Rule D:/source/libraries/yaml-cpp/CMakeLists.txt
13>  CMake does not need to re-run because D:/source/libraries/yaml-cpp/bin_msvs/CMakeFiles/generate.stamp is up-to-date.
14>------ Skipped Build: Project: INSTALL, Configuration: Debug Win32 ------
14>Project not selected to build for this solution configuration
========== Build: 11 succeeded, 0 failed, 0 up-to-date, 3 skipped ==========

Now I am trying to link it with my project test file called main.cpp:

#include "yaml-cpp/yaml.h"

#include <iostream>
#include <sstream>
#include <cstdlib>
#include <exception>

#include <fstream>
#include <string>
#include <vector>

int main( int argumentsCount, char* argumentsStringList[] )
{
    std::cout << "YAML\n" << std::endl;

    // https://learnxinyminutes.com/docs/yaml/
    YAML::Node SyntaxFile = YAML::LoadFile("test.beauty-blocks");

    return EXIT_SUCCESS;
}

When I try to compile it with vs.bat cl.exe /I. /I./libraries/yaml-cpp/include libraries/yaml-cpp/bin_msvs/Debug/libyaml-cppmdd.lib /EHsc /Femain.exe main.cpp is does outputs:

$ vs.bat cl.exe /I. /I./libraries/yaml-cpp/include libraries/yaml-cpp/bin_msvs/Debug/libyaml-cppmdd.lib /EHsc /Femain.exe main.cpp

Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

main.cpp
Microsoft (R) Incremental Linker Version 14.00.23506.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:main.exe
libraries/yaml-cpp/bin_msvs/Debug/libyaml-cppmdd.lib
main.obj
libyaml-cppmdd.lib(parse.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj
libyaml-cppmdd.lib(parse.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmdd.lib(exceptions.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj
libyaml-cppmdd.lib(exceptions.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmdd.lib(parser.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj
libyaml-cppmdd.lib(parser.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmdd.lib(nodebuilder.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj
libyaml-cppmdd.lib(nodebuilder.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmdd.lib(directives.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj
libyaml-cppmdd.lib(directives.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmdd.lib(scanner.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj
libyaml-cppmdd.lib(scanner.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmdd.lib(singledocparser.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj
libyaml-cppmdd.lib(singledocparser.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmdd.lib(node_data.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj
libyaml-cppmdd.lib(node_data.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmdd.lib(memory.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj
libyaml-cppmdd.lib(memory.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmdd.lib(regex_yaml.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj
libyaml-cppmdd.lib(regex_yaml.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmdd.lib(stream.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj
libyaml-cppmdd.lib(stream.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmdd.lib(simplekey.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj
libyaml-cppmdd.lib(simplekey.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmdd.lib(scantoken.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj
libyaml-cppmdd.lib(scantoken.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmdd.lib(tag.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj
libyaml-cppmdd.lib(tag.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmdd.lib(null.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj
libyaml-cppmdd.lib(null.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmdd.lib(scanscalar.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj
libyaml-cppmdd.lib(scanscalar.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmdd.lib(scantag.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj
libyaml-cppmdd.lib(scantag.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmdd.lib(exp.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in main.obj
libyaml-cppmdd.lib(exp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MT_StaticRelease' in main.obj
msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: __thiscall std::_Lockit::_Lockit(int)" (??0_Lockit@std@@QAE@H@Z) already defined in libcpmt.lib(xlock.obj)
msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QAE@XZ) already defined in libcpmt.lib(xlock.obj)
msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "bool __cdecl std::uncaught_exception(void)" (?uncaught_exception@std@@YA_NXZ) already defined in libcpmt.lib(uncaught.obj)
...
libyaml-cppmdd.lib(exp.obj) : warning LNK4049: locally defined symbol __invalid_parameter imported
libyaml-cppmdd.lib(scantoken.obj) : warning LNK4049: locally defined symbol __invalid_parameter imported
libyaml-cppmdd.lib(tag.obj) : warning LNK4049: locally defined symbol __invalid_parameter imported
libyaml-cppmdd.lib(scanscalar.obj) : warning LNK4217: locally defined symbol __invalid_parameter imported in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??$?6DU?$char_traits@D@std@@V?$allocator@D@1@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@@Z)
libyaml-cppmdd.lib(scantag.obj) : warning LNK4049: locally defined symbol __invalid_parameter imported
libyaml-cppmdd.lib(memory.obj) : warning LNK4049: locally defined symbol __invalid_parameter imported
libyaml-cppmdd.lib(regex_yaml.obj) : warning LNK4049: locally defined symbol __invalid_parameter imported
libyaml-cppmdd.lib(stream.obj) : warning LNK4049: locally defined symbol __invalid_parameter imported
libyaml-cppmdd.lib(simplekey.obj) : warning LNK4049: locally defined symbol __invalid_parameter imported
libyaml-cppmdd.lib(directives.obj) : warning LNK4049: locally defined symbol __invalid_parameter imported
libyaml-cppmdd.lib(scanner.obj) : warning LNK4049: locally defined symbol __invalid_parameter imported
libyaml-cppmdd.lib(singledocparser.obj) : warning LNK4049: locally defined symbol __invalid_parameter imported
...
libyaml-cppmdd.lib(parse.obj) : error LNK2001: unresolved external symbol __imp___CrtDbgReportW
libyaml-cppmdd.lib(exceptions.obj) : error LNK2001: unresolved external symbol __imp___CrtDbgReportW
libyaml-cppmdd.lib(parser.obj) : error LNK2001: unresolved external symbol __imp___CrtDbgReportW
libyaml-cppmdd.lib(nodebuilder.obj) : error LNK2001: unresolved external symbol __imp___CrtDbgReportW
libyaml-cppmdd.lib(tag.obj) : error LNK2001: unresolved external symbol __imp___wassert
libyaml-cppmdd.lib(nodebuilder.obj) : error LNK2001: unresolved external symbol __imp___wassert
libyaml-cppmdd.lib(scanner.obj) : error LNK2001: unresolved external symbol __imp___wassert
libyaml-cppmdd.lib(singledocparser.obj) : error LNK2001: unresolved external symbol __imp___wassert
libyaml-cppmdd.lib(node_data.obj) : error LNK2001: unresolved external symbol __imp___wassert
MSVCRTD.lib(_chandler4gs_.obj) : error LNK2019: unresolved external symbol __except_handler4_common referenced in function __except_handler4
main.exe : fatal error LNK1120: 3 unresolved externals

Moreoever I searched for the error error LNK2038: mismatch detected for and I found out this question:

  1. error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj

It is saying I am compiling one project with debug mode, but I could not find out how to configure it to build both on release mode or in debug mode.


Resumely these are the command lines used:

cmake -G "Visual Studio 14 2015" ../
devenv YAML_CPP.sln /Build
cl.exe /I. /I./libraries/yaml-cpp/include libraries/yaml-cpp/bin_msvs/Debug/libyaml-cppmdd.lib /EHsc /Femain.exe main.cpp

How would be to put them to release or debug mode?

The yaml-cpp documentation does not mention how to do it. I tried to use this other answer:

  1. Debug vs Release in CMAKE

But when I ran vs.bat cmake -DCMAKE_BUILD_TYPE=Release -G "Visual Studio 14 2015" ../ outputting:

$ vs.bat cmake -DCMAKE_BUILD_TYPE=Release -G "Visual Studio 14 2015" ../
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_BUILD_TYPE


-- Build files have been written to: D:/source/libraries/yaml-cpp/bin_msvs

It seems not to be recognizing the mentioned variable CMAKE_BUILD_TYPE on that answer. Was also opened an issue on: https://github.com/jbeder/yaml-cpp/issues/483


Update

Even after the @flyx's answer I got a new error:

./cl_env.bat /I. /I./libraries/yaml-cpp/include libraries/yaml-cpp/bin_msvs/Release/libyaml-cppmd.lib /EHsc /Femain.exe main.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

main.cpp
Microsoft (R) Incremental Linker Version 14.00.23506.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:main.exe
libraries/yaml-cpp/bin_msvs/Release/libyaml-cppmd.lib
main.obj
libyaml-cppmd.lib(exceptions.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmd.lib(memory.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmd.lib(node_data.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmd.lib(parse.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmd.lib(parser.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmd.lib(nodebuilder.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
libyaml-cppmd.lib(directives.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in main.obj
...
libyaml-cppmd.lib(nodebuilder.obj) : warning LNK4049: locally defined symbol __invalid_parameter_noinfo_noreturn imported
libyaml-cppmd.lib(directives.obj) : warning LNK4049: locally defined symbol __invalid_parameter_noinfo_noreturn imported
libyaml-cppmd.lib(scanner.obj) : warning LNK4049: locally defined symbol __invalid_parameter_noinfo_noreturn imported
libyaml-cppmd.lib(exceptions.obj) : warning LNK4217: locally defined symbol __invalid_parameter_noinfo_noreturn imported in function "void __cdecl std::_Deallocate(void *,unsigned int,unsigned int)" (?_Deallocate@std@@YAXPAXII@Z)
libyaml-cppmd.lib(memory.obj) : warning LNK4049: locally defined symbol __invalid_parameter_noinfo_noreturn imported
libyaml-cppmd.lib(node_data.obj) : warning LNK4049: locally defined symbol __invalid_parameter_noinfo_noreturn imported
libyaml-cppmd.lib(parse.obj) : warning LNK4049: locally defined symbol __invalid_parameter_noinfo_noreturn imported
libyaml-cppmd.lib(scanscalar.obj) : warning LNK4049: locally defined symbol ___std_exception_destroy imported
libyaml-cppmd.lib(scantag.obj) : warning LNK4049: locally defined symbol ___std_exception_destroy imported
...
libyaml-cppmd.lib(singledocparser.obj) : warning LNK4049: locally defined symbol ___std_exception_copy imported
libyaml-cppmd.lib(scantoken.obj) : warning LNK4049: locally defined symbol ___std_exception_copy imported
libyaml-cppmd.lib(tag.obj) : warning LNK4049: locally defined symbol ___std_exception_copy imported
libyaml-cppmd.lib(scanscalar.obj) : warning LNK4049: locally defined symbol ___std_exception_copy imported
libyaml-cppmd.lib(node_data.obj) : warning LNK4217: locally defined symbol ___std_exception_copy imported in function "public: __thiscall YAML::Exception::Exception(struct YAML::Mark const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0Exception@YAML@@QAE@ABUMark@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
libyaml-cppmd.lib(parse.obj) : warning LNK4217: locally defined symbol ___std_exception_copy imported in function "public: virtual void * __thiscall std::basic_filebuf<char,struct std::char_traits<char> >::`scalar deleting destructor'(unsigned int)" (??_G?$basic_filebuf@DU?$char_traits@D@std@@@std@@UAEPAXI@Z)
...
libyaml-cppmd.lib(parse.obj) : warning LNK4217: locally defined symbol __errno imported in function _memcpy_s
libyaml-cppmd.lib(scanscalar.obj) : warning LNK4217: locally defined symbol _memchr imported in function "public: unsigned int __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::find_last_not_of(char const *,unsigned int,unsigned int)const " (?find_last_not_of@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIPBDII@Z)
MSVCRT.lib(_chandler4gs_.obj) : error LNK2019: unresolved external symbol __except_handler4_common referenced in function __except_handler4
main.exe : fatal error LNK1120: 1 unresolved externals

But after I searched error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease', I found out LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in file.obj, therefore I added /MD (desc) to my main's the command line, resulting on this full version steps:

cmake -G "Visual Studio 14 2015" ../
devenv YAML_CPP.sln /Build Release
cl.exe /I. /I./libraries/yaml-cpp/include libraries/yaml-cpp/bin_msvs/Debug/libyaml-cppmdd.lib /EHsc /MD /Femain.exe main.cpp

Now it is finally compiling fine.


Solution

  • Visual Studio is a CMake target which allows multiple configurations (you can have both a Debug, a Release and several other build configurations in a Visual Studio project). Therefore, CMAKE_BUILD_TYPE is ignored when generating the *.sln file.

    Instead, you should give the configuration when invoking the compiler, i.e.

    vs.bat devenv YAML_CPP.sln /build Debug
    

    or

    vs.bat devenv YAML_CPP.sln /build Release
    

    It seems strange that your command even works given that the configuration name is not optional according to the documentation.

    Since you compile your main.cpp without debug options, you should compile yaml-cpp with Release configuration.

    In general, it would be a good idea to generate a Solution file for your code with CMAKE – you can then include the yaml-cpp CMAKE file and are guaranteed that everything compiles with the same switches.