[cmake-developers] try_compile does not work for linker flags?

Stephen Kelly steveire at gmail.com
Mon Oct 10 10:27:09 EDT 2011


Brad King wrote:

> On 10/8/2011 7:40 AM, Stephen Kelly wrote:
>> Would it break anything if we changed check_cxx_compiler_flag to build a
>> shared library instead of an executable? Maybe that will make the
>> try_compile fail as expected. (I'll try add a test for that now)
> 
> We cannot make a change like that to such a widely used check.  It will
> undoubtedly cause subtle behavior changes for other checks.
> 
> You can use the source-tree signature of try_compile to build your own
> test project that creates a shared library and tries using that flag.
> 
> BTW, the reason the compiler won't warn about -Wl,--no-undefined is
> because "-Wl," is the part parsed by the compiler.  It then passes the
> --no-undefined option to the linker, and the linker is not warning.


Yes, I realised all this yesterday too and wrote a new macro 
check_cxx_linker_flags. It required changing try_compile to not use 
add_executable, but optionally to create a shared library. 

It is staged as check-cxx-linker-flags, and seems to work on linux for me. 
(I haven't tried on windows yet)





More information about the cmake-developers mailing list