Wireshark-dev: Re: [Wireshark-dev] Mac Build Error
From: Guy Harris <guy@xxxxxxxxxxxx>
Date: Thu, 21 Jan 2016 11:29:05 -0800
On Jan 21, 2016, at 6:08 AM, David Morsberger <dave@xxxxxxxxxxxxxx> wrote:

> It appears the linker isn’t called when the -c and the -o options are present.

Correct.  It's not *supposed* to be called.  In UNIX C compilers, the "-c" flag means "compile to an object file, but don't link the resulting object file into an executable file"; it's the standard option used if you have a program that's built from more than one object file.

> The cmake logic in CMakeLists.txt is basically:
> 
>    SET(CMAKE_REQUIRED_FLAGS "${_FLAG}")
>    CHECK_C_SOURCE_RUNS(“int main() { return 0;}" ${_RESULT})

The documentation for the CHECK_C_SOURCE_RUNS() macro is

	* CheckCSourceRuns: Check if the given C source code compiles and runs.

	CHECK_C_SOURCE_RUNS(<code> <var>)

	  <code>   - source code to try to compile
	  <var>    - variable to store the result
	             (1 for success, empty for failure)

Presumably what it's doing is:

	1) compiling the source file into an object file;

	2) linking the object file into an executable;

	3) trying to run the resulting executable.

(As per my previous CMake complaint, they ***REALLY*** need CHECK_C_SOURCE_LINKS(), for the benefit of, for example, projects that are cross-compiling.  But I digress.)

The documentation for CHECK_C_SOURCE_RUNS() continues:

	The following variables may be set before calling this macro to modify the way the check is run:

	  CMAKE_REQUIRED_FLAGS = string of compile command line flags
	  CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
	  CMAKE_REQUIRED_INCLUDES = list of include directories
	  CMAKE_REQUIRED_LIBRARIES = list of libraries to link

Note the lack of a "string of *LINKER* command line flags" in that list; *that* is what we'd need to test this.

I guess, with Makefiles, the linking is done with a compiler command (another UNIX tradition) and the -Wl,--as-needed flag is passed on the link command line, but, with Xcode, it's not done with a compiler command, and the C flags aren't passed to the link phase at all.