How to check for linker argument support?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to check for linker argument support?

Bent Bisballe Nyeng
Hi list

I want to use the --no-undefined linker argument through the
-Wl,--no-undefined CXXFLAGS. This is only supported by gcc but has a
clang alternative: -Wl,-undefined,error.
I have tried writing a test in my configure.ac script to figure out
which one should be used, but my test reports 'yes' on both gcc and
clang, so clang never falls back to it's own variant.
My test looks like this:

dnl ===========================
dnl Check for -Wl,--no-undefined or -Wl,-undefined,error support
dnl ===========================
AC_LANG_PUSH([C++])
TMP_CXXFLAGS="$CXXFLAGS"
AC_MSG_CHECKING([whether CXX supports '-Wl,--no-undefined'])
CXXFLAGS="-Wall -Werror -Wl,--no-undefined"
AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
        [ AC_MSG_RESULT([yes])
                NO_UNDEFINED_PARAM=-Wl,--no-undefined
        ],
        [ AC_MSG_RESULT([no])
                AC_MSG_CHECKING([whether CXX supports '-Wl,-undefined,error'])
                CXXFLAGS="-Wall -Werror -Wl,-undefined,error"
                AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
                        [AC_MSG_RESULT([yes])
                                NO_UNDEFINED_PARAM=-Wl,-undefined,error
                        ],
                        [AC_MSG_RESULT([no])
                                NO_UNDEFINED_PARAM=""
                        ]
                )
        ]
)
CXXFLAGS="$TMP_CXXFLAGS"
AC_LANG_POP([C++])

Any input to what I might be doing wrong?

Kind regards
Bent Bisballe Nyeng

_______________________________________________
Autoconf mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/autoconf
Reply | Threaded
Open this post in threaded view
|

Re: How to check for linker argument support?

Bent Bisballe Nyeng
On 12/10/16 12:22, Bent Bisballe Nyeng wrote:

> Hi list
>
> I want to use the --no-undefined linker argument through the
> -Wl,--no-undefined CXXFLAGS. This is only supported by gcc but has a
> clang alternative: -Wl,-undefined,error.
> I have tried writing a test in my configure.ac script to figure out
> which one should be used, but my test reports 'yes' on both gcc and
> clang, so clang never falls back to it's own variant.
> My test looks like this:
>
> dnl ===========================
> dnl Check for -Wl,--no-undefined or -Wl,-undefined,error support
> dnl ===========================
> AC_LANG_PUSH([C++])
> TMP_CXXFLAGS="$CXXFLAGS"
> AC_MSG_CHECKING([whether CXX supports '-Wl,--no-undefined'])
> CXXFLAGS="-Wall -Werror -Wl,--no-undefined"
> AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
>     [ AC_MSG_RESULT([yes])
>         NO_UNDEFINED_PARAM=-Wl,--no-undefined
>     ],
>     [ AC_MSG_RESULT([no])
>         AC_MSG_CHECKING([whether CXX supports '-Wl,-undefined,error'])
>         CXXFLAGS="-Wall -Werror -Wl,-undefined,error"
>         AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
>             [AC_MSG_RESULT([yes])
>                 NO_UNDEFINED_PARAM=-Wl,-undefined,error
>             ],
>             [AC_MSG_RESULT([no])
>                 NO_UNDEFINED_PARAM=""
>             ]
>         )
>     ]
> )
> CXXFLAGS="$TMP_CXXFLAGS"
> AC_LANG_POP([C++])
>
> Any input to what I might be doing wrong?
>

I found out that I needed to use AC_COMPILE_IFELSE instead of
AC_LINK_IFELSE because test need to be done through the compiler in
order to use the -Wall and -Werror and thereby result in the error the
way I the test needs it to.

Kind regards
Bent Bisballe Nyeng


_______________________________________________
Autoconf mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/autoconf
Reply | Threaded
Open this post in threaded view
|

Re: How to check for linker argument support?

Mike Frysinger
In reply to this post by Bent Bisballe Nyeng
On 10 Dec 2016 12:22, Bent Bisballe Nyeng wrote:
> I want to use the --no-undefined linker argument through the
> -Wl,--no-undefined CXXFLAGS. This is only supported by gcc but has a
> clang alternative: -Wl,-undefined,error.

you're referring to a linker option, not a compiler, so gcc/clang don't
care here.

if you're using libtool to link your libs (which you prob should), then
have you tried using -no-undefined instead ?
-mike

_______________________________________________
Autoconf mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/autoconf

signature.asc (836 bytes) Download Attachment