以前搭建过一次,这次在另一台电脑的visual studio中应用不是那么顺利。
首先参考的是
https://blog.csdn.net/hp_cpp/article/details/81561310
如果按照上文引用编译成功了,就不用往下看了。
下图是我安装了cmake之后打不开,界面显示不出来,任务栏看到的是白板。卸载重装,换版本重装都不起作用。好在命令行方式能用。
最终使用cmake命令完成。
本地安装好visual studio 后,如果要编译32位protobuf. 打开x86 Native Tools Command Prompt for VS 2019
如果要编译64位protobuf, 在上图打开x64 Native Tools Command Prompt for VS 2019. 使用其他的也能构建sln 工程。但是在vs中打开工程可能会build失败。
为了不污染下载下来的protobuf源码,新建一个目录build_64,进入到这个目录(D:\Workspace\VsWorkspaces\protobuf\build_64)下再cmake. cmake 后面的路径指向源码中的cmake文件夹
**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.5.4
** Copyright (c) 2019 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
C:\Windows\System32>cd D:\Workspace\VsWorkspaces\protobuf\build_64
C:\Windows\System32>D:
D:\Workspace\VsWorkspaces\protobuf\build_64>cmake D:\Workspace\VsWorkspaces\protobuf\protobuf-3.11.4\cmake
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.18363.
-- The C compiler identification is MSVC 19.25.28614.0
-- The CXX compiler identification is MSVC 19.25.28614.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
--
-- 3.11.4.0
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE
-- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Workspace/VsWorkspaces/protobuf/build_64
D:\Workspace\VsWorkspaces\protobuf\build_64>
会在当前目录[D:/Workspace/VsWorkspaces/protobuf/build_64]下生成vs工程
VS 打开后在All_BUILD 工程上右键生成。
在工程目录的Debug文件夹目录下生成需要的lib库文件 , libprotobufd.lib, libprotobuf-lited.lib, libprotocd.lib
这些静态库可以拿来引用了。
本文由VS软件圈(vssoft.net)发布,不代表VS软件圈立场,转载联系作者并注明出处:https://vssoft.net/vsazwt/VS2019anzhuangwenti/2020/0725/3556.html