Wireshark-dev: Re: [Wireshark-dev] Mac Build Error
From: David Morsberger <[email protected]>
Date: Thu, 21 Jan 2016 09:08:37 -0500
I went down a rabbit hole and pulled myself back out. I narrowed it down to the following.

We are using cmake to check if the linker supports ‘-Wl,—as-needed'. The test compile (and link?) command cmake builds using ‘cmake -G Xcode’  does not fail.

The command from ‘cmake -G’ has been narrowed down to the following:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang \
 -Qunused-arguments \
 -Wl,--as-needed \
 -c src.c \
 -o src.o 

The following modified command generates an error:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang \
 -Qunused-arguments \
 -Wl,--as-needed \

ld: unknown option: --as-needed
clang: error: linker command failed with exit code 1 (use -v to see invocation)

It appears the linker isn’t called when the -c and the -o options are present. The following warning is generated when the ‘-Qunused-arguments’ is removed.

clang: warning: -Wl,--as-needed: 'linker' input unused

The cmake logic in CMakeLists.txt is basically:

   CHECK_C_SOURCE_RUNS(“int main() { return 0;}" ${_RESULT})

where _FLAG is set to ‘-DWS_LD_FLAG_VALID0 -Wl,—-as-needed’

So, how/where is the clang compile/link command generated and why isn’t it being setup for clang to link?

On Jan 20, 2016, at 3:22 PM, Guy Harris <[email protected]> wrote:

On Jan 20, 2016, at 11:09 AM, David Morsberger <[email protected]> wrote:

This is what I am also tracking down. It has to do with the way cmake is instantiating the compiler. The --serialized-diagnostics option is what appears to be hiding the error.

--serialize-diagnostics takes an argument, which is the name of a file to which the diagnostics are written, in a binary format.

Clang documentation sucks.  Srsly.  The man page doesn't enumerate the -W options; the website:


does, but I'm not sure how to get the manual for an *arbitrary* version of Clang (the GCC folks are kind enough to provide online manuals, complete with listings of compiler flags, for multiple versions), and the word "serialize" appears nowhere on that page.

It might be that, when the tests are done, ld is being run directly, rather than by the gcc/clang driver, and that -as-needed isn't getting passed to it.  It obviously is getting passed when the actual *build* is done.

Perhaps when CMake was being designed, its designers should have looked at the documentation for another configuration system - I think it's called "autoconf" or something such as that - and noticed that it offered not only macros to try compiling a file ("compiling" as in "turning a source file into an object file, without trying to link anything"), but macros to try *linking* things, which can come in handy if, say, to pick a purely *hypothetical* example, you're trying to see whether a given linker flag works.

Or perhaps they mistakenly had the attitude that "we take care of all the platform details, so you don't have to".
Sent via:    Wireshark-dev mailing list <[email protected]>
Archives:    https://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
            mailto:[email protected]?subject=unsubscribe