r-lib / later

Schedule an R function or formula to run after a specified period of time.
https://r-lib.github.io/later
Other
141 stars 29 forks source link

Linker warning: argument unused during compilation: '-pthread' #11

Open wch opened 7 years ago

wch commented 7 years ago

When I build the package, I get:

clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o later.so RcppExports.o callback_registry.o init.o later.o later_native.o later_posix.o later_win32.o timer_posix.o timestamp_unix.o timestamp_win32.o -pthread -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
clang: warning: argument unused during compilation: '-pthread' [-Wunused-command-line-argument]

Having this for the Makevars file seems to make it go away (but I don't know if it's correct):

PKG_CPPFLAGS = -pthread
PKG_LIBS = -lpthread
andypohl commented 6 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.

wch commented 6 years ago

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).