clang error building native AoT application with Sentry.AspNetCore on Linux #4116
Copy link
Copy link
Closed
Closed
Copy link
Labels
BugSomething isn't workingSomething isn't working
Description
Package
Sentry.AspNetCore
.NET Flavor
.NET
.NET Version
9.0.203
OS
Linux
OS Version
Ubuntu 24.04.2
Development Environment
Other
SDK Version
5.5.1
Self-Hosted Sentry Version
No response
Workload Versions
N/A
UseSentry or SentrySdk.Init call
N/A
Steps to Reproduce
- Clone martincostello/website@f36510d on Ubuntu (or in a GitHub Actions runner)
- Run
build.ps1in the root of the repository
Expected Result
The application builds successfully.
Actual Result
Generating native code
/usr/bin/ld.bfd: cannot find -lcurl: No such file or directory
clang : error : linker command failed with exit code 1 (use -v to see invocation) [/home/runner/work/website/website/src/Website/Website.csproj]
/home/runner/.nuget/packages/microsoft.dotnet.ilcompiler/9.0.4/build/Microsoft.NETCore.Native.targets(376,5): error MSB3073: The command ""clang" "/home/runner/work/website/website/artifacts/obj/Website/release/native/Website.o" -o "/home/runner/work/website/website/artifacts/bin/Website/release/native/Website" -Wl,--version-script=/home/runner/work/website/website/artifacts/obj/Website/release/native/Website.exports -Wl,--export-dynamic -gz=zlib -fuse-ld=bfd /home/runner/.nuget/packages/sentry/5.5.1/buildTransitive/../sentry-native/linux-x64/libsentry-native.a /home/runner/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/9.0.4/sdk/libbootstrapper.o /home/runner/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/9.0.4/sdk/libRuntime.ServerGC.a /home/runner/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/9.0.4/sdk/libeventpipe-enabled.a /home/runner/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/9.0.4/sdk/libRuntime.VxsortEnabled.a /home/runner/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/9.0.4/sdk/libstandalonegc-disabled.a /home/runner/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/9.0.4/sdk/libstdc++compat.a /home/runner/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/9.0.4/framework/libSystem.Native.a /home/runner/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/9.0.4/framework/libSystem.IO.Compression.Native.a /home/runner/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/9.0.4/framework/libSystem.Net.Security.Native.a /home/runner/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/9.0.4/framework/libSystem.Security.Cryptography.Native.OpenSsl.a /home/runner/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/9.0.4/sdk/libz.a -g -Wl,-rpath,'$ORIGIN' -Wl,--build-id=sha1 -Wl,--as-needed -pthread -lcurl -ldl -lrt -lm -pie -Wl,-pie -Wl,-z,relro -Wl,-z,now -Wl,--eh-frame-hdr -Wl,--discard-all -Wl,--gc-sections" exited with code 1. [/home/runner/work/website/website/src/Website/Website.csproj]
Originally reported here: #3928 (comment)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugSomething isn't workingSomething isn't working
Projects
- StatusShow more project fieldsDone
- StatusShow more project fieldsNo status
Activity
jamescrosswell commentedon Apr 15, 2025
Hi @martincostello ,
I think this is the same issue that was reported here:
Essentially the Native SDK (that we leverage in AOT compiled applications) needs/uses curl to send envelopes to Sentry.
Some options:
martincostello commentedon Apr 15, 2025
jamescrosswell commentedon Apr 15, 2025
I don't quite understand why this is required when referencing
Sentry.AspNetcore, as your sample project does. Somewhere/somehow I'm guessing a native compiler kicks in and spots a missing dependency from our Native SDK.When building the Native SDK itself, these are the prerequisites:
So you could try installing
libcurl4-openssl-devprior to attempting to build your project.If that does indeed solve the issue, we need to work out a way to make it easier for people like yourself in the future... possibly we could build something into our transitive build files that checks to see whether an AOT compilation is being performed on *nix, check to see if appropriate curl dependencies have been installed and give a helpful warning/error explaining how to install these if they're not present. We'll cross that bridge when we come to it though.
martincostello commentedon Apr 16, 2025
Thanks - that fixed it (martincostello/website@d28aa5f).
54 remaining items
bruno-garcia commentedon May 26, 2025
Thanks J-P! Merged and will make a patch release asap
jpnurmi commentedon May 26, 2025
I'm not sure if we can deduce anything useful from the container name alone because the problem doesn't only apply to "chiseled" containers. For example,
dotnet/runtime-depsor evenubuntu:latestdon't havelibcurl.so.4by default either. Furthermore,PublishContaineris an optional target that may or may not come after the build.How about simply displaying a warning if
PublishContainerdoes get executed andSentryNativehasn't been defined?bruno-garcia commentedon May 26, 2025
That'd be a step in the right direction but tbqh I'm thinking we're better off turning this off by default then, and documenting this option under a Native AOT specific page with clarifiaction of dependencies, some example containers where it won't work, etc.
wdyt?
jpnurmi commentedon May 26, 2025
Another possibility could be
dlopen(libcurl)in sentry-native and return a failure fromsentry_init()instead of preventing the AOT-compiled executable from starting up.bruno-garcia commentedon May 26, 2025
That's a better solution. But is libcurl the only thing that can fail? There were lots of other dependencies involved. If we can 'try-load' and print to the console if it fails, that'd definitely be a better solution so we can keep this on by default
bruno-garcia commentedon May 27, 2025
The fix to disable native (#4220) is live in: https://github.com/getsentry/sentry-dotnet/releases/tag/5.8.1
martincostello commentedon May 31, 2025
Just tried again with 5.9.0, and as long as I set
SentryNative=falsethen the build is successful and there's no issues at runtime when the container is deployed.bruno-garcia commentedon May 31, 2025
Thank you for confirming Martin.
Next we just need to figure out the default behavior (so folks don't end up with a crash OOTB and hopefully coming across
SentryNative=falseonline as a work around