Re: AX_PTHREAD incorrectly adds -pthread on OSX
"Daniel Richard G." <[email protected]>
| Newsgroups | gmane.comp.sysutils.autoconf.archive-maintainers |
|---|---|
| Message-ID | <1453512643.3546096.500129378.51292248@webmail.messagingengine.com> |
Hi Peter, Spurred by your/this e-mail, I've started working on this macro again to finally get a working version pushed out. On Fri, 2016 Jan 8 19:56+0100, Peter Simons wrote: > I'm forwarding this message to Steven and Richard, the macro's > authors. > > Peter > > Jason Gross <[email protected]> writes: Hi Jason, sorry for the wait. Lot of loose threads from the holiday! > > The latest version of AX_PTHREAD > > (dd946914edb9da25e2d8c8b2186fab5d8103f3d4, serial 21) does not work > > on OS X. It tests for whether or not `clang -o conftest -g -O2 > > -pthread -Werror conftest.c` succeeds (which it does), when it > > actually needs to be checking for `clang -o conftest.o -g -O2 > > -pthread -Werror - c conftest.c && clang -o conftest -g -O2 -pthread > > -Werror conftest.o` (which, I believe, fails). If there's a variant > > of AC_LINK_IFELSE that does the compilation separately from the > > linking, then the change should be as simple as AC_LINK_IFELSE() is defined at the Autoconf level. I can't change how it works, and there isn't any alternative macro that performs the link separately from the compilation. Even if there were, it wouldn't solve the problem. The issue is that [certain older versions of] Clang takes -pthread when compiling, but doesn't want the flag when it is only linking. This flies in the face of how basically every other C compiler works, where compile- time flags are at least silently ignored when linking with the compiler frontend, and are at times actually required (e.g. flags indicating 64- bit mode) in order for the link to succeed. That is why Automake always includes $(CFLAGS) when linking with $(CC), in addition to $(LDFLAGS). If you want to have a flag that is used *only* at compile time, that's actually a bit tricky to pull off [with Automake]. What's more, not setting PTHREAD_CFLAGS="-pthread" is actually an incorrect result, because then _REENTRANT is not #defined, meaning that "errno" and the like are not defined appropriately for multi- threaded builds. Ultimately, it is not possible to build POSIX-threaded software with this combination of elements: 1. A version of Clang that complains about -pthread when only linking 2. Automake 3. -pthread 4. -Werror One of those has to be taken out. Removing #1 or #2 tends not to be practically feasible. #3 is required for correct compilation. So it's #4 that's got to go. Sometimes, you just can't avoid a warning. > > plus associated documentation and indentation changes, but I don't > > know if anything like AC_COMPILE_AND_LINK_SEPARATELY_IFELSE exists---- > > does it? Not in Autoconf proper. There's never been a need for it, and the Clang folks have corrected the behavior of the -pthread flag in more recent versions. --Daniel -- Daniel Richard G. || [email protected] My ASCII-art .sig got a bad case of Times New Roman.