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

Static linkage of a program not otherwise using pthreads fails under Ubuntu 20.04 #305

Closed
bobfriesenhahn opened this issue Nov 21, 2021 · 5 comments

Comments

@bobfriesenhahn
Copy link

bobfriesenhahn commented Nov 21, 2021

Using the development version of JasPer (which now uses thread APIs) I find that a statically-linked program which is not otherwise using pthreads will fail to link due to unresolved symbols:

/usr/bin/ld: /usr/local/lib/libjasper.so: undefined reference to `pthread_getspecific'
/usr/bin/ld: /usr/local/lib/libjasper.so: undefined reference to `pthread_key_create'
/usr/bin/ld: /usr/local/lib/libjasper.so: undefined reference to `pthread_once'
/usr/bin/ld: /usr/local/lib/libjasper.so: undefined reference to `pthread_setspecific'
/usr/bin/ld: /usr/local/lib/libjasper.so: undefined reference to `pthread_key_delete'

Adding -pthread to the build options for the statically-linked program solves the problem.

To solve this problem, the JasPer shared library should assure that it has an implicit dependency on -pthread (not expecting the linked program to provide this) so that linkage succeeds by default on systems supporting implicit dependencies. If JasPer is built as a static library, then there is no solution other than users adding the needed -pthread since static libraries do not support implicit dependencies.

@mdadams
Copy link
Collaborator

mdadams commented Nov 23, 2021

This is very strange since Ubuntu 20.04 is used as one of the configurations in the JasPer CI testing, which is done on every commit. So, JasPer has been working in this environment. Maybe this is due to the JasPer application programs having a direct dependency on the pthread library? In any case, I did see a target_link_libraries directive that did not list the threading libraries used. I have added this and committed the change to master. See commit 4a55343. If this does not fix the problem, please let me know what is printed for "Threading library:" during the configuration stage of cmake.

@mdadams mdadams closed this as completed Nov 23, 2021
@bobfriesenhahn
Copy link
Author

bobfriesenhahn commented Nov 23, 2021 via email

@mdadams
Copy link
Collaborator

mdadams commented Nov 23, 2021

So, just to be clear, it works now, right?

@bobfriesenhahn
Copy link
Author

bobfriesenhahn commented Nov 23, 2021 via email

@mdadams
Copy link
Collaborator

mdadams commented Nov 24, 2021

Thank you for the confirmation that the bug is now fixed.

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