2017-03-26 73 views
0

我建yaml-cppvs.bat cmake -G "Visual Studio 14 2015" ../如何通過命令行在Visual Studio/cmake上建立yaml-cpp?

$ 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 

其中vs.bat是:

@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 
%* 

genereating項目爲Visual Studio之後,我跑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 ========== 

現在我想將其與我的項目測試文件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; 
} 

當我試着使用vs.bat cl.exe /I. /I./libraries/yaml-cpp/include libraries/yaml-cpp/bin_msvs/Debug/libyaml-cppmdd.lib /EHsc /Femain.exe main.cpp編譯它確實產出:

$ 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)" ([email protected]@@[email protected]@Z) already defined in libcpmt.lib(xlock.obj) 
msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" ([email protected]@@[email protected]) already defined in libcpmt.lib(xlock.obj) 
msvcprtd.lib(MSVCP140D.dll) : error LNK2005: "bool __cdecl std::uncaught_exception(void)" ([email protected]@@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 &)" ([email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected]@[email protected]@@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@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我搜索了錯誤error LNK2038: mismatch detected for,我發現了這樣一個問題:

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

這是說我是用debug mode, 編譯一個項目,但我找不到如何配置它以建立 release modedebug mode


Resumely這些都是用過的命令行:

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 

將如何把他們釋放或調試模式?

yaml-cpp文檔沒有提及如何去做。我試圖用這個其他答案:

  1. Debug vs Release in CMAKE

但是,當我跑vs.bat cmake -DCMAKE_BUILD_TYPE=Release -G "Visual Studio 14 2015" ../輸出:

$ 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 

它似乎並沒有被承認對答案提到的變量CMAKE_BUILD_TYPE。還開設了一個問題上:https://github.com/jbeder/yaml-cpp/issues/483


更新

即使在@flyx的答案,我得到了一個新的錯誤:

./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)" ([email protected]@@[email protected]) 
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 &)" ([email protected]@@[email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@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)" ([email protected][email protected]@[email protected]@@[email protected]@[email protected]) 
... 
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 " ([email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]) 
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 

但我搜索error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease'後,我發現了LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in file.obj ,因此我將/MD(​​)添加到我的main的命令行中,導致完整版本的步驟如下:

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 

現在終於編譯好了。

回答

1

Visual Studio是一個CMake的目標,它允許多個配置(你可以同時擁有調試,一個發佈和Visual Studio項目中其他幾個構建配置)。因此,在生成*.sln文件時將忽略CMAKE_BUILD_TYPE

相反,你應該調用編譯器時,即

vs.bat devenv YAML_CPP.sln /build Debug 

vs.bat devenv YAML_CPP.sln /build Release 

這似乎很奇怪,即使作品給你的命令配置名稱根據是不可選給配置documentation

由於您編譯的main.cpp沒有調試選項,因此應該使用Release配置編譯yaml-cpp。

通常,用CMAKE爲您的代碼生成解決方案文件是個好主意 - 然後您可以包含yaml-cpp CMAKE文件,並保證所有內容都使用相同的開關進行編譯。