我有一个项目,其架构如下:
├── CMakeLists.txt
├── projects
│ ├── CMakeLists.txt
│ ├── io
│ │ ├── CMakeLists.txt
│ │ ├── data.proto
│ │ └── generated
│ │ ├── data.pb.cc
│ │ └── data.pb.h
│ ├── service
│ │ ├── CMakeLists.txt
│ │ └── main.cpp
│ ├── dll_project_1
│ └── dll_project_2
└── third_party
└── protobuf
├── bin
├── cmake
├── include
└── lib
项目目录包含我所有的项目(显然):
服务- 为可执行项目
- io一个静态库,我只想在其中编辑".proto"文件
- 其他项目是一些共享库基本上
third_party/protobuf包含这里列出的所有protobuf安装文件。请注意,为了安装protobuf,我遵循了这里的所有说明(在Debug x64和Release x64中使用Visual Studio for Compilation and Installation)。
CMakeLists.txt
如下:
。/CMakeLists.txt
set(THIRD_PARTY ${CMAKE_CURRENT_SOURCE_DIR}/third_party)
set(PROTOBUF ${THIRD_PARTY}/protobuf)
set(Protobuf_USE_STATIC_LIBS ON)
include(${PROTOBUF}/cmake/protobuf-config.cmake)
include(${PROTOBUF}/cmake/protobuf-module.cmake)
include(${PROTOBUF}/cmake/protobuf-options.cmake)
include(${PROTOBUF}/cmake/protobuf-targets.cmake)
find_package(Protobuf REQUIRED HINTS ${PROTOBUF})
include_directories(${Protobuf_INCLUDE_DIRS})
link_libraries(${Protobuf_LIBRARIES})
。/项目/CMakeLists.txt
add_subdirectory(io)
add_subdirectory(dll_project_1)
add_subdirectory(dll_project_2)
add_subdirectory(service)
。/项目/io/CMakeLists.txt
set(PROTO
data.proto
)
set(PROTO_GENERATED
generated/data.pb.cc
generated/data.pb.h
)
source_group(Proto FILES ${PROTO})
source_group(Generated FILES ${PROTO_GENERATED})
add_library(IO STATIC ${PROTO} ${PROTO_GENERATED})
。/项目/服务/CMakeLists.txt
add_executable(Service main.cpp)
target_link_libraries(Service
IO
Dll1
Dll2
)
现在构建解决方案,我要做的就是像这样:
#include "../io/generated/data.pb.h"
int main()
{
Data::SomeData d;
d.set_value(0.0);
}
但是当我尝试编译时,我得到了很多LNK2038和LNK2005错误:
6>main.cpp
6>libprotobufd.lib(common.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(common.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(common.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(coded_stream.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(coded_stream.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(coded_stream.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(arena.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(arena.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(arena.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(message_lite.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(message_lite.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(message_lite.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(parse_context.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(parse_context.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(parse_context.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(generated_message_util.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(generated_message_util.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(generated_message_util.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(unknown_field_set.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(unknown_field_set.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(unknown_field_set.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(generated_message_reflection.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(generated_message_reflection.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(generated_message_reflection.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(message.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(message.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(message.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(reflection_ops.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(reflection_ops.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(reflection_ops.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(wire_format.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(wire_format.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(wire_format.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(status.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(status.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(status.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(int128.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(int128.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(int128.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(stringpiece.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(stringpiece.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(stringpiece.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(strutil.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(strutil.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(strutil.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(zero_copy_stream.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(zero_copy_stream_impl_lite.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(zero_copy_stream.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(zero_copy_stream.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(zero_copy_stream_impl_lite.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(zero_copy_stream_impl_lite.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(zero_copy_stream_impl.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(zero_copy_stream_impl.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(zero_copy_stream_impl.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(structurally_valid.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(structurally_valid.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(structurally_valid.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(repeated_field.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(repeated_field.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(repeated_field.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(wire_format_lite.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(wire_format_lite.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(wire_format_lite.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(extension_set.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(extension_set.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(extension_set.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(descriptor.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(descriptor.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(descriptor.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(arenastring.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(arenastring.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(arenastring.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(extension_set_heavy.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(extension_set_heavy.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(extension_set_heavy.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(map_field.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(map_field.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(map_field.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(io_win32.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(io_win32.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(io_win32.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(implicit_weak_message.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(implicit_weak_message.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(implicit_weak_message.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(stringprintf.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(stringprintf.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(stringprintf.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(text_format.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(text_format.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(text_format.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(descriptor.pb.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(descriptor.pb.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(descriptor.pb.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(tokenizer.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(tokenizer.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(tokenizer.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(descriptor_database.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(descriptor_database.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(descriptor_database.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(dynamic_message.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(dynamic_message.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(dynamic_message.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(substitute.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(substitute.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(substitute.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(strtod.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(strtod.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(strtod.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(any_lite.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(any_lite.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(any_lite.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(map.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(map.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(map.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libprotobufd.lib(any.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libprotobufd.lib(any.obj) : warning LNK4099: PDB 'libprotobuf.pdb' was not found with 'libprotobufd.lib(any.obj)' or at 'C:devMyProjectbuildDebuglibprotobuf.pdb'; linking object as if no debug info
6>libcpmtd.lib(locale0.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libcpmtd.lib(locale0.obj) : error LNK2005: "void __cdecl std::_Facet_Register(class std::_Facet_base *)" (?_Facet_Register@std@@YAXPEAV_Facet_base@1@@Z) already defined in msvcprtd.lib(locale0_implib.obj)
6>libcpmtd.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Getgloballocale(void)" (?_Getgloballocale@locale@std@@CAPEAV_Locimp@12@XZ) already defined in msvcprtd.lib(MSVCP140D.dll)
6>libcpmtd.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Init(bool)" (?_Init@locale@std@@CAPEAV_Locimp@12@_N@Z) already defined in msvcprtd.lib(MSVCP140D.dll)
6>libcpmtd.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_ctor(class std::_Locinfo *,char const *)" (?_Locinfo_ctor@_Locinfo@std@@SAXPEAV12@PEBD@Z) already defined in msvcprtd.lib(MSVCP140D.dll)
6>libcpmtd.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_dtor(class std::_Locinfo *)" (?_Locinfo_dtor@_Locinfo@std@@SAXPEAV12@@Z) already defined in msvcprtd.lib(MSVCP140D.dll)
6>libcpmtd.lib(locale.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libcpmtd.lib(iosptrs.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libcpmtd.lib(wlocale.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libcpmtd.lib(xlocale.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libcpmtd.lib(xstol.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libcpmtd.lib(xstoul.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libcpmtd.lib(xstoll.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libcpmtd.lib(xstoull.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libcpmtd.lib(xlock.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libcpmtd.lib(xlock.obj) : error LNK2005: "public: __cdecl std::_Lockit::_Lockit(int)" (??0_Lockit@std@@QEAA@H@Z) already defined in msvcprtd.lib(MSVCP140D.dll)
6>libcpmtd.lib(xlock.obj) : error LNK2005: "public: __cdecl std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QEAA@XZ) already defined in msvcprtd.lib(MSVCP140D.dll)
6>libcpmtd.lib(xstrcoll.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libcpmtd.lib(xdateord.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libcpmtd.lib(xwcscoll.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libcpmtd.lib(xwcsxfrm.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libcpmtd.lib(xstrxfrm.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libcpmtd.lib(xmtx.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libcpmtd.lib(StlCompareStringA.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libcpmtd.lib(winapinls.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libcpmtd.lib(StlCompareStringW.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libcpmtd.lib(StlLCMapStringW.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libcpmtd.lib(StlLCMapStringA.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>libcpmtd.lib(winapisupp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj
6>MSVCRTD.lib(initializers.obj) : warning LNK4098: defaultlib 'libcmtd.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
6>C:devMyProjectbuildDebugService.exe : fatal error LNK1169: one or more multiply defined symbols found
6>Done building project "Service.vcxproj" -- FAILED.
我首先发现了这个问题,但是我不知道如何用cmake来回答这个问题。
像往常一样,我需要问一个困扰我几个小时的问题,然后在几分钟后自己找到解决方案。
答案在这里。只需要在cmake命令中添加-Dprotobuf_MSVC_STATIC_RUNTIME=OFF
来构建解决方案(这一步):
cmake -G "Visual Studio 16 2019" -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -DCMAKE_INSTALL_PREFIX=../../../install ../..