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

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

Open
wch opened this issue Sep 19, 2017 · 2 comments
Open

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

wch opened this issue Sep 19, 2017 · 2 comments

Comments

@wch
Copy link
Member

wch commented Sep 19, 2017

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
Copy link

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
Copy link
Member Author

wch commented May 1, 2018

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

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

No branches or pull requests

2 participants