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

Making .so on x86 w/ libz-ng.a #1759

Open
rjzak opened this issue Jul 10, 2024 · 6 comments
Open

Making .so on x86 w/ libz-ng.a #1759

rjzak opened this issue Jul 10, 2024 · 6 comments

Comments

@rjzak
Copy link

rjzak commented Jul 10, 2024

I'm trying to compile a Python module which links against the static library for Zlib-ng, and I was getting a linker error:

relocation R_X86_PC32 against symbol zng_z_errmsg can not be used when making a shared object; recompile with -fPIC

This is on a Debian 12 system on x86_64 with gcc. I was able to fix this by adding -fPIC to the CFLAGS variable in the Makefile after running the configure script. Maybe this could be added to the project?

Interestingly enough, I was able to compile the same code on Power9, also on Debian 12 with gcc without any issues.

@mtl1979
Copy link
Collaborator

mtl1979 commented Jul 10, 2024

This has been discussed numerous times before... Mixing static and shared libraries isn't supported as linker won't know how to resolve if two compilation units define or use same symbol. Some platforms might enable PIC or PIE by default, but that doesn't eliminate the root cause of why we don't support manually specifying -fPIC.

@rjzak
Copy link
Author

rjzak commented Aug 7, 2024

Fair enough. In general, how would other projects handle this (shared and static), or how should it be done?

@mtl1979
Copy link
Collaborator

mtl1979 commented Aug 21, 2024

Fair enough. In general, how would other projects handle this (shared and static), or how should it be done?

The main binary should be dynamically linked against zlib-ng and the symbols should be re-exported for any modules. This is the best way unless modules of that program can request other modules to be loaded on-demand.

@rjzak
Copy link
Author

rjzak commented Aug 21, 2024

Sure, but the configure script has the option --static. Seems like that doesn't go well with not having -fPIC, since the linker will complain when a project then uses the resulting .a file. Maybe I'm not understanding correctly, I'm just trying to reduce run-time dependencies for easier distribution of my app.

@mtl1979
Copy link
Collaborator

mtl1979 commented Aug 23, 2024

Sure, but the configure script has the option --static. Seems like that doesn't go well with not having -fPIC, since the linker will complain when a project then uses the resulting .a file. Maybe I'm not understanding correctly, I'm just trying to reduce run-time dependencies for easier distribution of my app.

The static flag only works when linking against an executable, not a shared library, that is limitation of the linker, not zlib-ng.

@rjzak
Copy link
Author

rjzak commented Aug 23, 2024

What I meant was the project seems to support a static version of zlib-ng, and it seems that -fPIC is required for that. So I'm saying -fPIC seems to be required.

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

2 participants