我使用vs.bat cmake -G "Visual Studio 14 2015" ../
构建了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
%*
在为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)" (??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
无论我搜索错误error LNK2038: mismatch detected for
,我都发现了这个问题:
这是说我正在用debug mode
编译一个项目,
但我无法找到如何配置它来构建它们
在release mode
或debug mode
。
恢复这些是使用的命令行:
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
文档未提及如何执行此操作。我试着用另一个答案:
但是当我运行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)" (?_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
但在我搜索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
(desc)添加到我的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
现在它终于编译好了。
答案 0 :(得分:1)
Visual Studio是一个CMake目标,它允许多个配置(您可以在Visual Studio项目中同时拥有 Debug , Release 和其他几个构建配置)。因此,生成CMAKE_BUILD_TYPE
文件时会忽略*.sln
。
相反,您应该在调用编译器时给出配置,即
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文件并保证所有内容都使用相同的开关进行编译。