Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 1 | This directory contains *CMake* files that can be used to build protobuf |
| 2 | with *MSVC* on *Windows*. You can build the project from *Command Prompt* |
| 3 | and using an *Visual Studio* IDE. |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 4 | |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 5 | You need to have [CMake](http://www.cmake.org), [Visual Studio](https://www.visualstudio.com) |
| 6 | and optionally [Git](http://git-scm.com) installed on your computer before proceeding. |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 7 | |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 8 | Most of the instructions will be given to the *ะกommand Prompt*, but the same |
| 9 | actions can be performed using appropriate GUI tools. |
Feng Xiao | 2286ab3 | 2015-06-04 11:12:32 -0700 | [diff] [blame] | 10 | |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 11 | Environment Setup |
| 12 | ================= |
Feng Xiao | 2286ab3 | 2015-06-04 11:12:32 -0700 | [diff] [blame] | 13 | |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 14 | Open the appropriate *Command Prompt* from the *Start* menu. |
Feng Xiao | ee6b3d5 | 2015-06-05 17:59:09 -0700 | [diff] [blame] | 15 | |
Daniel Johansen | e93dea7 | 2019-10-17 14:27:00 +0200 | [diff] [blame] | 16 | For example *x86 Native Tools Command Prompt for VS 2019*: |
Feng Xiao | ee6b3d5 | 2015-06-05 17:59:09 -0700 | [diff] [blame] | 17 | |
Daniel Johansen | e93dea7 | 2019-10-17 14:27:00 +0200 | [diff] [blame] | 18 | C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional> |
Feng Xiao | ee6b3d5 | 2015-06-05 17:59:09 -0700 | [diff] [blame] | 19 | |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 20 | Change to your working directory: |
Feng Xiao | 2286ab3 | 2015-06-04 11:12:32 -0700 | [diff] [blame] | 21 | |
Daniel Johansen | e93dea7 | 2019-10-17 14:27:00 +0200 | [diff] [blame] | 22 | C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional>cd C:\Path\to |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 23 | C:\Path\to> |
Feng Xiao | 2286ab3 | 2015-06-04 11:12:32 -0700 | [diff] [blame] | 24 | |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 25 | Where *C:\Path\to* is path to your real working directory. |
Feng Xiao | ee6b3d5 | 2015-06-05 17:59:09 -0700 | [diff] [blame] | 26 | |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 27 | Create a folder where protobuf headers/libraries/binaries will be installed after built: |
Feng Xiao | ee6b3d5 | 2015-06-05 17:59:09 -0700 | [diff] [blame] | 28 | |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 29 | C:\Path\to>mkdir install |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 30 | |
Dongjoon Hyun | 7b08d49 | 2016-01-11 14:52:01 -0800 | [diff] [blame] | 31 | If *cmake* command is not available from *Command Prompt*, add it to system *PATH* variable: |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 32 | |
| 33 | C:\Path\to>set PATH=%PATH%;C:\Program Files (x86)\CMake\bin |
| 34 | |
Dongjoon Hyun | 7b08d49 | 2016-01-11 14:52:01 -0800 | [diff] [blame] | 35 | If *git* command is not available from *Command Prompt*, add it to system *PATH* variable: |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 36 | |
| 37 | C:\Path\to>set PATH=%PATH%;C:\Program Files\Git\cmd |
| 38 | |
| 39 | Good. Now you are ready to continue. |
| 40 | |
| 41 | Getting Sources |
| 42 | =============== |
| 43 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 44 | You can get the latest stable source packages from the release page: |
| 45 | |
Feng Xiao | afe98de | 2018-08-22 11:55:30 -0700 | [diff] [blame] | 46 | https://github.com/protocolbuffers/protobuf/releases/latest |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 47 | |
| 48 | For example: if you only need C++, download `protobuf-cpp-[VERSION].tar.gz`; if |
| 49 | you need C++ and Java, download `protobuf-java-[VERSION].tar.gz` (every package |
| 50 | contains C++ source already); if you need C++ and multiple other languages, |
| 51 | download `protobuf-all-[VERSION].tar.gz`. |
| 52 | |
| 53 | Or you can use git to clone from protobuf git repository. |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 54 | |
Feng Xiao | afe98de | 2018-08-22 11:55:30 -0700 | [diff] [blame] | 55 | C:\Path\to> git clone -b [release_tag] https://github.com/protocolbuffers/protobuf.git |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 56 | |
| 57 | Where *[release_tag]* is a git tag like *v3.0.0-beta-1* or a branch name like *master* |
| 58 | if you want to get the latest code. |
| 59 | |
| 60 | Go to the project folder: |
| 61 | |
| 62 | C:\Path\to>cd protobuf |
| 63 | C:\Path\to\protobuf> |
| 64 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 65 | Remember to update any submodules if you are using git clone (you can skip this |
| 66 | step if you are using a release .tar.gz or .zip package): |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 67 | |
Carlos O'Ryan | 3c5442a | 2018-03-26 16:54:32 -0400 | [diff] [blame] | 68 | ```console |
| 69 | C:\Path\to> git submodule update --init --recursive |
| 70 | ``` |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 71 | |
| 72 | Now go to *cmake* folder in protobuf sources: |
| 73 | |
Feng Xiao | 014e76e | 2018-03-29 12:11:50 -0700 | [diff] [blame] | 74 | C:\Path\to\protobuf>cd cmake |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 75 | C:\Path\to\protobuf\cmake> |
| 76 | |
| 77 | Good. Now you are ready to *CMake* configuration. |
| 78 | |
| 79 | CMake Configuration |
| 80 | =================== |
| 81 | |
| 82 | *CMake* supports a lot of different |
| 83 | [generators](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html) |
| 84 | for various native build systems. |
| 85 | We are only interested in |
| 86 | [Makefile](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#makefile-generators) |
| 87 | and |
| 88 | [Visual Studio](http://www.cmake.org/cmake/help/latest/manual/cmake-generators.7.html#visual-studio-generators) |
| 89 | generators. |
| 90 | |
| 91 | We will use shadow building to separate the temporary files from the protobuf source code. |
| 92 | |
| 93 | Create a temporary *build* folder and change your working directory to it: |
| 94 | |
| 95 | C:\Path\to\protobuf\cmake>mkdir build & cd build |
| 96 | C:\Path\to\protobuf\cmake\build> |
| 97 | |
| 98 | The *Makefile* generator can build the project in only one configuration, so you need to build |
| 99 | a separate folder for each configuration. |
| 100 | |
| 101 | To start using a *Release* configuration: |
| 102 | |
| 103 | C:\Path\to\protobuf\cmake\build>mkdir release & cd release |
| 104 | C:\Path\to\protobuf\cmake\build\release>cmake -G "NMake Makefiles" ^ |
| 105 | -DCMAKE_BUILD_TYPE=Release ^ |
| 106 | -DCMAKE_INSTALL_PREFIX=../../../../install ^ |
| 107 | ../.. |
| 108 | |
| 109 | It will generate *nmake* *Makefile* in current directory. |
| 110 | |
| 111 | To use *Debug* configuration: |
| 112 | |
| 113 | C:\Path\to\protobuf\cmake\build>mkdir debug & cd debug |
| 114 | C:\Path\to\protobuf\cmake\build\debug>cmake -G "NMake Makefiles" ^ |
| 115 | -DCMAKE_BUILD_TYPE=Debug ^ |
| 116 | -DCMAKE_INSTALL_PREFIX=../../../../install ^ |
| 117 | ../.. |
| 118 | |
| 119 | It will generate *nmake* *Makefile* in current directory. |
| 120 | |
| 121 | To create *Visual Studio* solution file: |
| 122 | |
Leif Gruenwoldt | 24e2d8c | 2015-10-16 15:53:23 -0400 | [diff] [blame] | 123 | C:\Path\to\protobuf\cmake\build>mkdir solution & cd solution |
Daniel Johansen | e93dea7 | 2019-10-17 14:27:00 +0200 | [diff] [blame] | 124 | C:\Path\to\protobuf\cmake\build\solution>cmake -G "Visual Studio 16 2019" ^ |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 125 | -DCMAKE_INSTALL_PREFIX=../../../../install ^ |
| 126 | ../.. |
| 127 | |
Leif Gruenwoldt | 24e2d8c | 2015-10-16 15:53:23 -0400 | [diff] [blame] | 128 | It will generate *Visual Studio* solution file *protobuf.sln* in current directory. |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 129 | |
| 130 | If the *gmock* directory does not exist, and you do not want to build protobuf unit tests, |
Leif Gruenwoldt | a9e6a8f | 2015-10-16 19:53:21 -0400 | [diff] [blame] | 131 | you need to add *cmake* command argument `-Dprotobuf_BUILD_TESTS=OFF` to disable testing. |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 132 | |
Daniel Johansen | e93dea7 | 2019-10-17 14:27:00 +0200 | [diff] [blame] | 133 | To make a *Visual Studio* file for Visual Studio 16 2019, create the *Visual Studio* |
debugx | 9fdb2cf | 2019-10-11 22:30:31 +0300 | [diff] [blame] | 134 | solution file above and edit the CMakeCache file. |
Xiang Dai | e479410 | 2019-02-21 11:28:50 +0800 | [diff] [blame] | 135 | |
dyyap | 4361398 | 2018-11-15 18:47:08 -0800 | [diff] [blame] | 136 | C:Path\to\protobuf\cmake\build\solution\CMakeCache |
Xiang Dai | e479410 | 2019-02-21 11:28:50 +0800 | [diff] [blame] | 137 | |
dyyap | 4361398 | 2018-11-15 18:47:08 -0800 | [diff] [blame] | 138 | Then create the *Visual Studio* solution file again |
| 139 | |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 140 | Compiling |
| 141 | ========= |
| 142 | |
| 143 | To compile protobuf: |
| 144 | |
| 145 | C:\Path\to\protobuf\cmake\build\release>nmake |
| 146 | |
| 147 | or |
| 148 | |
| 149 | C:\Path\to\protobuf\cmake\build\debug>nmake |
| 150 | |
| 151 | And wait for the compilation to finish. |
| 152 | |
Leif Gruenwoldt | 24e2d8c | 2015-10-16 15:53:23 -0400 | [diff] [blame] | 153 | If you prefer to use the IDE: |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 154 | |
| 155 | * Open the generated protobuf.sln file in Microsoft Visual Studio. |
| 156 | * Choose "Debug" or "Release" configuration as desired. |
| 157 | * From the Build menu, choose "Build Solution". |
| 158 | |
Leif Gruenwoldt | 24e2d8c | 2015-10-16 15:53:23 -0400 | [diff] [blame] | 159 | And wait for the compilation to finish. |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 160 | |
| 161 | Testing |
| 162 | ======= |
| 163 | |
Josh Haberman | fe96a21 | 2016-02-10 14:44:29 -0800 | [diff] [blame] | 164 | To run unit-tests, first you must compile protobuf as described above. |
| 165 | Then run: |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 166 | |
| 167 | C:\Path\to\protobuf\cmake\build\release>nmake check |
| 168 | |
| 169 | or |
| 170 | |
Leif Gruenwoldt | 24e2d8c | 2015-10-16 15:53:23 -0400 | [diff] [blame] | 171 | C:\Path\to\protobuf\cmake\build\debug>nmake check |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 172 | |
| 173 | You can also build project *check* from Visual Studio solution. |
| 174 | Yes, it may sound strange, but it works. |
| 175 | |
| 176 | You should see output similar to: |
| 177 | |
| 178 | Running main() from gmock_main.cc |
| 179 | [==========] Running 1546 tests from 165 test cases. |
Xiang Dai | e479410 | 2019-02-21 11:28:50 +0800 | [diff] [blame] | 180 | |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 181 | ... |
Xiang Dai | e479410 | 2019-02-21 11:28:50 +0800 | [diff] [blame] | 182 | |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 183 | [==========] 1546 tests from 165 test cases ran. (2529 ms total) |
| 184 | [ PASSED ] 1546 tests. |
| 185 | |
| 186 | To run specific tests: |
| 187 | |
| 188 | C:\Path\to\protobuf>cmake\build\release\tests.exe --gtest_filter=AnyTest* |
| 189 | Running main() from gmock_main.cc |
| 190 | Note: Google Test filter = AnyTest* |
| 191 | [==========] Running 3 tests from 1 test case. |
| 192 | [----------] Global test environment set-up. |
| 193 | [----------] 3 tests from AnyTest |
| 194 | [ RUN ] AnyTest.TestPackAndUnpack |
| 195 | [ OK ] AnyTest.TestPackAndUnpack (0 ms) |
| 196 | [ RUN ] AnyTest.TestPackAndUnpackAny |
| 197 | [ OK ] AnyTest.TestPackAndUnpackAny (0 ms) |
| 198 | [ RUN ] AnyTest.TestIs |
| 199 | [ OK ] AnyTest.TestIs (0 ms) |
| 200 | [----------] 3 tests from AnyTest (1 ms total) |
Xiang Dai | e479410 | 2019-02-21 11:28:50 +0800 | [diff] [blame] | 201 | |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 202 | [----------] Global test environment tear-down |
| 203 | [==========] 3 tests from 1 test case ran. (2 ms total) |
| 204 | [ PASSED ] 3 tests. |
| 205 | |
| 206 | Note that the tests must be run from the source folder. |
| 207 | |
| 208 | If all tests are passed, safely continue. |
| 209 | |
| 210 | Installing |
| 211 | ========== |
| 212 | |
| 213 | To install protobuf to the specified *install* folder: |
| 214 | |
| 215 | C:\Path\to\protobuf\cmake\build\release>nmake install |
| 216 | |
| 217 | or |
| 218 | |
Leif Gruenwoldt | 24e2d8c | 2015-10-16 15:53:23 -0400 | [diff] [blame] | 219 | C:\Path\to\protobuf\cmake\build\debug>nmake install |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 220 | |
| 221 | You can also build project *INSTALL* from Visual Studio solution. |
| 222 | It sounds not so strange and it works. |
| 223 | |
| 224 | This will create the following folders under the *install* location: |
| 225 | * bin - that contains protobuf *protoc.exe* compiler; |
Dongjoon Hyun | 7b08d49 | 2016-01-11 14:52:01 -0800 | [diff] [blame] | 226 | * include - that contains C++ headers and protobuf *.proto files; |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 227 | * lib - that contains linking libraries and *CMake* configuration files for *protobuf* package. |
| 228 | |
| 229 | Now you can if needed: |
| 230 | * Copy the contents of the include directory to wherever you want to put headers. |
| 231 | * Copy protoc.exe wherever you put build tools (probably somewhere in your PATH). |
| 232 | * Copy linking libraries libprotobuf[d].lib, libprotobuf-lite[d].lib, and libprotoc[d].lib wherever you put libraries. |
| 233 | |
| 234 | To avoid conflicts between the MSVC debug and release runtime libraries, when |
| 235 | compiling a debug build of your application, you may need to link against a |
| 236 | debug build of libprotobufd.lib with "d" postfix. Similarly, release builds should link against |
| 237 | release libprotobuf.lib library. |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 238 | |
| 239 | DLLs vs. static linking |
| 240 | ======================= |
| 241 | |
| 242 | Static linking is now the default for the Protocol Buffer libraries. Due to |
| 243 | issues with Win32's use of a separate heap for each DLL, as well as binary |
| 244 | compatibility issues between different versions of MSVC's STL library, it is |
| 245 | recommended that you use static linkage only. However, it is possible to |
| 246 | build libprotobuf and libprotoc as DLLs if you really want. To do this, |
| 247 | do the following: |
| 248 | |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 249 | * Add an additional flag `-Dprotobuf_BUILD_SHARED_LIBS=ON` when invoking cmake |
| 250 | * Follow the same steps as described in the above section. |
| 251 | * When compiling your project, make sure to `#define PROTOBUF_USE_DLLS`. |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 252 | |
| 253 | When distributing your software to end users, we strongly recommend that you |
| 254 | do NOT install libprotobuf.dll or libprotoc.dll to any shared location. |
| 255 | Instead, keep these libraries next to your binaries, in your application's |
| 256 | own install directory. C++ makes it very difficult to maintain binary |
| 257 | compatibility between releases, so it is likely that future versions of these |
| 258 | libraries will *not* be usable as drop-in replacements. |
| 259 | |
| 260 | If your project is itself a DLL intended for use by third-party software, we |
| 261 | recommend that you do NOT expose protocol buffer objects in your library's |
| 262 | public interface, and that you statically link protocol buffers into your |
| 263 | library. |
| 264 | |
| 265 | ZLib support |
| 266 | ============ |
| 267 | |
| 268 | If you want to include GzipInputStream and GzipOutputStream |
| 269 | (google/protobuf/io/gzip_stream.h) in libprotobuf, you will need to do a few |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 270 | additional steps. |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 271 | |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 272 | Obtain a copy of the zlib library. The pre-compiled DLL at zlib.net works. |
| 273 | You need prepare it: |
Feng Xiao | 2286ab3 | 2015-06-04 11:12:32 -0700 | [diff] [blame] | 274 | |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 275 | * Make sure zlib's two headers are in your `C:\Path\to\install\include` path |
| 276 | * Make sure zlib's linking libraries (*.lib file) is in your |
| 277 | `C:\Path\to\install\lib` library path. |
Feng Xiao | 2286ab3 | 2015-06-04 11:12:32 -0700 | [diff] [blame] | 278 | |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 279 | You can also compile it from source by yourself. |
| 280 | |
| 281 | Getting sources: |
| 282 | |
| 283 | C:\Path\to>git clone -b v1.2.8 https://github.com/madler/zlib.git |
| 284 | C:\Path\to>cd zlib |
| 285 | |
| 286 | Compiling and Installing: |
| 287 | |
| 288 | C:\Path\to\zlib>mkdir build & cd build |
| 289 | C:\Path\to\zlib\build>mkdir release & cd release |
| 290 | C:\Path\to\zlib\build\release>cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release ^ |
| 291 | -DCMAKE_INSTALL_PREFIX=../../../install ../.. |
| 292 | C:\Path\to\zlib\build\release>nmake & nmake install |
| 293 | |
| 294 | You can make *debug* version or use *Visual Studio* generator also as before for the |
| 295 | protobuf project. |
| 296 | |
| 297 | Now add *bin* folder from *install* to system *PATH*: |
| 298 | |
| 299 | C:\Path\to>set PATH=%PATH%;C:\Path\to\install\bin |
| 300 | |
| 301 | You need reconfigure protobuf with flag `-Dprotobuf_WITH_ZLIB=ON` when invoking cmake. |
| 302 | |
| 303 | Note that if you have compiled ZLIB yourself, as stated above, |
| 304 | further disable the option `-Dprotobuf_MSVC_STATIC_RUNTIME=OFF`. |
| 305 | |
| 306 | If it reports NOTFOUND for zlib_include or zlib_lib, you might haven't put |
| 307 | the headers or the .lib file in the right directory. |
| 308 | |
Abdul Sami | fe33c5f | 2018-02-21 12:17:55 +0500 | [diff] [blame] | 309 | If you already have ZLIB library and headers at some other location on your system then alternatively you can define following configuration flags to locate them: |
| 310 | |
| 311 | -DZLIB_INCLUDE_DIR=<path to dir containing zlib headers> |
| 312 | -DZLIB_LIB=<path to dir containing zlib> |
Xiang Dai | e479410 | 2019-02-21 11:28:50 +0800 | [diff] [blame] | 313 | |
Konstantin Podsvirov | 0f21c53 | 2015-10-09 10:46:53 +0300 | [diff] [blame] | 314 | Build and testing protobuf as usual. |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 315 | |
| 316 | Notes on Compiler Warnings |
| 317 | ========================== |
| 318 | |
| 319 | The following warnings have been disabled while building the protobuf libraries |
| 320 | and compiler. You may have to disable some of them in your own project as |
| 321 | well, or live with them. |
| 322 | |
Feng Xiao | 2286ab3 | 2015-06-04 11:12:32 -0700 | [diff] [blame] | 323 | * C4018 - 'expression' : signed/unsigned mismatch |
| 324 | * C4146 - unary minus operator applied to unsigned type, result still unsigned |
| 325 | * C4244 - Conversion from 'type1' to 'type2', possible loss of data. |
| 326 | * C4251 - 'identifier' : class 'type' needs to have dll-interface to be used by |
| 327 | clients of class 'type2' |
| 328 | * C4267 - Conversion from 'size_t' to 'type', possible loss of data. |
| 329 | * C4305 - 'identifier' : truncation from 'type1' to 'type2' |
| 330 | * C4355 - 'this' : used in base member initializer list |
| 331 | * C4800 - 'type' : forcing value to bool 'true' or 'false' (performance warning) |
| 332 | * C4996 - 'function': was declared deprecated |
Feng Xiao | 4333edb | 2015-05-31 02:28:34 -0700 | [diff] [blame] | 333 | |
| 334 | C4251 is of particular note, if you are compiling the Protocol Buffer library |
| 335 | as a DLL (see previous section). The protocol buffer library uses templates in |
| 336 | its public interfaces. MSVC does not provide any reasonable way to export |
| 337 | template classes from a DLL. However, in practice, it appears that exporting |
| 338 | templates is not necessary anyway. Since the complete definition of any |
| 339 | template is available in the header files, anyone importing the DLL will just |
| 340 | end up compiling instances of the templates into their own binary. The |
| 341 | Protocol Buffer implementation does not rely on static template members being |
| 342 | unique, so there should be no problem with this, but MSVC prints warning |
| 343 | nevertheless. So, we disable it. Unfortunately, this warning will also be |
| 344 | produced when compiling code which merely uses protocol buffers, meaning you |
| 345 | may have to disable it in your code too. |