瀏覽代碼

* Fix build on MSVC.
* Switch to statically-linked libraries instead of DLLs on MSVC.

kenton@google.com 17 年之前
父節點
當前提交
9b10f5845a

+ 48 - 44
CHANGES.txt

@@ -1,5 +1,5 @@
-2008-09-24 version 2.0.2:
-
+2008-09-29 version 2.0.2:
+
   General
   General
   * License changed from Apache 2.0 to New BSD.
   * License changed from Apache 2.0 to New BSD.
   * It is now possible to define custom "options", which are basically
   * It is now possible to define custom "options", which are basically
@@ -28,12 +28,12 @@
     predictable among other things.
     predictable among other things.
   * TextFormat will no longer accept messages which contain multiple
   * TextFormat will no longer accept messages which contain multiple
     instances of a singular field.  Previously, the latter instance
     instances of a singular field.  Previously, the latter instance
-    would overwrite the former.
+    would overwrite the former.
   * Now works on systems that don't have hash_map.
   * Now works on systems that don't have hash_map.
 
 
-  Java
-  * Print @Override annotation in generated code where appropriate.
-
+  Java
+  * Print @Override annotation in generated code where appropriate.
+
   Python
   Python
   * Strings now use the "unicode" type rather than the "str" type.
   * Strings now use the "unicode" type rather than the "str" type.
     String fields may still be assigned ASCII "str" values; they will
     String fields may still be assigned ASCII "str" values; they will
@@ -42,55 +42,59 @@
     raises an exception.  For example:
     raises an exception.  For example:
       # No longer works (and never should have).
       # No longer works (and never should have).
       message.some_repeated_field.foo = 1
       message.some_repeated_field.foo = 1
-
+
+  Windows
+  * We now build static libraries rather than DLLs by default on MSVC.
+    See vsprojects/readme.txt for more information.
+
 2008-08-15 version 2.0.1:
 2008-08-15 version 2.0.1:
-
-  protoc
-  * New flags --encode and --decode can be used to convert between protobuf text
-    format and binary format from the command-line.
-  * New flag --descriptor_set_out can be used to write FileDescriptorProtos for
-    all parsed files directly into a single output file.  This is particularly
-    useful if you wish to parse .proto files from programs written in languages
-    other than C++: just run protoc as a background process and have it output
-    a FileDescriptorList, then parse that natively.
-  * Improved error message when an enum value's name conflicts with another
-    symbol defined in the enum type's scope, e.g. if two enum types declared
-    in the same scope have values with the same name.  This is disallowed for
+
+  protoc
+  * New flags --encode and --decode can be used to convert between protobuf text
+    format and binary format from the command-line.
+  * New flag --descriptor_set_out can be used to write FileDescriptorProtos for
+    all parsed files directly into a single output file.  This is particularly
+    useful if you wish to parse .proto files from programs written in languages
+    other than C++: just run protoc as a background process and have it output
+    a FileDescriptorList, then parse that natively.
+  * Improved error message when an enum value's name conflicts with another
+    symbol defined in the enum type's scope, e.g. if two enum types declared
+    in the same scope have values with the same name.  This is disallowed for
     compatibility with C++, but this wasn't clear from the error.
     compatibility with C++, but this wasn't clear from the error.
-  * Fixed absolute output paths on Windows.
+  * Fixed absolute output paths on Windows.
   * Allow trailing slashes in --proto_path mappings.
   * Allow trailing slashes in --proto_path mappings.
-
-  C++
-  * Reflection objects are now per-class rather than per-instance.  To make this
-    possible, the Reflection interface had to be changed such that all methods
-    take the Message instance as a parameter.  This change improves performance
-    significantly in memory-bandwidth-limited use cases, since it makes the
-    message objects smaller.  Note that source-incompatible interface changes
-    like this will not be made again after the library leaves beta.
+
+  C++
+  * Reflection objects are now per-class rather than per-instance.  To make this
+    possible, the Reflection interface had to be changed such that all methods
+    take the Message instance as a parameter.  This change improves performance
+    significantly in memory-bandwidth-limited use cases, since it makes the
+    message objects smaller.  Note that source-incompatible interface changes
+    like this will not be made again after the library leaves beta.
   * Heuristically detect sub-messages when printing unknown fields.
   * Heuristically detect sub-messages when printing unknown fields.
