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

sokol_app.h: trigger a linker error if users forget -pthread #456

Merged
merged 1 commit into from Jan 13, 2021

Conversation

iboB
Copy link
Contributor

@iboB iboB commented Jan 9, 2021

My suggestion to resolve #455

@floooh floooh merged commit 0649a40 into floooh:master Jan 13, 2021
@floooh
Copy link
Owner

floooh commented Jan 13, 2021

Looks like good solution, thanks!

@floooh
Copy link
Owner

floooh commented Jan 13, 2021

There's an error when compiled as C++:

/usr/include/pthread.h:470:12: error: conflicting declaration of ‘int pthread_yield()’ with ‘C’ linkage
 extern int pthread_yield (void) __THROW;
            ^~~~~~~~~~~~~

I'll include pthread.h instead and removed the manual declaration.

@floooh
Copy link
Owner

floooh commented Jan 13, 2021

hmmmm it's not that simple... pthread.h doesn't contain pthread_yield() by default, instead _GNU_SOURCE must be defined before, but if there's already another include of pthread.h the _GNU_SOURCE define doesn't work. What a mess :/

My next attempt was calling pthread_self(), but for some reason this seems to be optimized away...

@iboB
Copy link
Contributor Author

iboB commented Jan 13, 2021

pthread_self (funny enough) doesn't actually require pthread to be linked. It's in libc.

And yeah, _GNU_SOURCE was the reason I just forward declared pthread_yield instead of including pthread.

As for C++, that's unpleasant. How about we keep the __THROW for now and in a couple of hours I'll find some time to submit a better solution in a PR?

@iboB
Copy link
Contributor Author

iboB commented Jan 13, 2021

Er... by the way won't adding "C" fix things properly? C functions should be nothrow

extern "C" int pthread_yield();

@floooh
Copy link
Owner

floooh commented Jan 13, 2021

No worries, I found an okay-ish solution: pthread_attr_init/destroy works. It shows up in libsokol.a as external undefined symbol (unlike pthread_self()).

@floooh
Copy link
Owner

floooh commented Jan 13, 2021

won't adding "C" fix things properly

Not sure, there's a lot of C++ specific stuff in /usr/include/pthread.h, and almost all functions are marked as __THROW.

@floooh
Copy link
Owner

floooh commented Jan 13, 2021

Ok, see: 5fbb6a2

@iboB iboB deleted the pthread_linker_error branch February 2, 2022 14:47
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.

[sokol_app] Suggestion: add a pthread call to Linux init so there's an error instead of "weird things"
2 participants