THRIFT-3873: fix various compiler warnings and overflow errors
THRIFT-3847: change VERSION to PACKAGE_VERSION to avoid conflicts with third party or OS headers

This closes #1128
diff --git a/lib/cpp/test/AllProtocolTests.tcc b/lib/cpp/test/AllProtocolTests.tcc
index 8c8eaa8..3e0b833 100644
--- a/lib/cpp/test/AllProtocolTests.tcc
+++ b/lib/cpp/test/AllProtocolTests.tcc
@@ -190,14 +190,14 @@
 
     testNaked<TProto, int64_t>(0);
     for (int64_t i = 0; i < 62; i++) {
-      testNaked<TProto, int64_t>(1L << i);
-      testNaked<TProto, int64_t>(-(1L << i));
+      testNaked<TProto, int64_t>(1LL << i);
+      testNaked<TProto, int64_t>(-(1LL << i));
     }
 
     testField<TProto, T_I64, int64_t>(0);
     for (int i = 0; i < 62; i++) {
-      testField<TProto, T_I64, int64_t>(1L << i);
-      testField<TProto, T_I64, int64_t>(-(1L << i));
+      testField<TProto, T_I64, int64_t>(1LL << i);
+      testField<TProto, T_I64, int64_t>(-(1LL << i));
     }
 
     testNaked<TProto, double>(123.456);
diff --git a/lib/cpp/test/CMakeLists.txt b/lib/cpp/test/CMakeLists.txt
index cbeff08..74b0a09 100644
--- a/lib/cpp/test/CMakeLists.txt
+++ b/lib/cpp/test/CMakeLists.txt
@@ -19,7 +19,13 @@
 
 include_directories(SYSTEM "${Boost_INCLUDE_DIRS}")
 
-#Make sure gen-cpp files can be included
+add_definitions("-D__STDC_LIMIT_MACROS")
+
+if (WITH_DYN_LINK_TEST)
+    add_definitions( -DBOOST_TEST_DYN_LINK )
+endif()
+
+# Make sure gen-cpp files can be included
 include_directories("${CMAKE_CURRENT_BINARY_DIR}")
 
 # Create the thrift C++ test library
@@ -54,7 +60,6 @@
 )
 add_library(testgencpp_cob STATIC ${testgencpp_cob_SOURCES})
 
-
 add_executable(Benchmark Benchmark.cpp)
 target_link_libraries(Benchmark testgencpp)
 LINK_AGAINST_THRIFT_LIBRARY(Benchmark thrift)
diff --git a/lib/cpp/test/JSONProtoTest.cpp b/lib/cpp/test/JSONProtoTest.cpp
index 301a064..2da3044 100644
--- a/lib/cpp/test/JSONProtoTest.cpp
+++ b/lib/cpp/test/JSONProtoTest.cpp
@@ -262,8 +262,9 @@
   ":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2,3]},\"14\":{\"lst\":[\"i64"
   "\",3,1,2,3]}}";
 
+  const std::size_t bufSiz = strlen(json_string) * sizeof(char);
   boost::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(
-    (uint8_t*)(json_string), strlen(json_string)*sizeof(char)));
+    (uint8_t*)(json_string), static_cast<uint32_t>(bufSiz)));
   boost::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
 
   OneOfEach ooe2;
diff --git a/lib/cpp/test/ZlibTest.cpp b/lib/cpp/test/ZlibTest.cpp
index e155970..a4387a9 100644
--- a/lib/cpp/test/ZlibTest.cpp
+++ b/lib/cpp/test/ZlibTest.cpp
@@ -17,13 +17,19 @@
  * under the License.
  */
 
-#define __STDC_FORMAT_MACROS
-
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE // needed for getopt_long
 #endif
 
+#if (_MSC_VER <= 1700)
+// polynomial and std::fill_t warning happens in MSVC 2010, 2013, maybe others
+// https://svn.boost.org/trac/boost/ticket/11426
+#pragma warning(disable:4996)
+#endif
+
+#ifdef HAVE_STDINT_H
 #include <stdint.h>
+#endif
 #ifdef HAVE_INTTYPES_H
 #include <inttypes.h>
 #endif
diff --git a/lib/cpp/test/processor/ServerThread.cpp b/lib/cpp/test/processor/ServerThread.cpp
index e9d468f..009c4c6 100644
--- a/lib/cpp/test/processor/ServerThread.cpp
+++ b/lib/cpp/test/processor/ServerThread.cpp
@@ -35,6 +35,8 @@
   assert(!running_);
   running_ = true;
 
+  helper_.reset(new Helper(this));
+
   // Start the other thread
   concurrency::PlatformThreadFactory threadFactory;
   threadFactory.setDetached(false);
diff --git a/lib/cpp/test/processor/ServerThread.h b/lib/cpp/test/processor/ServerThread.h
index eed3469..3803e7e 100644
--- a/lib/cpp/test/processor/ServerThread.h
+++ b/lib/cpp/test/processor/ServerThread.h
@@ -71,8 +71,7 @@
 class ServerThread {
 public:
   ServerThread(const boost::shared_ptr<ServerState>& state, bool autoStart)
-    : helper_(new Helper(this)),
-      port_(0),
+    : port_(0),
       running_(false),
       serving_(false),
       error_(false),