From 6ba1084f244f48d118f22a31d42dc00b8258a469 Mon Sep 17 00:00:00 2001 From: Kai Liu Date: Thu, 27 Feb 2014 22:15:30 -0800 Subject: [PATCH] Fix some compilation bugs in different platforms Summary: detect some problems when testing my 3rd party release tool. --- Makefile | 8 ++++++-- util/auto_roll_logger_test.cc | 4 ++-- util/thread_local_test.cc | 12 ++++++------ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 6eef8bec0b..9e24806737 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,10 @@ OPT += -O2 -fno-omit-frame-pointer -momit-leaf-frame-pointer else OPT += -fno-omit-frame-pointer -momit-leaf-frame-pointer endif + +ifeq ($(MAKECMDGOALS),shared_lib) +PLATFORM_SHARED_LDFLAGS=-fPIC +endif #----------------------------------------------- # detect what platform we're building on @@ -135,8 +139,8 @@ $(SHARED2): $(SHARED3) ln -fs $(SHARED3) $(SHARED2) endif -$(SHARED3): $(LIBOBJECTS) - $(CXX) $(PLATFORM_SHARED_LDFLAGS)$(SHARED2) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) $(LDFLAGS) $(SOURCES)-o $@ +$(SHARED3): + $(CXX) $(PLATFORM_SHARED_LDFLAGS)$(SHARED2) $(CXXFLAGS) $(PLATFORM_SHARED_CFLAGS) $(LDFLAGS) $(SOURCES) -o $@ endif # PLATFORM_SHARED_EXT diff --git a/util/auto_roll_logger_test.cc b/util/auto_roll_logger_test.cc index 423ef416bb..7e30a27771 100755 --- a/util/auto_roll_logger_test.cc +++ b/util/auto_roll_logger_test.cc @@ -245,7 +245,7 @@ TEST(AutoRollLoggerTest, InfoLogLevel) { InitTestDb(); size_t log_size = 8192; - int log_lines = 0; + size_t log_lines = 0; // an extra-scope to force the AutoRollLogger to flush the log file when it // becomes out of scope. { @@ -275,7 +275,7 @@ TEST(AutoRollLoggerTest, InfoLogLevel) { } } std::ifstream inFile(AutoRollLoggerTest::kLogFile.c_str()); - int lines = std::count(std::istreambuf_iterator(inFile), + size_t lines = std::count(std::istreambuf_iterator(inFile), std::istreambuf_iterator(), '\n'); ASSERT_EQ(log_lines, lines); inFile.close(); diff --git a/util/thread_local_test.cc b/util/thread_local_test.cc index 2d663f31ce..96e35d9592 100644 --- a/util/thread_local_test.cc +++ b/util/thread_local_test.cc @@ -103,7 +103,7 @@ TEST(ThreadLocalTest, UniqueIdTest) { TEST(ThreadLocalTest, SequentialReadWriteTest) { // global id list carries over 3, 1, 2, 0 - ASSERT_EQ(IDChecker::PeekId(), 0); + ASSERT_EQ(IDChecker::PeekId(), 0u); port::Mutex mu; port::CondVar cv(&mu); @@ -133,7 +133,7 @@ TEST(ThreadLocalTest, SequentialReadWriteTest) { }; for (int iter = 0; iter < 1024; ++iter) { - ASSERT_EQ(IDChecker::PeekId(), 1); + ASSERT_EQ(IDChecker::PeekId(), 1u); // Another new thread, read/write should not see value from previous thread env_->StartThread(func, static_cast(&p)); mu.Lock(); @@ -141,13 +141,13 @@ TEST(ThreadLocalTest, SequentialReadWriteTest) { cv.Wait(); } mu.Unlock(); - ASSERT_EQ(IDChecker::PeekId(), 1); + ASSERT_EQ(IDChecker::PeekId(), 1u); } } TEST(ThreadLocalTest, ConcurrentReadWriteTest) { // global id list carries over 3, 1, 2, 0 - ASSERT_EQ(IDChecker::PeekId(), 0); + ASSERT_EQ(IDChecker::PeekId(), 0u); ThreadLocalPtr tls2; port::Mutex mu1; @@ -226,11 +226,11 @@ TEST(ThreadLocalTest, ConcurrentReadWriteTest) { } mu2.Unlock(); - ASSERT_EQ(IDChecker::PeekId(), 3); + ASSERT_EQ(IDChecker::PeekId(), 3u); } TEST(ThreadLocalTest, Unref) { - ASSERT_EQ(IDChecker::PeekId(), 0); + ASSERT_EQ(IDChecker::PeekId(), 0u); auto unref = [](void* ptr) { auto& p = *static_cast(ptr);