Skip to content

Fix linking against new libssh2 formula #356

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

Merged
merged 6 commits into from
Apr 14, 2014

Conversation

robrix
Copy link
Contributor

@robrix robrix commented Apr 14, 2014

🚨 ⚠️ Warning: This is not ready to merge until we have confirmation that it doesn’t break the build for folks who haven’t updated brew yet, and that it actually works correctly in deployed projects linking against ObjectiveGit.framework. 🚨 ⚠️

This is intended to fix linking Objective-Git against the libssh2 that brew gives us, which apparently can no longer be linked against system openssl.

  • confirm that it succeeds for @raheelahmad & @jlalvarez18
  • confirm that it succeeds for someone who hasn’t done brew upgrade libssh2 to get 1.4.3_1 yet
  • confirm that it is not linking the dylibs under /usr/local/… (and therefore that it can run on Macs without brew 😬) Unfortunately, we are.
  • support other versions of openssl (is this sane?) Probably not sane to try to manage upstream’s versioning carefully. Totally sane, just change the library search path to /usr/local/opt/openssl/lib like brew told me to
  • figure out how to make it prefer libssl.a and libcrypto.a to their dylib counterparts
  • and then do that

Fixes #352.

@robrix
Copy link
Contributor Author

robrix commented Apr 14, 2014

@raheelahmad @jlalvarez18 Could you please give this branch a try?

@raheelahmad
Copy link

@robrix it does, but I had to modify your modified LIBRARY_SEARCH_PATHS to /usr/local/Cellar/openssl/1.0.1f/lib/ from /usr/local/Cellar/openssl/1.0.1g/lib/. (Not sure how ...f vs. ...g directories come about) .

@robrix
Copy link
Contributor Author

robrix commented Apr 14, 2014

I bet if you were to brew upgrade openssl you’d get g. Good to know tho—I’ll have to add that to the PR.

@raheelahmad
Copy link

Indeed. A brew update && brew upgrade openssl gave me the g.

@jlalvarez18
Copy link

Doing a brew update && brew upgrade openssl definitely fixes the problem. :) The branch looks good. Just a heads up... there is this warning

warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: -dynamic not specified, -all_load invalid
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: -dynamic not specified the following flags are invalid: -ObjC 

@robrix
Copy link
Contributor Author

robrix commented Apr 14, 2014

Thanks to you both!

@jlalvarez18: That warning is benign. We’re passing -all_load and -ObjC for the linker on a static archive, probably, and not on the thing linking it; but it doesn’t result in bad behaviour. Xcode 5.1 just changed the chattiness of libtool, is all.

@jlalvarez18
Copy link

@robrix no no.. thank you!

@robrix
Copy link
Contributor Author

robrix commented Apr 14, 2014

Okay, we are linking the dylibs:

/usr/local/Cellar/openssl/1.0.1g/lib/libcrypto.1.0.0.dylib
/usr/local/Cellar/openssl/1.0.1g/lib/libssl.1.0.0.dylib

So, that’s pretty terrible.

Going to go spelunking in the man pages to try to figure out what to do about this.

@jspahrsummers
Copy link
Contributor

Including the path to the .a manually in the linker flags will link it statically, but that's kinda fragile.

robrix added 4 commits April 14, 2014 13:48
When these symlinks are unable to be resolved, the linker just skips
past them on to the next entry in the search paths. Thus, this should
work fine for system dylibs (since the search path entries that would
resolve to brewed dylibs have been removed) and for brewed archives.
@robrix
Copy link
Contributor Author

robrix commented Apr 14, 2014

@jspahrsummers Could you please give this branch a try again? (Assuming that you haven’t brew upgraded in the meantime 😁)

I’ve added symlinks to the .a files to External and removed the customized search paths, which means that it will use the (project-wide) External/ search path and try to resolve the .a files. Failing that it will try the other search paths, eventually ending up with system openssl dylibs.

So, brewed archives get top priority—meaning that recently-brewed libssh2 will work—and it should fallback otherwise. Only fly in the ointment is that you do have something at those paths—so now we just need to find out if it can link with it or not. (I’ve reason to expect “yes.”)

@jspahrsummers
Copy link
Contributor

The above warning has disappeared too.

@robrix robrix changed the title [WIP] Fix linking against new libssh2 formula Fix linking against new libssh2 formula Apr 14, 2014
@robrix
Copy link
Contributor Author

robrix commented Apr 14, 2014

That’s good enough for me!

Ready for review.

🐚

@@ -1510,6 +1502,8 @@
"-force_load",
External/libgit2.a,
/usr/local/lib/libssh2.a,
"-lcrypto",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this have the same issue with dylib preference?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both -lcrypto and -lssl are tested against $(SRCROOT)/External first, which has a libcrypto.a symlink in it. If that resolves, we’re done; otherwise, it falls back to system dylibs (which is fine).

@jspahrsummers jspahrsummers self-assigned this Apr 14, 2014
@jspahrsummers
Copy link
Contributor

1️⃣

@raheelahmad
Copy link

🙏 Thanks @robrix et al.

@robrix
Copy link
Contributor Author

robrix commented Apr 14, 2014

2️⃣

@jspahrsummers
Copy link
Contributor

:shipit:

jspahrsummers added a commit that referenced this pull request Apr 14, 2014
…formula

Fix linking against new libssh2 formula
@jspahrsummers jspahrsummers merged commit 14108f0 into master Apr 14, 2014
@jspahrsummers jspahrsummers deleted the fix-linking-against-new-libssh2-formula branch April 14, 2014 22:41
@robrix
Copy link
Contributor Author

robrix commented Apr 14, 2014

You’re welcome!

phatblat pushed a commit to phatblat/objective-git that referenced this pull request Sep 13, 2014
…ibssh2-formula

Fix linking against new libssh2 formula
mdiep added a commit to SwiftGit2/SwiftGit2 that referenced this pull request Dec 15, 2014
@jspahrsummers jspahrsummers removed their assignment May 22, 2015
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

Successfully merging this pull request may close these issues.

Error building with Xcode 5.1
5 participants