ardaku / whoami

Rust crate to get the current user and environment.
Apache License 2.0
195 stars 31 forks source link

Xcode 13.2.1 import fails at build: `Undefined symbols for architecture x86_64` #37

Closed Ontokrat closed 2 years ago

Ontokrat commented 2 years ago

Hello, I found a bug at the import in Xcode. Any idea?

Describe the bug Fail to import the lib in Xcode 13.2.1, as part of a backend Rust library used by a MacOS app. whoami::devicename() throws:

Undefined symbols for architecture x86_64:
  "_SCDynamicStoreCopyComputerName", referenced from:
      whoami::unix::devicename_os::a41b3da222bd09bd0 in redacted.a(whoami-b71e222d3f2cfa22.whoami.25222f57-cgu.0.rcgu.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

To Reproduce Steps to reproduce the behavior:

  1. import the crate to a Rust library
  2. Export the Rust library through cargo build --lib --release --all-targets
  3. Import the library.a file in XCode (TARGETS > MacOS > General > Frameworks, Libraries, and Embedded Content)
  4. The build fails with the output code above.

Expected behavior No build failure

Versions


Other template sections not relevant

AldaronLau commented 2 years ago

@Ontokrat Thanks for opening this issue.

Import the library.a file in XCode (TARGETS > MacOS > General > Frameworks, Libraries, and Embedded Content)

I don't see this menu option in XCode (I'm running the same version as you), nor does cargo build --lib --release --all-targets produce any .a files, so I wasn't able to reproduce the issue.


Make sure that you have given your XCode app access to the following frameworks required by whoami:

Ontokrat commented 2 years ago

@AldaronLau Thanks for having a look. You're right, just importing those 2 frameworks in the swift file calling the C function did the trick. Kudos.

import CoreFoundation
import SystemConfiguration

I didn't see it in the doc, my bad.

Nevertheless, if you're interested by more on the rust library within Xcode: