Closed junjiexing closed 6 years ago
The problem is not that it is not defined in the cpp file, the problem is that it is defined multiple times in the header. Which should be OK if I mark it as a weak symbol, but apparently your environment (MSYS? MSYS2?) does accept the __attribute__(( weak ))
, but then decides to ignore it.
What makes the situation worse is that I already tried to find a common solution which would be accepted by all compilers, versions, and environments and especially Clang and MSVC seem to have very different ideas of what the code should look like. It's not an easy problem.
I'll try again to solve this and maybe get rid of the format
variables altogether, at the cost of duplicating quite a bit of code. We'll see... :)
I've committed a fix by manually unrolling the template specializations. Let's see how the CI reacts, meanwhile could you please check if it also solves the problem in your environment? Re-open the issue if necessary. Thanks!
Now I got a compile error, not a link error:
[ 48%] Building CXX object src/test/postgres/CMakeFiles/transaction.dir/transaction.cpp.obj
In file included from D:/Project/Cpp/taocpp_pg/include/tao/postgres/transaction.hpp:13:0,
from D:/Project/Cpp/taocpp_pg/include/tao/postgres/connection.hpp:13,
from D:/Project/Cpp/taocpp_pg/src/test/postgres/transaction.cpp:6:
D:/Project/Cpp/taocpp_pg/include/tao/postgres/parameter_traits.hpp: In constructor 'tao::postgres::parameter_traits<signed char>::parameter_traits(signed char)':
D:/Project/Cpp/taocpp_pg/include/tao/postgres/parameter_traits.hpp:149:57: error: unknown conversion type character 'h' in format [-Werror=format=]
: string_helper( utility::printf( "%hhd", v ) )
^
D:/Project/Cpp/taocpp_pg/include/tao/postgres/parameter_traits.hpp:149:57: error: too many arguments for format [-Werror=format-extra-args]
D:/Project/Cpp/taocpp_pg/include/tao/postgres/parameter_traits.hpp: In constructor 'tao::postgres::parameter_traits<unsigned char>::parameter_traits(unsigned char)':
D:/Project/Cpp/taocpp_pg/include/tao/postgres/parameter_traits.hpp:159:57: error: unknown conversion type character 'h' in format [-Werror=format=]
: string_helper( utility::printf( "%hhu", v ) )
^
D:/Project/Cpp/taocpp_pg/include/tao/postgres/parameter_traits.hpp:159:57: error: too many arguments for format [-Werror=format-extra-args]
D:/Project/Cpp/taocpp_pg/include/tao/postgres/parameter_traits.hpp: In constructor 'tao::postgres::parameter_traits<long long int>::parameter_traits(long long int)':
D:/Project/Cpp/taocpp_pg/include/tao/postgres/parameter_traits.hpp:229:57: error: unknown conversion type character 'l' in format [-Werror=format=]
: string_helper( utility::printf( "%lld", v ) )
^
D:/Project/Cpp/taocpp_pg/include/tao/postgres/parameter_traits.hpp:229:57: error: too many arguments for format [-Werror=format-extra-args]
D:/Project/Cpp/taocpp_pg/include/tao/postgres/parameter_traits.hpp: In constructor 'tao::postgres::parameter_traits<long long unsigned int>::parameter_traits(long long unsigned int)':
D:/Project/Cpp/taocpp_pg/include/tao/postgres/parameter_traits.hpp:239:57: error: unknown conversion type character 'l' in format [-Werror=format=]
: string_helper( utility::printf( "%llu", v ) )
^
D:/Project/Cpp/taocpp_pg/include/tao/postgres/parameter_traits.hpp:239:57: error: too many arguments for format [-Werror=format-extra-args]
D:/Project/Cpp/taocpp_pg/include/tao/postgres/parameter_traits.hpp: In constructor 'tao::postgres::parameter_traits<long double>::parameter_traits(long double)':
D:/Project/Cpp/taocpp_pg/include/tao/postgres/parameter_traits.hpp:269:59: error: unknown conversion type character 'L' in format [-Werror=format=]
: string_helper( utility::printf( "%.21Lg", v ) )
^
D:/Project/Cpp/taocpp_pg/include/tao/postgres/parameter_traits.hpp:269:59: error: too many arguments for format [-Werror=format-extra-args]
cc1plus.exe: all warnings being treated as errors
make[2]: *** [src/test/postgres/CMakeFiles/transaction.dir/build.make:63:src/test/postgres/CMakeFiles/transaction.dir/transaction.cpp.obj] 错误 1
make[1]: *** [CMakeFiles/Makefile2:137:src/test/postgres/CMakeFiles/transaction.dir/all] 错误 2
make: *** [Makefile:141:all] 错误 2
My environment is MSYS2, and gcc version is 7.3.0. But when I use the same version gcc on archlinux to compile it, there is no problem. I don't know what's the problem.
Quick googling turned up this: https://github.com/msys2/msys2/wiki/Porting#c-printf-format-specifier-issues
See if setting __USE_MINGW_ANSI_STDIO=1
helps. I currently don't have the time to support MSYS2 myself, if you could figure out a solution I'd be happy to hear about it.
I try to add add_definitions(-D__USE_MINGW_ANSI_STDIO=1)
to CMakeLists.txt, but has no effective, and I did not find an effective solution to this problem😞. Finally I removed the Werror
compile option.
Compile command:
Output:
It seems that the static variable "format" at there is not defined in the cpp file.