-
Notifications
You must be signed in to change notification settings - Fork 2.5k
libssh2 iOS link #4604
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
Closed
Closed
libssh2 iOS link #4604
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dd09dd3
stransport: fix a warning on iOS
tiennou 860d31e
cmake: setup required libraries before checking function
tiennou 6d39c81
cmake: manually pass link flags when checking libssh2 function
tiennou d647a07
fixup! use the ldflags instead of building arguments manually
tiennou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
cmake: setup required libraries before checking function
As per the docs[1], another set of variables will be provided by PKG_CHECK_MODULES when static linking (with the additional libraries required for static links). We need to pass those libraries to CHECK_LIBRARY_EXISTS so *its* link succeeds. 1 - https://cmake.org/cmake/help/v3.1/module/FindPkgConfig.html#command:pkg_check_modules Ref: libgit2/objective-git#645
- Loading branch information
commit 860d31e22efaa0b1d718d2b453a1d2490f90fdce
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, that's a gross hack. If necessary I'll merge that, but I'm not yet convinced the problem isn't actually us.
Previously, we've been using
CHECK_LIBRARY_EXISTS("${LIBSSH2_LIBRARIES}" ...)
, which works just right with dynamic libraries. Sure, we don't need to pass in dependencies of libssh2, as they're picked up by the linker anyway. That's why${LIBSSH2_LIBRARIES}
will only contain the path to the libssh2.so.Now the case with static archives. We have to link not only against libssh2, but also explicitly against its dependencies. That's why
${LIBSSH2_LIBRARIES}
will be something like "ssh2;ssl;crypto;z". Passing that one again toCHECK_LIBRARY_EXISTS
is obviously not gonna work: the first parameter of that function shall be the library we're searching in, not a list of libraries. So what we'd have to do is to only pass ssh2 intoCHECK_LIBRARY_EXISTS
, but setCMAKE_REQUIRED_LIBRARIES
up accordingly to contain the other libraries, as well.The old commits of yours arent available anymore, so I can't check and don't remember if you did that. I know you used
CMAKE_REQUIRED_LIBRARIES
, but did you also modifyCHECK_LIBRARY_EXISTS
to only pass in "ssh2" as first argument?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's unsightly 😭. IIRC the old code did the same
SET(CMAKE_REQUIRED_LIBRARIES…)
as it is now (ie. direct passthrough of whateverPKG_CHECK_MODULE
found for the static case), with only ssh2 as the first argument (lest CMake fails anyway, withLooking for libssh2_userauth_publickey_frommemory in ssh2;ssl;crypto;z - not found
)For reference, here's the implementation of CHECK_LIBRARY_EXISTS. As you can see, it will stringify whatever is passed as the
LOCATION
argument, which will output as a -L"${STATIC_LIBDIRS}", erroring because of file not found (which is one of the issues I encountered the 1st time).STATIC_LIBDIRS
inCMAKE_REQUIRED_LIBRARIES
will result in :Everything results int the same underlying error (
ld: library not found for -lssh2
). What's maddening is that the last few arguments passed to ld are-L/usr/local/Cellar/openssl/1.0.2o_1/lib -Wl,-rpath,/usr/local/Cellar/openssl/1.0.2o_1/lib -lssh2 -lssh2 -lssl -lcrypto -lz
so it sees the openssl libdir coming fromLOCATION
, but it only processes the first item (the CMake "bug").There are a bunch of alternatives :
cmake
forget it's running in an Xcode build environment (that-isysroot
is IMHO the curx of the issue). That would be the cleanest IMHO, but I haven't been able to find what causes it to grab this environment.