With gcc, how do I include a library (-lpthread) in my own static user library?

I want to use pthread in my static user library, but dependent projects will not be linked unless I add '-lpthread' to every project that uses it.

I would prefer to specify '-lpthread' in my own custom library. Actually, I did it, but it does nothing; I still need to add '-lpthread' to the dependent projects, otherwise I get

Invoking: GCC C++ Linker
g++ <....>
/usr/bin/ld: /home/xxx/git/xxx/xxx.CUtil/Debug/libxxx.CUtil.a(EzyThread.o): undefined reference to symbol 'pthread_create@@GLIBC_2.2.5'

IMO hits the target of my own custom library if I also need to include its dependencies in the projects it uses; What if I decide to use a different internal mechanism instead of pthread?

I used

#pragma comment(lib, "SomeOtherStuff.lib")

in MS VC, which does what I want, but now I'm in gcc environment. I checked the #pragma comment (lib, "xxx.lib") equivalent on Linux? that seemed high on emotion and low on useful information. Is there something similar in gcc or some other way to avoid specifying "-lpthread" in every dependent project? I know that C is not OOP, but why make every dependency work on a custom library implementation?

(Please do not say that something like the #pragma method is longer than β€œ-lpthread.” Note that #pragma or the equivalent mechanism in my user library is typed once, but β€œ-lpthread” is potentially hundreds of times needed, and needs to be changed as many times if the underlying mechanism in the user library changes.)

+4
1

- . , .

- gcc - , "-lpthread" ?... "-lpthread" ,

Unix (, LIBS , Autoconf).

, #pragma

. -, , ?

0

Source: https://habr.com/ru/post/1688376/


All Articles