Why do I have to explicitly link to pthreads in my main.c compilation when my main.c does not use pthreads?

女生的网名这么多〃 提交于 2019-12-06 07:22:33

In order to create an executable or DLL you need to link in the transitive closure of all dependencies in your program. Because main.c links in sharedlib you must also link in all dependencies of sharedlib which includes pthreads.

Thank you R.. and Pavan Manjunath, for encouraging me to keep digging.

The link step for the shared library libmapreduce.so looked like:

icc -shared -g -o libmapreduce.so.1.0 map.o map_wrp.o -openmp [...] -lpthread -ldl

That -openmp link flag was not needed and in fact introduced the undefined reference to pthread_atfork. The undefined reference to pthread_atfork did not show up until I tried to link a main.c with the shared library libmapreduce.so. Re-creating libmapreduce.so without the -openmp flag removed the problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!