Solved Help with compiling 15+ years old program

I have C++/SQL web application that I wrote when in college. Since then I have moved away from programming, but I still daily use that application, so I would like it to work.

I think last time I managed to recompile it with FreeBSD 10 or 11. Currently result in on 12.3-RELEASE-p5:

Code:
>g++ kliendid.cpp lehepais.cpp -o kliendid.cgi -l pqxx -I/usr/local/include -L/usr/local/lib/
In file included from kliendid.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:2:
In file included from /usr/local/include/pqxx/array:4:
In file included from /usr/local/include/pqxx/array.hxx:17:
/usr/local/include/pqxx/internal/encoding_group.hxx:14:15: warning: nested
      namespace definition is a C++17 extension; define each namespace
      separately [-Wc++17-extensions]
namespace pqxx::internal
              ^~~~~~~~~~
               { namespace internal
In file included from kliendid.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:2:
In file included from /usr/local/include/pqxx/array:4:
In file included from /usr/local/include/pqxx/array.hxx:18:
/usr/local/include/pqxx/internal/encodings.hxx:18:15: warning: nested namespace
      definition is a C++17 extension; define each namespace separately
      [-Wc++17-extensions]
namespace pqxx::internal
              ^~~~~~~~~~
               { namespace internal
In file included from kliendid.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:3:
In file included from /usr/local/include/pqxx/binarystring:4:
In file included from /usr/local/include/pqxx/binarystring.hxx:21:
In file included from /usr/local/include/pqxx/result.hxx:25:
In file included from /usr/local/include/pqxx/util.hxx:32:
/usr/local/include/pqxx/version.hxx:29:15: warning: nested namespace definition
      is a C++17 extension; define each namespace separately
      [-Wc++17-extensions]
namespace pqxx::internal
              ^~~~~~~~~~
               { namespace internal
In file included from kliendid.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:3:
In file included from /usr/local/include/pqxx/binarystring:4:
In file included from /usr/local/include/pqxx/binarystring.hxx:21:
In file included from /usr/local/include/pqxx/result.hxx:25:
In file included from /usr/local/include/pqxx/util.hxx:39:
/usr/local/include/pqxx/internal/libpq-forward.hxx:19:15: warning: nested
      namespace definition is a C++17 extension; define each namespace
      separately [-Wc++17-extensions]
namespace pqxx::internal::pq
              ^~~~~~~~~~~~~~
               { namespace internal { namespace pq
In file included from kliendid.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:3:
In file included from /usr/local/include/pqxx/binarystring:4:
In file included from /usr/local/include/pqxx/binarystring.hxx:21:
In file included from /usr/local/include/pqxx/result.hxx:25:
/usr/local/include/pqxx/util.hxx:55:22: error: no template named
      'is_arithmetic_v' in namespace 'std'; did you mean 'is_arithmetic'?
  static_assert(std::is_arithmetic_v<FROM>);
                ~~~~~^~~~~~~~~~~~~~~
                     is_arithmetic
/usr/include/c++/v1/type_traits:994:50: note: 'is_arithmetic' declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_arithmetic
                                                 ^
In file included from kliendid.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:3:
In file included from /usr/local/include/pqxx/binarystring:4:
In file included from /usr/local/include/pqxx/binarystring.hxx:21:
In file included from /usr/local/include/pqxx/result.hxx:25:
/usr/local/include/pqxx/util.hxx:55:43: error: expected '(' for function-style
      cast or type construction
  static_assert(std::is_arithmetic_v<FROM>);
                ~~~~~~~~~~~~~~~~~~~~~~~~~~^
/usr/local/include/pqxx/util.hxx:56:22: error: no template named
      'is_arithmetic_v' in namespace 'std'; did you mean 'is_arithmetic'?
  static_assert(std::is_arithmetic_v<TO>);
                ~~~~~^~~~~~~~~~~~~~~
                     is_arithmetic
/usr/include/c++/v1/type_traits:994:50: note: 'is_arithmetic' declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_arithmetic
                                                 ^
In file included from kliendid.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:3:
In file included from /usr/local/include/pqxx/binarystring:4:
In file included from /usr/local/include/pqxx/binarystring.hxx:21:
In file included from /usr/local/include/pqxx/result.hxx:25:
/usr/local/include/pqxx/util.hxx:56:41: error: expected '(' for function-style
      cast or type construction
  static_assert(std::is_arithmetic_v<TO>);
                ~~~~~~~~~~~~~~~~~~~~~~~~^
/usr/local/include/pqxx/util.hxx:57:22: error: no template named 'is_integral_v'
      in namespace 'std'; did you mean 'is_integral'?
  static_assert(std::is_integral_v<FROM> == std::is_integral_v<TO>);
                ~~~~~^~~~~~~~~~~~~
                     is_integral
/usr/include/c++/v1/type_traits:764:50: note: 'is_integral' declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_integral
                                                 ^
In file included from kliendid.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:3:
In file included from /usr/local/include/pqxx/binarystring:4:
In file included from /usr/local/include/pqxx/binarystring.hxx:21:
In file included from /usr/local/include/pqxx/result.hxx:25:
/usr/local/include/pqxx/util.hxx:57:42: error: expected '(' for function-style
      cast or type construction
  static_assert(std::is_integral_v<FROM> == std::is_integral_v<TO>);
                ~~~~~~~~~~~~~~~~~~~~~~~~ ^
/usr/local/include/pqxx/util.hxx:57:50: error: no template named 'is_integral_v'
      in namespace 'std'; did you mean 'is_integral'?
  static_assert(std::is_integral_v<FROM> == std::is_integral_v<TO>);
                                            ~~~~~^~~~~~~~~~~~~
                                                 is_integral
/usr/include/c++/v1/type_traits:764:50: note: 'is_integral' declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_integral
                                                 ^
In file included from kliendid.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:3:
In file included from /usr/local/include/pqxx/binarystring:4:
In file included from /usr/local/include/pqxx/binarystring.hxx:21:
In file included from /usr/local/include/pqxx/result.hxx:25:
/usr/local/include/pqxx/util.hxx:57:67: error: expected '(' for function-style
      cast or type construction
  static_assert(std::is_integral_v<FROM> == std::is_integral_v<TO>);
                                            ~~~~~~~~~~~~~~~~~~~~~~^
/usr/local/include/pqxx/util.hxx:61:6: warning: constexpr if is a C++17
      extension [-Wc++17-extensions]
  if constexpr (std::is_same_v<FROM, bool>)
     ^
/usr/local/include/pqxx/util.hxx:61:22: error: no template named 'is_same_v' in
      namespace 'std'; did you mean 'is_same'?
  if constexpr (std::is_same_v<FROM, bool>)
                ~~~~~^~~~~~~~~
                     is_same
/usr/include/c++/v1/type_traits:547:61: note: 'is_same' declared here
  ...<class _Tp, class _Up> struct _LIBCPP_TEMPLATE_VIS is_same           : p...
                                                        ^
In file included from kliendid.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:3:
In file included from /usr/local/include/pqxx/binarystring:4:
In file included from /usr/local/include/pqxx/binarystring.hxx:21:
In file included from /usr/local/include/pqxx/result.hxx:25:
/usr/local/include/pqxx/util.hxx:61:43: error: expected unqualified-id
  if constexpr (std::is_same_v<FROM, bool>)
                                          ^
/usr/local/include/pqxx/util.hxx:70:6: warning: constexpr if is a C++17
      extension [-Wc++17-extensions]
  if constexpr (std::is_signed_v<FROM>)
     ^
/usr/local/include/pqxx/util.hxx:70:22: error: no template named 'is_signed_v'
      in namespace 'std'; did you mean 'is_signed'?
  if constexpr (std::is_signed_v<FROM>)
                ~~~~~^~~~~~~~~~~
                     is_signed
/usr/include/c++/v1/type_traits:1229:50: note: 'is_signed' declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_signed : public __li...
                                                 ^
In file included from kliendid.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:3:
In file included from /usr/local/include/pqxx/binarystring:4:
In file included from /usr/local/include/pqxx/binarystring.hxx:21:
In file included from /usr/local/include/pqxx/result.hxx:25:
/usr/local/include/pqxx/util.hxx:70:39: error: expected unqualified-id
  if constexpr (std::is_signed_v<FROM>)
                                      ^
/usr/local/include/pqxx/util.hxx:72:8: warning: constexpr if is a C++17
      extension [-Wc++17-extensions]
    if constexpr (std::is_signed_v<TO>)
       ^
/usr/local/include/pqxx/util.hxx:72:24: error: no template named 'is_signed_v'
      in namespace 'std'; did you mean 'is_signed'?
    if constexpr (std::is_signed_v<TO>)
                  ~~~~~^~~~~~~~~~~
                       is_signed
/usr/include/c++/v1/type_traits:1229:50: note: 'is_signed' declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_signed : public __li...
                                                 ^
In file included from kliendid.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:3:
In file included from /usr/local/include/pqxx/binarystring:4:
In file included from /usr/local/include/pqxx/binarystring.hxx:21:
In file included from /usr/local/include/pqxx/result.hxx:25:
/usr/local/include/pqxx/util.hxx:72:39: error: expected unqualified-id
    if constexpr (std::is_signed_v<TO>)
                                      ^
/usr/local/include/pqxx/util.hxx:94:6: warning: constexpr if is a C++17
      extension [-Wc++17-extensions]
  if constexpr (std::is_integral_v<FROM>)
     ^
/usr/local/include/pqxx/util.hxx:94:22: error: no template named 'is_integral_v'
      in namespace 'std'; did you mean 'is_integral'?
  if constexpr (std::is_integral_v<FROM>)
                ~~~~~^~~~~~~~~~~~~
                     is_integral
/usr/include/c++/v1/type_traits:764:50: note: 'is_integral' declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_integral
                                                 ^
In file included from kliendid.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:3:
In file included from /usr/local/include/pqxx/binarystring:4:
In file included from /usr/local/include/pqxx/binarystring.hxx:21:
In file included from /usr/local/include/pqxx/result.hxx:25:
/usr/local/include/pqxx/util.hxx:94:41: error: expected unqualified-id
  if constexpr (std::is_integral_v<FROM>)
                                        ^
/usr/local/include/pqxx/util.hxx:100:8: warning: constexpr if is a C++17
      extension [-Wc++17-extensions]
    if constexpr (from_max > to_max)
       ^
/usr/local/include/pqxx/util.hxx:106:11: warning: constexpr if is a C++17
      extension [-Wc++17-extensions]
  else if constexpr ((from_limits::max)() > (to_limits::max)())
          ^
/usr/local/include/pqxx/util.hxx:202:15: warning: nested namespace definition is
      a C++17 extension; define each namespace separately [-Wc++17-extensions]
namespace pqxx::internal
              ^~~~~~~~~~
               { namespace internal
/usr/local/include/pqxx/util.hxx:329:47: error: no type named 'byte' in
      namespace 'std'
unesc_bin(std::string_view escaped_data, std::byte buffer[]);
                                         ~~~~~^
In file included from kliendid.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:3:
In file included from /usr/local/include/pqxx/binarystring:4:
In file included from /usr/local/include/pqxx/binarystring.hxx:21:
In file included from /usr/local/include/pqxx/result.hxx:26:
/usr/local/include/pqxx/zview.hxx:89:15: warning: nested namespace definition is
      a C++17 extension; define each namespace separately [-Wc++17-extensions]
namespace pqxx::internal
              ^~~~~~~~~~
               { namespace internal
In file included from kliendid.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:3:
In file included from /usr/local/include/pqxx/binarystring:4:
In file included from /usr/local/include/pqxx/binarystring.hxx:21:
/usr/local/include/pqxx/result.hxx:31:15: warning: nested namespace definition
      is a C++17 extension; define each namespace separately
      [-Wc++17-extensions]
namespace pqxx::internal
              ^~~~~~~~~~
               { namespace internal
/usr/local/include/pqxx/result.hxx:37:15: warning: nested namespace definition
      is a C++17 extension; define each namespace separately
      [-Wc++17-extensions]
namespace pqxx::internal::gate
              ^~~~~~~~~~~~~~~~
               { namespace internal { namespace gate
In file included from kliendid.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:3:
In file included from /usr/local/include/pqxx/binarystring:4:
In file included from /usr/local/include/pqxx/binarystring.hxx:22:
/usr/local/include/pqxx/strconv.hxx:32:15: warning: nested namespace definition
      is a C++17 extension; define each namespace separately
      [-Wc++17-extensions]
namespace pqxx::internal
              ^~~~~~~~~~
               { namespace internal
/usr/local/include/pqxx/strconv.hxx:177:45: error: no template named 'is_enum_v'
      in namespace 'std'; did you mean 'is_enum'?
struct nullness<ENUM, std::enable_if_t<std::is_enum_v<ENUM>>> : no_null<ENUM>
                                       ~~~~~^~~~~~~~~
                                            is_enum
/usr/include/c++/v1/type_traits:967:50: note: 'is_enum' declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_enum
                                                 ^
In file included from kliendid.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:3:
In file included from /usr/local/include/pqxx/binarystring:4:
In file included from /usr/local/include/pqxx/binarystring.hxx:22:
/usr/local/include/pqxx/strconv.hxx:177:40: error: template argument for
      non-type template parameter must be an expression
struct nullness<ENUM, std::enable_if_t<std::is_enum_v<ENUM>>> : no_null<ENUM>
                                       ^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/v1/type_traits:542:16: note: template parameter is declared
      here
template <bool _Bp, class _Tp = void> using enable_if_t = typename enabl...
               ^
In file included from kliendid.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:3:
In file included from /usr/local/include/pqxx/binarystring:4:
In file included from /usr/local/include/pqxx/binarystring.hxx:22:
/usr/local/include/pqxx/strconv.hxx:182:15: warning: nested namespace definition
      is a C++17 extension; define each namespace separately
      [-Wc++17-extensions]
namespace pqxx::internal
              ^~~~~~~~~~
               { namespace internal
/usr/local/include/pqxx/strconv.hxx:334:25: warning: inline variables are a
      C++17 extension [-Wc++17-extensions]
template<typename TYPE> inline constexpr bool is_sql_array{false};
                        ^
/usr/local/include/pqxx/strconv.hxx:350:25: warning: inline variables are a
      C++17 extension [-Wc++17-extensions]
template<typename TYPE> inline constexpr bool is_unquoted_safe{false};
                        ^
/usr/local/include/pqxx/strconv.hxx:354:22: warning: inline variables are a
      C++17 extension [-Wc++17-extensions]
template<typename T> inline constexpr char array_separator{','};
                     ^
In file included from kliendid.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:3:
In file included from /usr/local/include/pqxx/binarystring:4:
In file included from /usr/local/include/pqxx/binarystring.hxx:22:
In file included from /usr/local/include/pqxx/strconv.hxx:359:
/usr/local/include/pqxx/internal/conversions.hxx:20:15: warning: nested
      namespace definition is a C++17 extension; define each namespace
      separately [-Wc++17-extensions]
namespace pqxx::internal
              ^~~~~~~~~~
               { namespace internal
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 warnings and 20 errors generated.

Any idea how to get it fixed? Is the problem in clang compiler? Or has C++ standard somehow changed? I have really not done any programming in years.

The binary program is still working, using old object files from backup. But those are really old:

Code:
>ldd /***/kliendid.cgi
/***/kliendid.cgi:
        libpqxx-3.1.so => /usr/local/lib/libpqxx-3.1.so (0x800651000)
        libc++.so.1 => /usr/lib/libc++.so.1 (0x8006b1000)
        libcxxrt.so.1 => /lib/libcxxrt.so.1 (0x80077e000)
        libm.so.5 => /lib/libm.so.5 (0x8007a1000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x8007d7000)
        libc.so.7 => /lib/libc.so.7 (0x8007f1000)
        libpq.so.5 => /usr/local/lib/libpq.so.5 (0x800be9000)
        libthr.so.3 => /lib/libthr.so.3 (0x800c3e000)
        libintl.so.8 => /usr/local/lib/libintl.so.8 (0x800c6b000)
        libssl.so.111 => /usr/lib/libssl.so.111 (0x800c79000)
        libcrypto.so.111 => /lib/libcrypto.so.111 (0x800d1d000)
 
You use external library, which uses C++17 features. So first you should add to gcc options -std=c++17.

GCC is not part of the base, therefor you should also add option -Wl,-rpath=/usr/local/lib/gccXX, where XX is version of installed GCC. For more information see GCC package message with command pkg info -D gccXX.

Edit: Typo in the path.
 
Bravo, it worked! Compiled!

g++ kliendid.cpp lehepais.cpp -o kliendid.cgi -l pqxx -I/usr/local/include -L/usr/local/lib/ -std=c++17

Maybe the problem was, that new version of libpqxx, that came with portupgrade, is C++17, but old versions were not?
 
It is likely that the authors of libpqxx raised C++ standard. C++17 is default standard from GCC 10.

I suggest you to add option -Wl,-rpath=/usr/local/lib/gccXX, otherwise you risk unpleasant surprises in your application.

Edit: Typo in the path.
 
Seems I don't have any gcc port installed in this machine and /usr/local/llib/ directory does not exist.

Even in another machine where i have gcc 7,8,9 installed, /usr/local/llib/ directory still does not exist.
 
Seems I don't have any gcc port installed in this machine and /usr/local/llib/ directory does not exist.
Sorry, it was typo. The path could be -Wl,-rpath=/usr/local/lib/gccXX.

g++ command is from GCC compiler. Try to find a package with command pkg which `which g++`.
 
Code:
>which g++
/usr/bin/g++

>ls -la /usr/bin/g++
lrwxr-xr-x  1 root  wheel  16 19 märts  2018 /usr/bin/g++ -> /usr/bin/clang++

Since that symlink does not exist in other machines, seems it was created by me last time I compiled that application in 2018.

What is the recommendation? Should I continue to use binaries I compiled right now with clang or should I install gcc (which version?) and recompile?
 
I recommend you delete your symlink /usr/bin/g++ pointing to clang++. You'll avoid confusion and nasty bugs in the future.
 
Bravo, it worked! Compiled!

g++ kliendid.cpp lehepais.cpp -o kliendid.cgi -l pqxx -I/usr/local/include -L/usr/local/lib/ -std=c++17

Maybe the problem was, that new version of libpqxx, that came with portupgrade, is C++17, but old versions were not?
I think this can be marked as 'Solved' by OP. :D
 
Back
Top