Skip to content

clang error building native AoT application with Sentry.AspNetCore on Linux #4116

Closed

Description

@martincostello

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

  1. Clone martincostello/website@f36510d on Ubuntu (or in a GitHub Actions runner)
  2. Run build.ps1 in 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)

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Apr 15, 2025
  2. jamescrosswell commented on Apr 15, 2025

    @jamescrosswell
    Collaborator

    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:

    1. Per the issue above, you could disable the Native SDK (once that PR is completed/merged)
    2. You could install curl
    3. We could modify the way the .NET SDK uses the Native SDK so that it plugs a managed transport into the Native SDK (that doesn't depend on curl). This might be the slickest solution but probably also the most work.
    4. Other ideas/suggestions?
  3. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Apr 15, 2025
  4. martincostello commented on Apr 15, 2025

    @martincostello
    ContributorAuthor
    1. Not a deal-breaker to do this when available (as I don't have any of my own native code, so wouldn't be the end of the world if I didn't get information from third party native code)
    2. I would have thought that it would be installed by default on a GitHub Actions runner Ubuntu image. Or do you mean something more specific for installing curl (i.e. libcurl being on the path or something?)
    3. If that makes things Just Work™ then I guess long-term that's the most sensible as no one (other than Sentry) needs to do anything.
    4. Something in the docs that explains how to do 1 and/or 2 if this specific error happens for future people who stumble into this problem if 3 isn't done.
  5. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Apr 15, 2025
  6. jamescrosswell commented on Apr 15, 2025

    @jamescrosswell
    Collaborator

    2. I would have thought that it would be installed by default on a GitHub Actions runner Ubuntu image. Or do you mean something more specific for installing curl (i.e. libcurl being on the path or something?)

    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:

    curl and zlib libraries (e.g. on Ubuntu: libcurl4-openssl-dev, libz-dev)

    So you could try installing libcurl4-openssl-dev prior 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.

  7. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Apr 15, 2025
  8. martincostello commented on Apr 16, 2025

    @martincostello
    ContributorAuthor

    Thanks - that fixed it (martincostello/website@d28aa5f).

    sudo apt-get update
    sudo apt-get install --yes --no-install-recommends libcurl4-openssl-dev libz-dev
  9. 54 remaining items

  10. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on May 26, 2025
  11. bruno-garcia commented on May 26, 2025

    @bruno-garcia
    Member

    Thanks J-P! Merged and will make a patch release asap

  12. jpnurmi commented on May 26, 2025

    @jpnurmi
    Collaborator

    Perhaps (not sure if this is practical/possible) we could not include SentryNative by default when building for chiseled and display a warning linking to some docs explaining why... but add a build flag that people could use to override this deliberately, if they'd read the docs and were OK adding the missing dependencies to a custom image/container themselves?

    For that to work, we'd have to be able to detect whether the build was for a chiseled container or not in our transitive build file though - not sure how easy that is. Possibly we could just check for the existence of one of the missing dependencies to do that? @jpnurmi you might know an easier or better way...

    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-deps or even ubuntu:latest don't have libcurl.so.4 by default either. Furthermore, PublishContainer is an optional target that may or may not come after the build.

    How about simply displaying a warning if PublishContainer does get executed and SentryNative hasn't been defined?

    <Target Name="_AfterPublishContainer" AfterTargets="PublishContainer">
      <Warning Condition="'$(SentryNative)' == ''"
        Text="Sentry Native integration is enabled by default. It requires libcurl and its dependencies to be deployed in the container. Either set SentryNative=true to silence the warning, or SentryNative=false to disable the integration." />
    </Target>
  13. bruno-garcia commented on May 26, 2025

    @bruno-garcia
    Member

    How about simply displaying a warning if PublishContainer does get executed and SentryNative hasn't been defined?

    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?

  14. jpnurmi commented on May 26, 2025

    @jpnurmi
    Collaborator

    Another possibility could be dlopen(libcurl) in sentry-native and return a failure from sentry_init() instead of preventing the AOT-compiled executable from starting up.

  15. bruno-garcia commented on May 26, 2025

    @bruno-garcia
    Member

    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

  16. bruno-garcia commented on May 27, 2025

    @bruno-garcia
    Member
  17. martincostello commented on May 31, 2025

    @martincostello
    ContributorAuthor

    Just tried again with 5.9.0, and as long as I set SentryNative=false then the build is successful and there's no issues at runtime when the container is deployed.

  18. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on May 31, 2025
  19. bruno-garcia commented on May 31, 2025

    @bruno-garcia
    Member

    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=false online as a work around

  20. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on May 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions