<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Eric,<div class=""><br class=""></div><div class="">I went down a rabbit hole and pulled myself back out. I narrowed it down to the following.</div><div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">The command from ‘cmake -G’ has been narrowed down to the following:</div><div class=""><span style="font-family: Menlo; font-size: 11px;" class=""><br class=""></span></div><div class="">$ <span style="font-family: Menlo; font-size: 11px;" class="">/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang \</span></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> -Qunused-arguments \</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> -DWS_LD_FLAG_VALID0 \</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> -Wl,--as-needed \</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> -c src.c \</div><div class=""><span style="font-family: Menlo; font-size: 11px;" class=""> </span><span style="font-family: Menlo; font-size: 11px;" class="">-o src.o</span> </div></blockquote><div class="">$</div><div class=""><br class=""></div><div class="">The following modified command generates an error:</div><div class=""><br class=""></div><div class=""><div class="">$ <span style="font-family: Menlo; font-size: 11px;" class="">/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang \</span></div><blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;" class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> -Qunused-arguments \</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> -DWS_LD_FLAG_VALID0 \</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> -Wl,--as-needed \</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> src.c</div></blockquote><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">ld: unknown option: --as-needed</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">clang: error: linker command failed with exit code 1 (use -v to see invocation)</span></div></div><div class="">$</div></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">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.</div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">clang: warning: -Wl,--as-needed: 'linker' input unused</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">The cmake logic in CMakeLists.txt is basically:</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">   SET(CMAKE_REQUIRED_FLAGS "${_FLAG}")</span></div><div style="margin: 0px; line-height: normal;" class="">   CHECK_C_SOURCE_RUNS(“int main() { return 0;}" ${_RESULT})</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">where _FLAG is set to ‘-DWS_LD_FLAG_VALID0 -Wl,—-as-needed’</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">So, how/where is the clang compile/link command generated and why isn’t it being setup for clang to link?</div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 21, 2016, at 1:51 AM, Eric Wing <<a href="mailto:ewmailing@gmail.com" class="">ewmailing@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">On 1/20/16, David Morsberger <<a href="mailto:dave@morsberger.com" class="">dave@morsberger.com</a>> wrote:<br class=""><blockquote type="cite" class=""><br class=""><blockquote type="cite" class="">On Jan 19, 2016, at 10:11 PM, Eric Wing <<a href="mailto:ewmailing@gmail.com" class="">ewmailing@gmail.com</a>> wrote:<br class=""><br class="">On 1/19/16, David Morsberger <<a href="mailto:dave@morsberger.com" class="">dave@morsberger.com</a>> wrote:<br class=""><blockquote type="cite" class="">Any help would be appreciated.<br class=""><br class="">In particular I’d like to know how the default compiler arguments are<br class="">set<br class="">when ‘cmake -G Xcode’ is executed. The attached file contains the cmake<br class="">test<br class="">compile extracted and reformatted from CMakeOutput.log that should have<br class="">failed. Again, what is setting all the clang compiler options when this<br class="">is<br class="">executed?<br class=""><br class=""><br class=""><br class="">All help is appreciated<br class=""><br class=""><blockquote type="cite" class="">On Jan 18, 2016, at 2:58 PM, David Morsberger <<a href="mailto:dave@morsberger.com" class="">dave@morsberger.com</a>><br class="">wrote:<br class=""><br class="">I’m having an issue generating and using a XCode project using cmake<br class="">-G.<br class=""><br class="">cmake —version<br class="">   cmake version 3.4.1<br class=""><br class="">Xcode Version 7.2 (7C68)<br class=""><br class="">Mac OS 10.11.<br class=""><br class=""><br class="">My CMakeLists.txt has a clang option that fails during the -G Xcode<br class="">pass<br class="">but fails when linking within XCode.<br class=""><br class="">The compiler / linker option is ‘-Wl,—as-needed’<br class=""><br class="">The test compile/link step in ‘cmake -G Xcode' creates a long clang<br class="">command with arguments ‘-Wl,—as-needed’ plus ‘—serialize-diagnostics<br class=""><path<br class="">to .dia file>’<br class=""><br class="">The link step within Xcode after the project created has the<br class="">‘-Wl,—as-needed’ argument and does not have the ‘—serialize-diagnostics<br class=""><path to .dia file>’ argument. The link fails because ‘-Wl,—as-needed’<br class="">isn’t supported.<br class=""><br class="">If copy and execute the long clang command from the ‘cmake -G Xcode’<br class="">command and remove the ‘—serialize-diagnostics <path to .dia file>’<br class="">then<br class="">it successfully fails with ‘-Wl, —as-needed’ isn’t supported.<br class=""><br class="">Finally, when I use cmake to generate unix makefiles it works meaning<br class="">cmake determines ‘-Wl—as-needed’ isn’t supported and doesn’t add it to<br class="">the<br class="">argument list.<br class=""><br class="">Questions:<br class="">- Where is the ‘—serialized-diagnostics’ argument coming from when<br class="">executing ‘cmake -G Xcode’?<br class=""><br class="">- What is a .dia file and how do I read it?<br class=""><br class="">- What’s the preferred / recommended way of detecting the non-supported<br class="">‘-Wl,—as-needed’ argument during the ‘cmake -G Xcode’ phase? One option<br class="">might to be to remove the ‘—serialize-diagnostics’ argument during the<br class="">generation phase.<br class=""><br class="">I can provide more details on request.<br class=""><br class="">David<br class=""><br class=""><br class=""><br class=""></blockquote></blockquote><br class=""><br class="">I just spot checked one of my Xcode compile logs. I see the<br class="">—serialize-diagnostics flag, but I don't have —as-needed anywhere.<br class="">Maybe one of your CMake scripts is adding that in, or you have set<br class="">some kind of environment variable that clang or Xcode is picking up?<br class="">(This recently happened to me on Linux.)<br class=""></blockquote><br class="">Ed,<br class=""><br class="">In this case cmake is attempting to determine if ‘—as-needed' is a supported<br class="">option and the build should fail.<br class=""><br class="">I have searched (grep’d) everything I can think of for the string<br class="">’serialize-diagnostics’ with zero hits.<br class=""><br class="">I can easily add an ‘if( Xcode )’ around the setting in CMakeLists.txt<br class="">however I’m trying to figure out what is exactly going on. The best<br class="">solutions are chosen when you know what is going on under the hood.<br class=""><br class=""><br class=""><br class=""></blockquote><br class="">I believe the serialize-diagnostics flag is added by Xcode itself. I<br class="">see it (along with many other flags) in a native (non-CMake generated)<br class="">Xcode project.<br class=""><br class="">-Eric<br class=""></div></div></blockquote></div><br class=""></div></body></html>