Open wch opened 7 years ago
I've come across something similar and learned that the POSIX threads API is always present to the XCode clang. According to the source code comments in the AX_PTHREAD autoconf archive macro, this presents a rare situation where ideally CFLAGS for the compile step would include "-pthread" and CFLAGS for the linking step wouldn't. I don't know exactly how building within R works, but clang has an option -Qunused-arguments which is a way to bypass these warnings if -Werror is turned on or the -Wunused-command-line-argument is otherwise undesirable. I wish I could say more definitively what the best practice is here but I just encountered this OSX-clang-specific quirk today.
FWIW, this is what Writing R Extensions says. It's not clear to me what we should actually do in this case, though.
https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Using-pthreads
There is no direct support for the POSIX threads (more commonly known as pthreads): by the time we considered adding it several packages were using it unconditionally so it seems that nowadays it is universally available on POSIX operating systems (hence not Windows).
For reasonably recent versions of gcc and clang the correct specification is
PKG_CPPFLAGS = -pthread
PKG_LIBS = -pthread
(and the plural version is also accepted on some systems/versions). For other platforms the specification is
PKG_CPPFLAGS = -D_REENTRANT
PKG_LIBS = -lpthread
(and note that the library name is singular). This is what -pthread does on all known current platforms (although earlier versions of OpenBSD used a different library name).
When I build the package, I get:
Having this for the Makevars file seems to make it go away (but I don't know if it's correct):