-  * Fix static initialization ordering bug that caused crashes at startup when
+  * Fix static initialization ordering bug that caused crashes at startup when
     compiling on Mac with static linking.
     compiling on Mac with static linking.
-  * Fixed TokenizerTest when compiling with -DNDEBUG on Linux.
-  * Fixed incorrect definition of kint32min.
+  * Fixed TokenizerTest when compiling with -DNDEBUG on Linux.
+  * Fixed incorrect definition of kint32min.
   * Fix bytes type setter to work with byte sequences with embedded NULLs.
   * Fix bytes type setter to work with byte sequences with embedded NULLs.
   * Other irrelevant tweaks.
   * Other irrelevant tweaks.
 
 
-  Java
-  * Fixed UnknownFieldSet's parsing of varints larger than 32 bits.
-  * Fixed TextFormat's parsing of "inf" and "nan".
-  * Fixed TextFormat's parsing of comments.
-  * Added info to Java POM that will be required when we upload the
+  Java
+  * Fixed UnknownFieldSet's parsing of varints larger than 32 bits.
+  * Fixed TextFormat's parsing of "inf" and "nan".
+  * Fixed TextFormat's parsing of comments.
+  * Added info to Java POM that will be required when we upload the
     package to a Maven repo.
     package to a Maven repo.
 
 
-  Python
-  * MergeFrom(message) and CopyFrom(message) are now implemented.
-  * SerializeToString() raises an exception if the message is missing required
-    fields.
-  * Code organization improvements.
-  * Fixed doc comments for RpcController and RpcChannel, which had somehow been
+  Python
+  * MergeFrom(message) and CopyFrom(message) are now implemented.
+  * SerializeToString() raises an exception if the message is missing required
+    fields.
+  * Code organization improvements.
+  * Fixed doc comments for RpcController and RpcChannel, which had somehow been
     swapped.
     swapped.
-  * Fixed text_format_test on Windows where floating-point exponents sometimes
-    contain extra zeros.
+  * Fixed text_format_test on Windows where floating-point exponents sometimes
+    contain extra zeros.
   * Fix Python service CallMethod() implementation.
   * Fix Python service CallMethod() implementation.
 
 
   Other
   Other

+ 6 - 28
src/google/protobuf/compiler/cpp/cpp_file.cc

