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

Check if libraries are present using dlopen #11852

Merged
merged 2 commits into from
Feb 28, 2022

Conversation

FnControlOption
Copy link
Contributor

Fixes this error from crystal i:

cannot find -liconv
Linker arguments: -L/usr/local/lib -L/usr/local/Cellar/libevent/2.1.12/lib -levent -liconv
Search path: /usr/lib:/usr/local/lib:/usr/local/lib:/usr/local/Cellar/libevent/2.1.12/lib (Crystal::Loader::LoadError)

@Blacksmoke16
Copy link
Member

Blacksmoke16 commented Feb 24, 2022

I'm going to take a guess and say the solution here is to install iconv instead of just not linking it? Because this is probably going to have unintended side effects for non crystal i usages.

EDIT: IIRC it was talked about at least moving this behind a flag, e.g. -Dwithout_iconv, which might be a better idea if this is indeed wanted.

@FnControlOption
Copy link
Contributor Author

Looking into this further, the problem comes from libiconv.dylib not existing anymore on macOS 11 and up. The solution is to call load_file? (which eventually calls LibC.dlopen) on each path and check if the returned value is nil:

New in macOS Big Sur 11.0.1, the system ships with a built-in dynamic linker cache of all system-provided libraries. As part of this change, copies of dynamic libraries are no longer present on the filesystem. Code that attempts to check for dynamic library presence by looking for a file at a path or enumerating a directory will fail. Instead, check for library presence by attempting to dlopen() the path, which will correctly check for the library in the cache.

https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11_0_1-release-notes

@FnControlOption FnControlOption changed the title Don't add -liconv flag on macOS Check if libraries are present using dlopen Feb 24, 2022
@straight-shoota
Copy link
Member

Thanks for digging into this. That's really weird and unexpected behaviour 🤦

I'm wondering whether to keep the old behaviour on non-darwin systems. But I suppose it really doesn't matter to check for the file's existence beforehand. That's one of the first dlopen will do and quickly errors when the file is missing.

Copy link
Member

@asterite asterite left a comment

Choose a reason for hiding this comment

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

It works, thank you!

@straight-shoota straight-shoota added this to the 1.4.0 milestone Feb 24, 2022
@Sija
Copy link
Contributor

Sija commented Feb 24, 2022

Since it turned out to be a generic change, the platform:darwin label should be removed.

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. platform:darwin labels Feb 25, 2022
@straight-shoota
Copy link
Member

Let's leave the darwin tag. This change specifically addresses a bug on darwin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. platform:darwin topic:compiler:interpreter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants