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

Brad King brad.king at kitware.com
Mon Oct 10 09:29:35 EDT 2011


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.

-Brad


More information about the cmake-developers mailing list