@@ -59,7 +59,8 @@ FileGenerator::FileGenerator(const FileDescriptor* file,
     service_generators_(
     service_generators_(
       new scoped_ptr<ServiceGenerator>[file->service_count()]),
       new scoped_ptr<ServiceGenerator>[file->service_count()]),
     extension_generators_(
     extension_generators_(
-      new scoped_ptr<ExtensionGenerator>[file->extension_count()]) {
+      new scoped_ptr<ExtensionGenerator>[file->extension_count()]),
+    dllexport_decl_(dllexport_decl) {
 
 
   for (int i = 0; i < file->message_type_count(); i++) {
   for (int i = 0; i < file->message_type_count(); i++) {
     message_generators_[i].reset(
     message_generators_[i].reset(
@@ -146,11 +147,13 @@ void FileGenerator::GenerateHeader(io::Printer* printer) {
   // declare it to be a friend of each class.
   // declare it to be a friend of each class.
   printer->Print(
   printer->Print(
     "\n"
     "\n"
-    "// Internal implementation detail -- do not call this.\n"
+    "// Internal implementation detail -- do not call these.\n"
+    "void $dllexport_decl$ $builddescriptorsname$();\n"
     "void $builddescriptorsname$_AssignGlobalDescriptors(\n"
     "void $builddescriptorsname$_AssignGlobalDescriptors(\n"
     "    ::google::protobuf::FileDescriptor* file);\n"
     "    ::google::protobuf::FileDescriptor* file);\n"
     "\n",
     "\n",
-    "builddescriptorsname", GlobalBuildDescriptorsName(file_->name()));
+    "builddescriptorsname", GlobalBuildDescriptorsName(file_->name()),
+    "dllexport_decl", dllexport_decl_);
 
 
   // Generate forward declarations of classes.
   // Generate forward declarations of classes.
   for (int i = 0; i < file_->message_type_count(); i++) {
   for (int i = 0; i < file_->message_type_count(); i++) {
@@ -235,31 +238,6 @@ void FileGenerator::GenerateSource(io::Printer* printer) {
     "#include <google/protobuf/wire_format_inl.h>\n",
     "#include <google/protobuf/wire_format_inl.h>\n",
     "basename", StripProto(file_->name()));
     "basename", StripProto(file_->name()));
 
 
-  // For each dependency, write a prototype for that dependency's
-  // BuildDescriptors() function.  We don't expose these in the header because
-  // they are internal implementation details, and since this is generated code
-  // we don't have the usual risks involved with declaring external functions
-  // within a .cc file.
-  for (int i = 0; i < file_->dependency_count(); i++) {
-    const FileDescriptor* dependency = file_->dependency(i);
-    // Open the dependency's namespace.
-    vector<string> dependency_package_parts;
-    SplitStringUsing(dependency->package(), ".", &dependency_package_parts);
-    for (int i = 0; i < dependency_package_parts.size(); i++) {
-      printer->Print("namespace $name$ { ",
-                     "name", dependency_package_parts[i]);
-    }
-    // Declare its BuildDescriptors() function.
-    printer->Print(
-      "void $function$();",
-      "function", GlobalBuildDescriptorsName(dependency->name()));
-    // Close the namespace.
-    for (int i = 0; i < dependency_package_parts.size(); i++) {
-      printer->Print(" }");
-    }
-    printer->Print("\n");
-  }
-
   GenerateNamespaceOpeners(printer);
   GenerateNamespaceOpeners(printer);
 
 
   printer->Print(
   printer->Print(

+ 2 - 0
src/google/protobuf/compiler/cpp/cpp_file.h

@@ -85,6 +85,8 @@ class FileGenerator {
   // E.g. if the package is foo.bar, package_parts_ is {"foo", "bar"}.
   // E.g. if the package is foo.bar, package_parts_ is {"foo", "bar"}.
   vector<string> package_parts_;
   vector<string> package_parts_;
 
 
+  string dllexport_decl_;
+
   GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator);
   GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator);
 };
 };
 
 

+ 2 - 1
src/google/protobuf/descriptor.pb.h

@@ -25,7 +25,8 @@
 namespace google {
 namespace google {
 namespace protobuf {
 namespace protobuf {
 
 
-// Internal implementation detail -- do not call this.
+// Internal implementation detail -- do not call these.
+void LIBPROTOBUF_EXPORT protobuf_BuildDesc_google_2fprotobuf_2fdescriptor_2eproto();
 void protobuf_BuildDesc_google_2fprotobuf_2fdescriptor_2eproto_AssignGlobalDescriptors(
 void protobuf_BuildDesc_google_2fprotobuf_2fdescriptor_2eproto_AssignGlobalDescriptors(
     ::google::protobuf::FileDescriptor* file);
     ::google::protobuf::FileDescriptor* file);
 
 

+ 1 - 1
src/google/protobuf/stubs/common.h

@@ -56,7 +56,7 @@ using namespace std;  // Don't do this at home, kids.
   TypeName(const TypeName&);                           \
   TypeName(const TypeName&);                           \
   void operator=(const TypeName&)
   void operator=(const TypeName&)
 
 
-#ifdef _MSC_VER
+#if defined(_MSC_VER) && defined(PROTOBUF_USE_DLLS)
   #ifdef LIBPROTOBUF_EXPORTS
   #ifdef LIBPROTOBUF_EXPORTS
     #define LIBPROTOBUF_EXPORT __declspec(dllexport)
     #define LIBPROTOBUF_EXPORT __declspec(dllexport)
   #else
   #else

+ 4 - 26
vsprojects/libprotobuf.vcproj

@@ -19,7 +19,7 @@
 			Name="Debug|Win32"
 			Name="Debug|Win32"
 			OutputDirectory="Debug"
 			OutputDirectory="Debug"
 			IntermediateDirectory="Debug"
 			IntermediateDirectory="Debug"
-			ConfigurationType="2"
+			ConfigurationType="4"
 			>
 			>
 			<Tool
 			<Tool
 				Name="VCPreBuildEventTool"
 				Name="VCPreBuildEventTool"
@@ -60,18 +60,11 @@
 				Name="VCPreLinkEventTool"
 				Name="VCPreLinkEventTool"
 			/>
 			/>
 			<Tool
 			<Tool
-				Name="VCLinkerTool"
-				LinkIncremental="2"
-				GenerateDebugInformation="true"
-				SubSystem="2"
-				TargetMachine="1"
+				Name="VCLibrarianTool"
 			/>
 			/>
 			<Tool
 			<Tool
 				Name="VCALinkTool"
 				Name="VCALinkTool"
 			/>
 			/>
-			<Tool
-				Name="VCManifestTool"
-			/>
 			<Tool
 			<Tool
 				Name="VCXDCMakeTool"
 				Name="VCXDCMakeTool"
 			/>
 			/>
@@ -81,9 +74,6 @@
 			<Tool
 			<Tool
 				Name="VCFxCopTool"
 				Name="VCFxCopTool"
 			/>
 			/>
-			<Tool
-				Name="VCAppVerifierTool"
-			/>
 			<Tool
 			<Tool
 				Name="VCPostBuildEventTool"
 				Name="VCPostBuildEventTool"
 			/>
 			/>
@@ -92,7 +82,7 @@
 			Name="Release|Win32"
 			Name="Release|Win32"
 			OutputDirectory="Release"
 			OutputDirectory="Release"
 			IntermediateDirectory="Release"
 			IntermediateDirectory="Release"
-			ConfigurationType="2"
+			ConfigurationType="4"
 			>
 			>
 			<Tool
 			<Tool
 				Name="VCPreBuildEventTool"
 				Name="VCPreBuildEventTool"
@@ -130,20 +120,11 @@
 				Name="VCPreLinkEventTool"
 				Name="VCPreLinkEventTool"
 			/>
 			/>
 			<Tool
 			<Tool
-				Name="VCLinkerTool"
-				LinkIncremental="2"
-				GenerateDebugInformation="true"
-				SubSystem="2"
-				OptimizeReferences="2"
-				EnableCOMDATFolding="2"
-				TargetMachine="1"
+				Name="VCLibrarianTool"
 			/>
 			/>
 			<Tool
 			<Tool
 				Name="VCALinkTool"
 				Name="VCALinkTool"
 			/>
 			/>
-			<Tool
-				Name="VCManifestTool"
-			/>
 			<Tool
 			<Tool
 				Name="VCXDCMakeTool"
 				Name="VCXDCMakeTool"
 			/>
 			/>
@@ -153,9 +134,6 @@
 			<Tool
 			<Tool
 				Name="VCFxCopTool"
 				Name="VCFxCopTool"
 			/>
 			/>
-			<Tool
-				Name="VCAppVerifierTool"
-			/>
 			<Tool
 			<Tool
 				Name="VCPostBuildEventTool"
 				Name="VCPostBuildEventTool"
 			/>
 			/>

+ 4 - 26
vsprojects/libprotoc.vcproj

@@ -19,7 +19,7 @@
 			Name="Debug|Win32"
 			Name="Debug|Win32"
 			OutputDirectory="Debug"
 			OutputDirectory="Debug"
 			IntermediateDirectory="Debug"
 			IntermediateDirectory="Debug"
-			ConfigurationType="2"
+			ConfigurationType="4"
 			>
 			>
 			<Tool
 			<Tool
 				Name="VCPreBuildEventTool"
 				Name="VCPreBuildEventTool"
@@ -60,18 +60,11 @@
 				Name="VCPreLinkEventTool"
 				Name="VCPreLinkEventTool"
 			/>
 			/>
 			<Tool
 			<Tool
-				Name="VCLinkerTool"
-				LinkIncremental="2"
-				GenerateDebugInformation="true"
-				SubSystem="2"
-				TargetMachine="1"
+				Name="VCLibrarianTool"
 			/>
 			/>
 			<Tool
 			<Tool
 				Name="VCALinkTool"
 				Name="VCALinkTool"
 			/>
 			/>
-			<Tool
-				Name="VCManifestTool"
-			/>
 			<Tool
 			<Tool
 				Name="VCXDCMakeTool"
 				Name="VCXDCMakeTool"
 			/>
 			/>
@@ -81,9 +74,6 @@
 			<Tool
 			<Tool
 				Name="VCFxCopTool"
 				Name="VCFxCopTool"
 			/>
 			/>
-			<Tool
-				Name="VCAppVerifierTool"
-			/>
 			<Tool
 			<Tool
 				Name="VCPostBuildEventTool"
 				Name="VCPostBuildEventTool"
 			/>
 			/>
@@ -92,7 +82,7 @@
 			Name="Release|Win32"
 			Name="Release|Win32"
 			OutputDirectory="Release"
 			OutputDirectory="Release"
 			IntermediateDirectory="Release"
 			IntermediateDirectory="Release"
-			ConfigurationType="2"
+			ConfigurationType="4"
 			>
 			>
 			<Tool
 			<Tool
 				Name="VCPreBuildEventTool"
 				Name="VCPreBuildEventTool"
@@ -130,20 +120,11 @@
 				Name="VCPreLinkEventTool"
 				Name="VCPreLinkEventTool"
 			/>
 			/>
 			<Tool
 			<Tool
-				Name="VCLinkerTool"
-				LinkIncremental="2"
-				GenerateDebugInformation="true"
-				SubSystem="2"
-				OptimizeReferences="2"
-				EnableCOMDATFolding="2"
-				TargetMachine="1"
+				Name="VCLibrarianTool"
 			/>
 			/>
 			<Tool
 			<Tool
 				Name="VCALinkTool"
 				Name="VCALinkTool"
 			/>
 			/>
-			<Tool
-				Name="VCManifestTool"
-			/>
 			<Tool
 			<Tool
 				Name="VCXDCMakeTool"
 				Name="VCXDCMakeTool"
 			/>
 			/>
@@ -153,9 +134,6 @@
 			<Tool
 			<Tool
 				Name="VCFxCopTool"
 				Name="VCFxCopTool"
 			/>
 			/>
-			<Tool
-				Name="VCAppVerifierTool"
-			/>
 			<Tool
 			<Tool
 				Name="VCPostBuildEventTool"
 				Name="VCPostBuildEventTool"
 			/>
 			/>

+ 21 - 10
vsprojects/readme.txt

@@ -24,27 +24,37 @@ Compiling and Installing
   build of libprotobuf.dll.  Similarly, release builds must link against
   build of libprotobuf.dll.  Similarly, release builds must link against
   release DLLs.
   release DLLs.
 
 
-DLLs and Distribution
-=====================
+DLLs vs. static linking
+=======================
+
+Static linking is now the default for the Protocol Buffer libraries.  Due to
+issues with Win32's use of a separate heap for each DLL, as well as binary
+compatibility issues between different versions of MSVC's STL library, it is
+recommended that you use static linkage only.  However, it is possible to
+build libprotobuf and libprotoc as DLLs if you really want.  To do this,
+do the following:
+
+  1) Open protobuf.sln in MSVC.
+  2) For each of the projects libprotobuf and libprotoc, do the following:
+    2a) Right-click the project and choose "properties".
+    2b) From the side bar, choose "General", under "Configuration Properties".
+    2c) Change the "Configuration Type" to "Dynamic Library (.dll)".
+    2d) From the side bar, choose "Preprocessor", under "C/C++".
+    2e) Add PROTOBUF_USE_DLLS to the list of preprocessor defines.
+  3) When compiling your project, make sure to #define PROTOBUF_USE_DLLS.
 
 
 When distributing your software to end users, we strongly recommend that you
 When distributing your software to end users, we strongly recommend that you
 do NOT install libprotobuf.dll or libprotoc.dll to any shared location.
 do NOT install libprotobuf.dll or libprotoc.dll to any shared location.
 Instead, keep these libraries next to your binaries, in your application's
 Instead, keep these libraries next to your binaries, in your application's
 own install directory.  C++ makes it very difficult to maintain binary
 own install directory.  C++ makes it very difficult to maintain binary
 compatibility between releases, so it is likely that future versions of these
 compatibility between releases, so it is likely that future versions of these
-libraries will *not* be usable as drop-in replacements.  The only reason we
-provide these libraries as DLLs rather than static libs is so that a program
-which is itself split into multiple DLLs can safely pass protocol buffer
-objects between them.
+libraries will *not* be usable as drop-in replacements.
 
 
 If your project is itself a DLL intended for use by third-party software, we
 If your project is itself a DLL intended for use by third-party software, we
 recommend that you do NOT expose protocol buffer objects in your library's
 recommend that you do NOT expose protocol buffer objects in your library's
 public interface, and that you statically link protocol buffers into your
 public interface, and that you statically link protocol buffers into your
 library.
 library.
 
 
-TODO(kenton):  This sounds kind of scary.  Maybe we should only provide static
-  libraries?
-
 Notes on Compiler Warnings
 Notes on Compiler Warnings
 ==========================
 ==========================
 
 
@@ -63,7 +73,8 @@ C4355 - 'this' : used in base member initializer list
 C4800 - 'type' : forcing value to bool 'true' or 'false' (performance warning)
 C4800 - 'type' : forcing value to bool 'true' or 'false' (performance warning)
 C4996 - 'function': was declared deprecated
 C4996 - 'function': was declared deprecated
 
 
-C4251 is of particular note.  The protocol buffer library uses templates in
+C4251 is of particular note, if you are compiling the Protocol Buffer library
+as a DLL (see previous section).  The protocol buffer library uses templates in
 its public interfaces.  MSVC does not provide any reasonable way to export
 its public interfaces.  MSVC does not provide any reasonable way to export
 template classes from a DLL.  However, in practice, it appears that exporting
 template classes from a DLL.  However, in practice, it appears that exporting
 templates is not necessary anyway.  Since the complete definition of any
 templates is not necessary anyway.  Since the complete definition of any

+ 32 - 0
vsprojects/tests.vcproj

@@ -262,6 +262,10 @@
 				RelativePath=".\google\protobuf\unittest_embed_optimize_for.pb.h"
 				RelativePath=".\google\protobuf\unittest_embed_optimize_for.pb.h"
 				>
 				>
 			</File>
 			</File>
+			<File
+				RelativePath=".\google\protobuf\unittest_custom_options.pb.h"
+				>
+			</File>
 		</Filter>
 		</Filter>
 		<Filter
 		<Filter
 			Name="Resource Files"
 			Name="Resource Files"
@@ -406,6 +410,10 @@
 				RelativePath=".\google\protobuf\unittest_embed_optimize_for.pb.cc"
 				RelativePath=".\google\protobuf\unittest_embed_optimize_for.pb.cc"
 				>
 				>
 			</File>
 			</File>
+			<File
+				RelativePath=".\google\protobuf\unittest_custom_options.pb.cc"
+				>
+			</File>
 			<File
 			<File
 				RelativePath="..\src\google\protobuf\unknown_field_set_unittest.cc"
 				RelativePath="..\src\google\protobuf\unknown_field_set_unittest.cc"
 				>
 				>
@@ -563,6 +571,30 @@
 				/>
 				/>
 			</FileConfiguration>
 			</FileConfiguration>
 		</File>
 		</File>
+		<File
+			RelativePath="..\src\google\protobuf\unittest_custom_options.proto"
+			>
+			<FileConfiguration
+				Name="Debug|Win32"
+				>
+				<Tool
+					Name="VCCustomBuildTool"
+					Description="Generating unittest_custom_options.pb.{h,cc}..."
+					CommandLine="Debug\protoc -I../src --cpp_out=. ../src/google/protobuf/unittest_custom_options.proto&#x0D;&#x0A;"
+					Outputs="google\protobuf\unittest_custom_options.pb.h;google\protobuf\unittest_custom_options.pb.cc"
+				/>
+			</FileConfiguration>
+			<FileConfiguration
+				Name="Release|Win32"
+				>
+				<Tool
+					Name="VCCustomBuildTool"
+					Description="Generating unittest_custom_options.pb.{h,cc}..."
+					CommandLine="Release\protoc -I../src --cpp_out=. ../src/google/protobuf/unittest_custom_options.proto&#x0D;&#x0A;"
+					Outputs="google\protobuf\unittest_custom_options.pb.h;google\protobuf\unittest_custom_options.pb.cc"
+				/>
+			</FileConfiguration>
+		</File>
 	</Files>
 	</Files>
 	<Globals>
 	<Globals>
 	</Globals>
 	</Globals>