Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined symbols for architecture x86_64: "_git_branch_name_is_valid" #721

Open
arxanas opened this issue Jun 13, 2021 · 8 comments
Open

Comments

@arxanas
Copy link
Contributor

arxanas commented Jun 13, 2021

As of 0454efb, cargo test fails on macOS.

System details:

$ uname -a
Darwin waleedkhan-mbp 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64
$ rustup show
Default host: x86_64-apple-darwin
rustup home:  /Users/Waleed/.rustup

stable-x86_64-apple-darwin (default)
rustc 1.52.1 (9bc8c42bb 2021-05-09)
```

Error message:

```
   Compiling git2 v0.13.20 (/Users/Waleed/workspace/git2-rs)
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-m64" "-arch" "x86_64" "-L" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.0.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.1.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.10.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.11.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.12.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.13.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.14.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.15.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.2.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.3.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.4.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.5.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.6.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.7.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.8.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.9.rcgu.o" "-o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.u09cr4b2fds5ba9.rcgu.o" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/Waleed/workspace/git2-rs/target/debug/deps" "-L" "/usr/local/Cellar/libgit2/1.1.0/lib" "-L" "/Users/Waleed/workspace/git2-rs/target/debug/build/libssh2-sys-34ee49cb41b19d75/out/build" "-L" "/usr/local/opt/openssl@1.1/lib" "-L" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libtest-db9eca8f5d08050d.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libterm-03ffa4db69efb895.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libgetopts-01bd0f519f94c074.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunicode_width-7901380749915546.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_std-ab361ac62179dadb.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/liblog-135ef244209a85d4.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/liburl-b42a4cec8f8c5eb2.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libidna-5fae12f627455a64.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libunicode_normalization-74a564265e91967d.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libtinyvec-6c23dec31872fc26.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libtinyvec_macros-6a3d9893f1f74a5e.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libunicode_bidi-6d116929acb2ac5f.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libform_urlencoded-ab8796b5b8e83d73.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libpercent_encoding-2dbd0b5d1d2ba49f.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libmatches-a9016931447b6b5e.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libtempfile-1c9892031130ac2e.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/librand-0d9d2110c5342d0f.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/librand_chacha-64b398b5594e7be9.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libppv_lite86-df618e8854d7d514.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/librand_core-7696cd0ce21900dd.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libgetrandom-d9735d083523c02e.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libremove_dir_all-eb405c93cdca49aa.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libcfg_if-e10c2c6247528dd5.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/liblibgit2_sys-d2b2004c9dcf63c6.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/liblibssh2_sys-293c0a5bd68c1708.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libopenssl_sys-fe4003bb0719f60d.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/liblibz_sys-a8082fefcfc7e72e.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/liblibc-fc25c8b902b51cd0.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libbitflags-7be09f63d9f2d764.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-9225b8e469c32698.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-2fe2b8cd4fa63c34.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libobject-80083cf4ee7ee3ff.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libaddr2line-ddf3832e718029e6.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libgimli-ba92c986e8ef2ca8.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-acd0bd456d8da820.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-55608c4156e4ecbb.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-4be618026614fdc7.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-fee25922260aa100.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-38ba3c5cc408e14d.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liblibc-899852a009fbe35f.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc-5687564a0ccea916.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-9ed2c58b16cff4ee.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-244bf5611f93ff45.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-70df686e6b4ebf5b.rlib" "-lgit2" "-lssl" "-lcrypto" "-lz" "-liconv" "-lSystem" "-lresolv" "-lc" "-lm" "-liconv"
  = note: Undefined symbols for architecture x86_64:
            "_git_branch_name_is_valid", referenced from:
                git2::branch::Branch::name_is_valid::hf21c1179aaf6f2cb in git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.11.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)
          

error: aborting due to previous error

error: could not compile `git2`

