Skip to content

Spurious "error: could not find native static library objc, perhaps an -L flag is missing?" on macOS Big Sur #96943

@adaszko

Description

@adaszko
Contributor

Hi 👋

I'm experiencing this issue on macOS Big Sur when libusb1-sys crate's build.rs invokes pkg-config and gets this:

$ pkg-config --static --libs /usr/local/Cellar/libusb/1.0.26/lib/pkgconfig/libusb-1.0.pc
-L/usr/local/Cellar/libusb/1.0.26/lib -lusb-1.0 -lobjc -Wl,-framework,IOKit -Wl,-framework,CoreFoundation -Wl,-framework,Security

rustc seems then proceed to try to link libobjc:

$ [...] cargo build
   Compiling libusb1-sys v0.6.2 (/Users/adaszko/repos/rusb/libusb1-sys)
   Compiling rusb v0.9.1
error: could not find native static library `objc`, perhaps an -L flag is missing?

This issue is preventing me from building a statically linked libusb1-sys. Linking itself should still work, it's just that rustc's erroring out prevents the pipeline from getting to the linking step AFAICT.

EDIT: Sorry, I've removed a misleading points about dynamic linking stemming from my misunderstanding of the issue.

Activity

added a commit that references this issue on May 20, 2022
madsmtm

madsmtm commented on Oct 10, 2024

@madsmtm
Contributor

I suspect this may have been caused by not properly passing the macOS SDK to the linker, which will be fixed by #131477.

In the meantime, could you try doing xcrun cargo build, to ensure that SDKROOT is set?

adaszko

adaszko commented on Oct 10, 2024

@adaszko
ContributorAuthor

Sorry, I'm no longer working on this (it's been a while) so won't be able to test it. Unless someone else is affected I think the issue can be closed.

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

    C-bugCategory: This is a bug.O-macosOperating system: macOS

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @adaszko@thomcc@madsmtm

      Issue actions

        Spurious "error: could not find native static library `objc`, perhaps an -L flag is missing?" on macOS Big Sur · Issue #96943 · rust-lang/rust