readme.txt 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. This directory contains project files for compiling Protocol Buffers using
  2. MSVC. This is not the recommended way to do Protocol Buffer development --
  3. we prefer to develop under a Unix-like environment -- but it may be more
  4. accessible to those who primarily work with MSVC.
  5. Compiling and Installing
  6. ========================
  7. 0) Check whether a gtest directory exists in the upper level directory. If
  8. you checkout the code from github via "git clone", this gtest directory
  9. won't exist and you won't be able to build the tests described below. To
  10. avoid this problem consider downloading one of the release tar balls which
  11. contains gtest already and copying the gest directory from there to your
  12. protobuf directory:
  13. https://github.com/google/protobuf/releases
  14. 1) Open protobuf.sln in Microsoft Visual Studio.
  15. 2) Choose "Debug" or "Release" configuration as desired.*
  16. 3) From the Build menu, choose "Build Solution". Wait for compiling to finish.
  17. 4) From a command shell, run tests.exe and lite-test.exe and check that all
  18. tests pass.
  19. 5) Run extract_includes.bat to copy all the public headers into a separate
  20. "include" directory (under the top-level package directory).
  21. 6) Copy the contents of the include directory to wherever you want to put
  22. headers.
  23. 7) Copy protoc.exe wherever you put build tools (probably somewhere in your
  24. PATH).
  25. 8) Copy libprotobuf.lib, libprotobuf-lite.lib, and libprotoc.lib wherever you
  26. put libraries.
  27. * To avoid conflicts between the MSVC debug and release runtime libraries, when
  28. compiling a debug build of your application, you may need to link against a
  29. debug build of libprotobuf.lib. Similarly, release builds should link against
  30. release libs.
  31. DLLs vs. static linking
  32. =======================
  33. Static linking is now the default for the Protocol Buffer libraries. Due to
  34. issues with Win32's use of a separate heap for each DLL, as well as binary
  35. compatibility issues between different versions of MSVC's STL library, it is
  36. recommended that you use static linkage only. However, it is possible to
  37. build libprotobuf and libprotoc as DLLs if you really want. To do this,
  38. do the following:
  39. 1) Open protobuf.sln in MSVC.
  40. 2) For each of the projects libprotobuf, libprotobuf-lite, and libprotoc, do
  41. the following:
  42. 2a) Right-click the project and choose "properties".
  43. 2b) From the side bar, choose "General", under "Configuration Properties".
  44. 2c) Change the "Configuration Type" to "Dynamic Library (.dll)".
  45. 2d) From the side bar, choose "Preprocessor", under "C/C++".
  46. 2e) Add PROTOBUF_USE_DLLS to the list of preprocessor defines.
  47. 3) When compiling your project, make sure to #define PROTOBUF_USE_DLLS.
  48. When distributing your software to end users, we strongly recommend that you
  49. do NOT install libprotobuf.dll or libprotoc.dll to any shared location.
  50. Instead, keep these libraries next to your binaries, in your application's
  51. own install directory. C++ makes it very difficult to maintain binary
  52. compatibility between releases, so it is likely that future versions of these
  53. libraries will *not* be usable as drop-in replacements.
  54. If your project is itself a DLL intended for use by third-party software, we
  55. recommend that you do NOT expose protocol buffer objects in your library's
  56. public interface, and that you statically link protocol buffers into your
  57. library.
  58. ZLib support
  59. ============
  60. If you want to include GzipInputStream and GzipOutputStream
  61. (google/protobuf/io/gzip_stream.h) in libprotoc, you will need to do a few
  62. additional steps:
  63. 1) Obtain a copy of the zlib library. The pre-compiled DLL at zlib.net works.
  64. 2) Make sure zlib's two headers are in your include path and that the .lib file
  65. is in your library path. You could place all three files directly into the
  66. vsproject directory to compile libprotobuf, but they need to be visible to
  67. your own project as well, so you should probably just put them into the
  68. VC shared icnlude and library directories.
  69. 3) Right-click on the "tests" project and choose "properties". Navigate the
  70. sidebar to "Configuration Properties" -> "Linker" -> "Input".
  71. 4) Under "Additional Dependencies", add the name of the zlib .lib file (e.g.
  72. zdll.lib). Make sure to update both the Debug and Release configurations.
  73. 5) If you are compiling libprotobuf and libprotoc as DLLs (see previous
  74. section), repeat steps 2 and 3 for the libprotobuf and libprotoc projects.
  75. If you are compiling them as static libraries, then you will need to link
  76. against the zlib library directly from your own app.
  77. 6) Edit config.h (in the vsprojects directory) and un-comment the line that
  78. #defines HAVE_ZLIB. (Or, alternatively, define this macro via the project
  79. settings.)
  80. Notes on Compiler Warnings
  81. ==========================
  82. The following warnings have been disabled while building the protobuf libraries
  83. and compiler. You may have to disable some of them in your own project as
  84. well, or live with them.
  85. C4018 - 'expression' : signed/unsigned mismatch
  86. C4146 - unary minus operator applied to unsigned type, result still unsigned
  87. C4244 - Conversion from 'type1' to 'type2', possible loss of data.
  88. C4251 - 'identifier' : class 'type' needs to have dll-interface to be used by
  89. clients of class 'type2'
  90. C4267 - Conversion from 'size_t' to 'type', possible loss of data.
  91. C4305 - 'identifier' : truncation from 'type1' to 'type2'
  92. C4355 - 'this' : used in base member initializer list
  93. C4800 - 'type' : forcing value to bool 'true' or 'false' (performance warning)
  94. C4996 - 'function': was declared deprecated
  95. C4251 is of particular note, if you are compiling the Protocol Buffer library
  96. as a DLL (see previous section). The protocol buffer library uses templates in
  97. its public interfaces. MSVC does not provide any reasonable way to export
  98. template classes from a DLL. However, in practice, it appears that exporting
  99. templates is not necessary anyway. Since the complete definition of any
  100. template is available in the header files, anyone importing the DLL will just
  101. end up compiling instances of the templates into their own binary. The
  102. Protocol Buffer implementation does not rely on static template members being
  103. unique, so there should be no problem with this, but MSVC prints warning
  104. nevertheless. So, we disable it. Unfortunately, this warning will also be
  105. produced when compiling code which merely uses protocol buffers, meaning you
  106. may have to disable it in your code too.