To learn more, run the command again with --verbose.
```
@ehuss
Copy link
Contributor

ehuss commented Jun 13, 2021

It looks like you are linking against a homebrew installed version of libgit2. However, since #708, libgit2-sys is expecting a recent master version (which is still called 1.1.0).

@alexcrichton How would you like to proceed? It seems that now that libgit2 is past 1.0, it might show up in package managers more often, and this kind of error will be more common. I think either libgit2-sys would need to stay pinned to the released version, or stop trying to use the system-built package (or, in the middle ground, we'd need to be very careful about referring to new symbols, which I guess could be checked in CI).

@ehuss
Copy link
Contributor

ehuss commented Jun 13, 2021

As a side note, this test fails for me on both macos and linux with:

thread 'branch::tests::name_is_valid' panicked at 'called Result::unwrap() on an Err value: Error { code: -1, klass: 0, message: "an unknown git error occurred" }', src/branch.rs:191:46

I don't have a moment to investigate more, but I'm surprised as it passes CI.

@alexcrichton
Copy link
Member

I'm fine either way, if this is an issue we can add versioning logic and only expose some APIs on some versions

@alerque
Copy link

alerque commented Aug 23, 2021

Is there any chance of accelerating the next tagged release? Downstream projects have started releasing things relying on the main branch features and it's blocking distro packaging. It would be really nice to see whatever APIs need to be stabilized stabilized so we can convince downstream projects to use stable release versions again.

@arxanas
Copy link
Contributor Author

arxanas commented Aug 23, 2021

@alerque when i was looking into it, it seemed like you can force git2 to build libgit2 from source by setting the zlib_ng_compat feature:

if !zlib_ng_compat {

This might be a good workaround for projects to avoid versioning issues for the time being.

It would probably be best if git2 exposed a "build from source" feature directly, since there are many reasons a consumer might want to statically build it. For example, rusqlite has a bundled feature which lets you build your own version of SQLite into your executable.

@extrawurst
Copy link
Contributor

@arxanas that would be nice, I would definitely like this approach for gitui (to be honest, I thought thats already what happens, considering the whole libgit2 repo is a submodule here)

@decathorpe
Copy link

That would not help distribution packagers much - many distributions have rules and / or guidelines in place that prohibit building against bundled libraries, if it's possible to build against system-provided libraries. So if git2 added a vendored feature that gitui would then start using, we'd probably end up having to patch it out again anyway.

arxanas added a commit to arxanas/git2-rs that referenced this issue Aug 23, 2021
As per rust-lang#721, some consumers may
prefer to build `libgit2` themselves to simplify distribution.

To test the vendored version, you can run:

```
cargo build --features vendored-libgit2`
```

That being said, the test `branch::tests::name_is_valid` fails on macOS. This
test is currently broken as per
rust-lang#721 (comment)
@arxanas
Copy link
Contributor Author

arxanas commented Aug 23, 2021

Even if it doesn't help distribution packagers, it should still help people who are trying to compile from source and end up in the same situation as me in the original report. I opened #739 to add a vendored feature.

Several of my users had compilation problems for SQLite which probably could have been avoided (arxanas/git-branchless#13, arxanas/git-branchless#17). Who knows how many users tried to install my project, but immediately gave up because libgit2 didn't link properly? I'll probably change my own project to build libgit2 by default when in a non-packaged setting.

alexcrichton pushed a commit that referenced this issue Aug 27, 2021
As per #721, some consumers may
prefer to build `libgit2` themselves to simplify distribution.

To test the vendored version, you can run:

```
cargo build --features vendored-libgit2`
```

That being said, the test `branch::tests::name_is_valid` fails on macOS. This
test is currently broken as per
#721 (comment)
arxanas referenced this issue in arxanas/git-branchless Sep 16, 2022
Using the `ssh` feature induces a dependency on `openssl`. On my Macbook, this produced the following linking error:

```
  = note: Undefined symbols for architecture x86_64:
            "_OPENSSL_init_ssl", referenced from:
                std::sync::once::Once::call_once::_$u7b$$u7b$closure$u7d$$u7d$::he73245cadb6fb5f7 (.llvm.1763620816825828942) in libopenssl_sys-e129a1c9f9682ba1.rlib(openssl_sys-e129a1c9f9682ba1.openssl_sys.dn7psuzk-cgu.6.rcgu.o)
                core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h2d3710fadd6753f9 (.llvm.1763620816825828942) in libopenssl_sys-e129a1c9f9682ba1.rlib(openssl_sys-e129a1c9f9682ba1.openssl_sys.dn7psuzk-cgu.6.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)
```

I tried the following:

* Running `brew install openssl@1.1` as per the instructions at https://docs.rs/openssl/0.10.33/openssl/
* Setting the environment variables mentioned in `brew info openssl`
* Setting `LIBGIT2_SYS_USE_PKG_CONFIG=1` as mentioned in rust-lang/git2-rs#229

None of these worked. So I'm disabling the `ssh` feature for now. If `git-branchless` needs the `ssh` feature in the future (for example, if we add a Github integration and want it to pull/push directly), then we'll have to resolve the issue properly.

It's possible my particular issue is due to running Homebrew on a too-old version of macOS, and that it might be resolved by an OS upgrade and re-installing my Homebrew packages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants