Commit 9b10f584 authored by kenton@google.com's avatar kenton@google.com

* Fix build on MSVC.

* Switch to statically-linked libraries instead of DLLs on MSVC.
parent 0b3023fa
2008-09-24 version 2.0.2:
2008-09-29 version 2.0.2:
General
* License changed from Apache 2.0 to New BSD.
......@@ -43,6 +43,10 @@
# No longer works (and never should have).
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:
protoc
......
......@@ -59,7 +59,8 @@ FileGenerator::FileGenerator(const FileDescriptor* file,
service_generators_(
new scoped_ptr<ServiceGenerator>[file->service_count()]),
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++) {
message_generators_[i].reset(
......@@ -146,11 +147,13 @@ void FileGenerator::GenerateHeader(io::Printer* printer) {
// declare it to be a friend of each class.
printer->Print(
"\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"
" ::google::protobuf::FileDescriptor* file);\n"
"\n",
"builddescriptorsname", GlobalBuildDescriptorsName(file_->name()));
"builddescriptorsname", GlobalBuildDescriptorsName(file_->name()),
"dllexport_decl", dllexport_decl_);
// Generate forward declarations of classes.
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",
"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);
printer->Print(
......
......@@ -85,6 +85,8 @@ class FileGenerator {
// E.g. if the package is foo.bar, package_parts_ is {"foo", "bar"}.
vector<string> package_parts_;
string dllexport_decl_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator);
};
......
......@@ -25,7 +25,8 @@
namespace google {
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(
::google::protobuf::FileDescriptor* file);
......
......@@ -56,7 +56,7 @@ using namespace std; // Don't do this at home, kids.
TypeName(const TypeName&); \
void operator=(const TypeName&)
#ifdef _MSC_VER
#if defined(_MSC_VER) && defined(PROTOBUF_USE_DLLS)
#ifdef LIBPROTOBUF_EXPORTS
#define LIBPROTOBUF_EXPORT __declspec(dllexport)
#else
......
......@@ -19,7 +19,7 @@
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="2"
ConfigurationType="4"
>
<Tool
Name="VCPreBuildEventTool"
......@@ -60,18 +60,11 @@
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
......@@ -81,9 +74,6 @@
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
......@@ -92,7 +82,7 @@
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="2"
ConfigurationType="4"
>
<Tool
Name="VCPreBuildEventTool"
......@@ -130,20 +120,11 @@
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
......@@ -153,9 +134,6 @@
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
......
......@@ -19,7 +19,7 @@
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="2"
ConfigurationType="4"
>
<Tool
Name="VCPreBuildEventTool"
......@@ -60,18 +60,11 @@
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
......@@ -81,9 +74,6 @@
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
......@@ -92,7 +82,7 @@
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="2"
ConfigurationType="4"
>
<Tool
Name="VCPreBuildEventTool"
......@@ -130,20 +120,11 @@
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
......@@ -153,9 +134,6 @@
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
......
......@@ -24,27 +24,37 @@ Compiling and Installing
build of libprotobuf.dll. Similarly, release builds must link against
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
do NOT install libprotobuf.dll or libprotoc.dll to any shared location.
Instead, keep these libraries next to your binaries, in your application's
own install directory. C++ makes it very difficult to maintain binary
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
recommend that you do NOT expose protocol buffer objects in your library's
public interface, and that you statically link protocol buffers into your
library.
TODO(kenton): This sounds kind of scary. Maybe we should only provide static
libraries?
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)
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
template classes from a DLL. However, in practice, it appears that exporting
templates is not necessary anyway. Since the complete definition of any
......
......@@ -262,6 +262,10 @@
RelativePath=".\google\protobuf\unittest_embed_optimize_for.pb.h"
>
</File>
<File
RelativePath=".\google\protobuf\unittest_custom_options.pb.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
......@@ -406,6 +410,10 @@
RelativePath=".\google\protobuf\unittest_embed_optimize_for.pb.cc"
>
</File>
<File
RelativePath=".\google\protobuf\unittest_custom_options.pb.cc"
>
</File>
<File
RelativePath="..\src\google\protobuf\unknown_field_set_unittest.cc"
>
......@@ -563,6 +571,30 @@
/>
</FileConfiguration>
</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>
<Globals>
</Globals>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment