Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
None
Description
We encountered tube cpp client link error when we migrate build tools from CMake to Bazel.
The error message is as below:
client_connection.cc: (.text+0xff0): undefined reference to `tubemq::ClientConnection::kConnnectMaxTimeMs'
client_service.cc:
(.text._ZN6tubemq14ConnectionPoolC2ERSt10shared_ptrINS_12ExecutorPoolEE[_ZN6tubemq14ConnectionPoolC5ERSt10shared_ptrINS_12ExecutorPoolEE]+0xbe): undefined reference to `tubemq::ConnectionPool::kRegularTimerSecond'
This link error can be reproduced in CMake environment when you remove "-O2" in CMAKE_CXX_FLAGS
According to cpp standard(https://en.cppreference.com/w/cpp/language/static),
"If a const non-inline (since C+17) static data member or a constexpr static data member (since C11)(until C17) is odr-used, a definition at namespace scope is still required, but it cannot have an initializer. A definition may be provided even though redundant (since C+17)."
Possible fix:
- Add static const variable definition in src/client_connection.cc and src/client_service.cc
- Or change static const variable to enum
Further consideration:
Turn off compiler optimization in CI to make sure the compiler optimization will not shadow the compile error or link error