bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cannot figure out how to work with GNULIB_NAMESPACE without warnings


From: Bruno Haible
Subject: Re: cannot figure out how to work with GNULIB_NAMESPACE without warnings
Date: Thu, 14 Jan 2021 01:58:16 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-197-generic; KDE/5.18.0; x86_64; ; )

Hi Alexandre,

> I ran into the following linking issue, which I did not have 8 months ago.
> 
> /usr/bin/i686-w64-mingw32-ld: misc/.libs/libmisc.a(satsolver.o): in function 
> `ZNSt13basic_filebufIcSt11char_traitsIcEED4Ev':
> /usr/lib/gcc/i686-w64-mingw32/10-posix/include/c++/fstream:249: undefined 
> reference to `std::basic_filebuf<char, std::char_traits<char> >::rpl_close()'
> collect2: error: ld returned 1 exit status
> 
> [That's a cross compilation for MinGW, obviously.]
> 
> Since this seems to the kind of error documented on
> https://www.gnu.org/software/gnulib/manual/html_node/A-C_002b_002b-namespace-for-gnulib.html
> I tried to do
> 
>    AC_DEFINE_UNQUOTED([GNULIB_NAMESPACE], [gnulib])

Right. In a C compilation, the recommendation would be "Include <unistd.h> 
first,
so that 'close' gets defined to 'rpl_close' early enough." But in C++, it is
easier and more robust to define GNULIB_NAMESPACE.

> However then compilation failed with a message telling me that a
> system-installed header should use gnulib::vsnprintf instead
> of std::vsnprintf!
> 
> libtool: compile:  clang++ -Qunused-arguments -DHAVE_CONFIG_H -I. -I../.. 
> -I../.. -I../.. -I../../buddy/src -I../../lib -I../../lib -W -Wall -Werror 
> -Wint-to-void-pointer-cast -Wcast-align -Wpointer-arith -Wwrite-strings 
> -Wcast-qual -DXTSTRINGDEFINES -Wdocumentation -Wmissing-declarations 
> -Woverloaded-virtual -Wmisleading-indentation -Wimplicit-fallthrough 
> -Wnull-dereference -Wsuggest-override -Wpedantic -fvisibility=hidden 
> -fvisibility-inlines-hidden -DSPOT_BUILD -std=c++20 -g -O -MT clz.lo -MD -MP 
> -MF .deps/clz.Tpo -c clz.cc  -fPIC -DPIC -o .libs/clz.o
> In file included from bitvect.cc:23:
> In file included from ../../spot/misc/bitvect.hh:22:
> In file included from ../../spot/misc/common.hh:21:
> In file included from 
> /usr/sbin/../lib64/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0/stdexcept:39:
> In file included from 
> /usr/sbin/../lib64/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0/string:55:
> /usr/sbin/../lib64/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../include/c++/10.2.0/bits/basic_string.h:6652:50:
>  error: The symbol ::vsnprintf refers to the system function. Use 
> gnulib::vsnprintf instead. [-Werror,-Wuser-defined-warnings]
>     return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
>                                                  ^

The use of '-Werror' has distorted your view of what warnings are about.

Warnings are not a means to make your compilation fail.

Warnings are a means to give you, the developer, some hints about possible/
suggested changes to your program.

In this case, Gnulib gives you the hint: Attention, you are using ::vsnprintf,
which has many bugs, as documented in
<https://www.gnu.org/software/gnulib/manual/html_node/vsnprintf.html>
Suggestion: use gnulib::vsnprintf instead.

You decide whether to follow this suggestion. If you follow it, this warning
will disappear. If you don't follow it, at the end of going through all
warnings, you add '-Wno-user-defined-warnings' to your CPPFLAGS, and are done
with it.

Bruno




reply via email to

[Prev in Thread] Current Thread [Next in Thread]