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

CMake linux fix: add linker flags -lm -lutil and -ldl (when configured for dynamic loading) #779

Merged
merged 1 commit into from
Sep 19, 2021
Merged

CMake linux fix: add linker flags -lm -lutil and -ldl (when configured for dynamic loading) #779

merged 1 commit into from
Sep 19, 2021

Conversation

lubgr
Copy link
Contributor

@lubgr lubgr commented Sep 18, 2021

I tested the CMake build on Archlinux x86, where I discovered that linking fails due to the missing -lm -lutil -ldl flags. Not sure how this slipped through - this PR fixes it (also tested on an ARM Archlinux system).

@lubgr lubgr marked this pull request as ready for review September 18, 2021 17:04
@okuoku
Copy link
Collaborator

okuoku commented Sep 18, 2021

Hmm, is libutil should only required with pty functions thus it should go to add_compiled_library -- need to some way to pass dependency to it.

Currently,

add_stubs_library(lib/chibi/pty.stub)

how about adding LINK_LIBRARIES parameter. cmake_parse_argument can parse such argument.

add_stubs_library(lib/chibi/pty.stub LINK_LIBRARIES util)

Actually, .stub files includes metadata that indicates which library should be linked;

(c-link "util")

but I'm not sure how to extract this.

@lubgr
Copy link
Contributor Author

lubgr commented Sep 18, 2021

That's a good suggestion! I think extracting the (c-link "util") reliably is non-trivial, while the LINK_LIBRARIES option is more doable. Needs some tweaks for the static build to work, as the dependencies needs to be collected for a collective linking when the clib.c gets generated and added to to libchibi-scheme, but it works.

@ashinn
Copy link
Owner

ashinn commented Sep 18, 2021

I can add a flag for chibi-ffi to output the linker deps, but you need a working build first.

@lubgr
Copy link
Contributor Author

lubgr commented Sep 18, 2021

I can add a flag for chibi-ffi to output the linker deps, but you need a working build first.

Thanks for offering your help on this! Given that there currenlty is only one (c-link ...) form, might it also be fine to keep this in manual sync for now?

@ashinn
Copy link
Owner

ashinn commented Sep 18, 2021

Yes, it's fine to special case -lutil for now.

Copy link
Collaborator

@okuoku okuoku left a comment

Choose a reason for hiding this comment

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

I can add a flag for chibi-ffi to output the linker deps, but you need a working build first.

When building shared library version, CMake build will build chibi-scheme-bootstrap first to run chibi-ffi thus that should be fine.

Difficult part is there is no way to describe .stub files themselves as "configure" dependency -- when .stub changed to link against another (native) library, we have to regenerate CMake build files. Unfortunately there's no straightforward way to do this.

Anyway, now the patch looks fine.

@okuoku okuoku self-assigned this Sep 19, 2021
@okuoku okuoku merged commit bf881b3 into ashinn:master Sep 19, 2021
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.

3 participants