Build failure
I'm working on updating the google-cloud-cpp FreeBSD port, and hit the build issue below. It also occurs under FreeBSD 14.2 with clang18.
# uname -a
FreeBSD barracuda.acadix.biz 14.3-RELEASE-p2 FreeBSD 14.3-RELEASE-p2 GENERIC amd64
# clang --version
FreeBSD clang version 19.1.7 (https://github.com/llvm/llvm-project.git llvmorg-19.1.7-0-gcd708029e0b2)
Target: x86_64-unknown-freebsd14.3
Thread model: posix
InstalledDir: /usr/bin
# pkg info|grep -E 'opentelemetry|grpc|abseil'
abseil-20250127.1 Abseil Common Libraries (C++)
grpc-1.74.0,2 HTTP/2-based RPC framework
opentelemetry-cpp-1.20.0 OpenTelemetry C++ client
# git describe --tags
v2.41.0-9-gc06d686e32
[ 50% 744/1457] /usr/bin/c++ -DGOOGLE_CLOUD_CPP_HAVE_OPENSSL -DOPENTELEMETRY_ABI_VERSION_NO=1 -DPROTOBUF_USE_DLLS -Dgoogle_cloud_cpp_opentelemetry_EXPORTS -I/usr/ports/wip/google-cloud-cpp/work/google-cloud-cpp-2.41.0-9-gc06d686e32 -isystem /usr/local/include -isystem /usr/ports/wip/google-cloud-cpp/work/.build -isystem /usr/ports/wip/google-cloud-cpp/work/.build/external/googleapis -isystem /usr/ports/wip/google-cloud-cpp/work/.build/google/cloud/monitoring -isystem /usr/ports/wip/google-cloud-cpp/work/.build/google/cloud/trace -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -std=c++17 -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -std=c++17 -DNDEBUG -fPIC -Wall -Wextra -Wconversion -Wno-sign-conversion -fno-exceptions -pthread -Wno-float-conversion -Wno-implicit-float-conversion -Wno-implicit-int-float-conversion -Wno-unknown-warning-option -DNOMINMAX -MD -MT google/cloud/opentelemetry/CMakeFiles/google_cloud_cpp_opentelemetry.dir/internal/monitored_resource.cc.o -MF google/cloud/opentelemetry/CMakeFiles/google_cloud_cpp_opentelemetry.dir/internal/monitored_resource.cc.o.d -o google/cloud/opentelemetry/CMakeFiles/google_cloud_cpp_opentelemetry.dir/internal/monitored_resource.cc.o -c /usr/ports/wip/google-cloud-cpp/work/google-cloud-cpp-2.41.0-9-gc06d686e32/google/cloud/opentelemetry/internal/monitored_resource.cc
FAILED: google/cloud/opentelemetry/CMakeFiles/google_cloud_cpp_opentelemetry.dir/internal/monitored_resource.cc.o
/usr/bin/c++ -DGOOGLE_CLOUD_CPP_HAVE_OPENSSL -DOPENTELEMETRY_ABI_VERSION_NO=1 -DPROTOBUF_USE_DLLS -Dgoogle_cloud_cpp_opentelemetry_EXPORTS -I/usr/ports/wip/google-cloud-cpp/work/google-cloud-cpp-2.41.0-9-gc06d686e32 -isystem /usr/local/include -isystem /usr/ports/wip/google-cloud-cpp/work/.build -isystem /usr/ports/wip/google-cloud-cpp/work/.build/external/googleapis -isystem /usr/ports/wip/google-cloud-cpp/work/.build/google/cloud/monitoring -isystem /usr/ports/wip/google-cloud-cpp/work/.build/google/cloud/trace -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -std=c++17 -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -std=c++17 -DNDEBUG -fPIC -Wall -Wextra -Wconversion -Wno-sign-conversion -fno-exceptions -pthread -Wno-float-conversion -Wno-implicit-float-conversion -Wno-implicit-int-float-conversion -Wno-unknown-warning-option -DNOMINMAX -MD -MT google/cloud/opentelemetry/CMakeFiles/google_cloud_cpp_opentelemetry.dir/internal/monitored_resource.cc.o -MF google/cloud/opentelemetry/CMakeFiles/google_cloud_cpp_opentelemetry.dir/internal/monitored_resource.cc.o.d -o google/cloud/opentelemetry/CMakeFiles/google_cloud_cpp_opentelemetry.dir/internal/monitored_resource.cc.o -c /usr/ports/wip/google-cloud-cpp/work/google-cloud-cpp-2.41.0-9-gc06d686e32/google/cloud/opentelemetry/internal/monitored_resource.cc
/usr/ports/wip/google-cloud-cpp/work/google-cloud-cpp-2.41.0-9-gc06d686e32/google/cloud/opentelemetry/internal/monitored_resource.cc:225:10: error: no matching function for call to 'visit'
225 | return absl::visit(AsStringVisitor{}, attribute);
| ^~~~~~~~~~~
/usr/include/c++/v1/variant:1573:1: note: candidate template ignored: substitution failure [with _Visitor = AsStringVisitor, _Vs = <const opentelemetry::sdk::common::OwnedAttributeValue &>]: no matching function for call to '__as_variant'
1153 | visit(_Visitor&& __visitor, _Vs&&... __vs) {
| ^
1 error generated.
FYI, I get the exact same error when building with GCC 13.
2.40.0 is the first release to exhibit this issue. 2.39.0 builds successfully.
Update: This appears to be only because opentelemetry is disabled by default in 2.39.0 and earlier. When I enable it using
-DGOOGLE_CLOUD_CPP_ENABLE="storage,opentelemetry"
I get the same error as 2.40.x.
Looks like there's some differing definitions of variant and visit between abseil and opentelemetry, with the possibilities being std::variant, absl::variant, and opentelemetry's nostd::variant.
You think it might just be a matter of clarifying the namespace in the scope(s) where the errors are happening?
Following your clue and using trial and error, I came up with the following patch set that produces a successful build, though I have no idea if there are runtime differences between these conflicting implementations that we need to worry about. These patches work with opentelemetry-cpp 1.20.0, but 1.21.0 requires additional patches that aren't so simple.
--- google/cloud/opentelemetry/internal/monitored_resource.cc.orig 2025-09-05 00:42:39 UTC
+++ google/cloud/opentelemetry/internal/monitored_resource.cc
@@ -222,7 +222,7 @@ std::string AsString(
std::string AsString(
opentelemetry::sdk::common::OwnedAttributeValue const& attribute) {
- return absl::visit(AsStringVisitor{}, attribute);
+ return opentelemetry::nostd::visit(AsStringVisitor{}, attribute);
}
MonitoredResource ToMonitoredResource(
--- google/cloud/opentelemetry/internal/recordable.cc.orig 2025-09-05 00:43:49 UTC
+++ google/cloud/opentelemetry/internal/recordable.cc
@@ -207,7 +207,7 @@ void AddAttributeImpl(
std::size_t limit) {
auto* proto = ProtoOrDrop(attributes, key, limit);
if (proto) {
- absl::visit(AttributeVisitor{*proto}, value);
+ opentelemetry::nostd::visit(AttributeVisitor{*proto}, value);
} else {
attributes.set_dropped_attributes_count(
attributes.dropped_attributes_count() + 1);
--- google/cloud/opentelemetry/internal/time_series.cc.orig 2025-09-05 00:45:42 UTC
+++ google/cloud/opentelemetry/internal/time_series.cc
@@ -41,10 +41,10 @@ google::monitoring::v3::TypedValue ToValue(
google::monitoring::v3::TypedValue ToValue(
opentelemetry::sdk::metrics::ValueType value) {
google::monitoring::v3::TypedValue proto;
- if (absl::holds_alternative<double>(value)) {
- proto.set_double_value(absl::get<double>(value));
+ if (opentelemetry::nostd::holds_alternative<double>(value)) {
+ proto.set_double_value(opentelemetry::nostd::get<double>(value));
} else {
- proto.set_int64_value(absl::get<std::int64_t>(value));
+ proto.set_int64_value(opentelemetry::nostd::get<std::int64_t>(value));
}
return proto;
}
@@ -63,9 +63,9 @@ double AsDouble(opentelemetry::sdk::metrics::ValueType
}
double AsDouble(opentelemetry::sdk::metrics::ValueType const& v) {
- return absl::holds_alternative<double>(v)
- ? absl::get<double>(v)
- : static_cast<double>(absl::get<std::int64_t>(v));
+ return opentelemetry::nostd::holds_alternative<double>(v)
+ ? opentelemetry::nostd::get<double>(v)
+ : static_cast<double>(opentelemetry::nostd::get<std::int64_t>(v));
}
std::vector<google::monitoring::v3::CreateTimeSeriesRequest> ToRequestsHelper(
@@ -118,7 +118,7 @@ void ToTimeSeriesHelper(
return absl::nullopt;
}
};
- auto ts = absl::visit(Visitor{metric_data}, pda.point_data);
+ auto ts = opentelemetry::nostd::visit(Visitor{metric_data}, pda.point_data);
if (!ts) continue;
ts->set_unit(metric_data.instrument_descriptor.unit_);
ts_collector_fn(metric_data, pda, *std::move(ts));
@google-cloud-cpp team.
Today, I also in trouble for this build issue.
To be honest, have you successfully build this package: https://github.com/googleapis/google-cloud-cpp/tree/v2.42.0/google/cloud/opentelemetry?
I need this package very much. I am very painful now.
Hello everyone, can you give me this package that you successfully build?
@outpaddling @scotthart @google-cloud-cpp team
For FreeBSD, I have working google-cloud-cpp-2.42.0 and opentelemetry-1.2.0 work-in-progress ports:
https://github.com/outpaddling/freebsd-ports-wip
That's what I'll be using until this issue is resolved and we can upgrade to the latest.
For FreeBSD, I have working google-cloud-cpp-2.42.0 and opentelemetry-1.2.0 work-in-progress ports:
https://github.com/outpaddling/freebsd-ports-wip
That's what I'll be using until this issue is resolved and we can upgrade to the latest.
@outpaddling opentelemetry-1.2.0, 1.2.0 is very old version. are you sure you don't type error?
I use debian os, how to use your freebsd-ports-wip? freebsd use glibc?
That's the latest version that will work with google-cloud-cpp-2.4.2 + minimal patching.
That's the latest version that will work with google-cloud-cpp-2.4.2 + minimal patching.
I use debian os, how to use your freebsd-ports-wip? freebsd use glibc?
@outpaddling execuse me.
It will only serve as an example for some other package manager, like Debian packages, vcpkg, etc. FreeBSD ports only works on FreeBSD and Dragonfly BSD AFAIK.
After review all google-cloud-cpp and opentelemetry-cpp source codes, I find that:
-
google-cloud-cppnamespace useopentelemetry-cppnamespace,opentelemetry-cppnamespace usegoogle-cloud-cppnamespace.opentelemetry-cppnamespace's depth is very deep and long. This sacrifice coding happy. This make package version lock-in - why must C++ namespace? Can we transform C++ namespace's codes to code in the folders?
Here is my patch to compile google-cloud-cpp 1.42.0 with opentelemetry-cpp-1.20.0 and pass the tests on gentoo.
https://github.com/wangjiezhe/gentoo-local/tree/main/net-libs/google-cloud-cpp/files
similar with outpaddling's patch, with more changes.