abseil / abseil-cpp

Abseil Common Libraries (C++)

Home Page:https://abseil.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Linking error when C++17 is used.

wkyu2kg opened this issue · comments

I am using C++17 to compile google-cloud-cpp and abseil. However, google-cloud-cpp always complains that some abseil functions are missing due to the mismatched signature.

std::string FormatTime(absl::string_view format, absl::Time t,
absl::TimeZone tz) {
if (t == absl::InfiniteFuture()) return std::string(kInfiniteFutureStr);
if (t == absl::InfinitePast()) return std::string(kInfinitePastStr);
const auto parts = Split(t);
return cctz::detail::format(std::string(format), parts.sec, parts.fem,
cctz::time_zone(tz));
}

Here are a few examples.

user_agent_prefix.cc:(.text._ZN4absl12lts_202103246StrCatIJNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEA3_cS7_A2_cEEES7_RKNS0_8AlphaNumESC_SC_SC_SC_DpRKT_[_ZN4absl12lts_202103246StrCatIJNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEA3_cS7_A2_cEEES7_RKNS0_8AlphaNumESC_SC_SC_SC_DpRKT_]+0x1b2): undefined reference to `absl::lts_20210324::strings_internal::CatPieces[abi:cxx11](std::initializer_list<std::basic_string_view<char, std::char_traits<char> > >)'
/home/wkyu/anaconda3/envs/meta-katana-dev/bin/../lib/gcc/x86_64-conda-linux-gnu/10.3.0/../../../../x86_64-conda-linux-gnu/bin/ld: ../google-cloud-cpp-prefix/lib/libgoogle_cloud_cpp_common.a(log.cc.o): in function `google::cloud::v1_40_1::(anonymous namespace)::operator<<(std::ostream&, google::cloud::v1_40_1::(anonymous namespace)::Timestamp const&)':
log.cc:(.text+0xaa): undefined reference to `absl::lts_20210324::FormatTime[abi:cxx11](std::basic_string_view<char, std::char_traits<char> >, absl::lts_20210324::Time, absl::lts_20210324::TimeZone)'

When compiling abseil with C++17 and google-cloud-cpp with C++11, there is no linking error. The required functions from google-cloud-cpp then use std::string_view as shown by the examples from CatPieces and FormatTime. But this would result in a run-time error because of the mixed compilers used.

_ZN4absl12lts_2021032410FormatTimeB5cxx11ENS0_11string_viewENS0_4TimeENS0_8TimeZoneE

_ZN4absl12lts_2021032416strings_internal9CatPiecesB5cxx11ESt16initializer_listINS0_11string_viewE

Can somebody please suggest a way to compile abseil differently for it to generate functions with std::basic_string_view<char, std::char_traits<char> > as the first parameter?

This issue is solved by leaving the file absl/base/options.h unchanged.