Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile error - error: invalid use of ‘this’ at top level #750

Closed
nairary opened this issue Nov 20, 2023 · 10 comments
Closed

Compile error - error: invalid use of ‘this’ at top level #750

nairary opened this issue Nov 20, 2023 · 10 comments

Comments

@nairary
Copy link

nairary commented Nov 20, 2023

Trying to compile code with this lib on manjaro linux with g++ 8.5.0 and astra linux with g++ 8.6.0 have same error on both, can't use higher g++

@jtv
Copy link
Owner

jtv commented Nov 21, 2023

I think gcc 8 can work, but you'll have to set the C++ version. Those gcc versions default to a C++ version that's too told for current libpqxx versions, but you can select a newer version.

Try adding -std=c++17 to your compile versions. (Or soon you will need -std=c++20 as a minimum.)

If you're using the configure script, add CXXFLAGS='-std=c++17' to the configure command line (you can add other compiler options in there as well). If you're using CMake, I believe you need to add -DCMAKE_CXX_FLAGS='-std=c++17' to the cmake command line, with the same notes.

@nairary
Copy link
Author

nairary commented Nov 21, 2023

I'm already using this flag.
This is my compilation line: g++-8 -o name -std=c++17 *.cpp -lssh -pthread -lstdc++fs -lpq -lpqxx

@nairary
Copy link
Author

nairary commented Nov 21, 2023

That's what I get

In file included from /usr/local/include/pqxx/pqxx:17,
from PSQLConnector.h:5,
from PSQLConnector.cpp:1:
/usr/local/include/pqxx/range.hxx:143:24: error: invalid use of ‘this’ at top level
noexcept(noexcept(*this->value() == *rhs.value()))
^~~~
/usr/local/include/pqxx/range.hxx:154:24: error: invalid use of ‘this’ at top level
noexcept(noexcept(*this == rhs))
^~~~
/usr/local/include/pqxx/range.hxx:266:23: error: invalid use of ‘this’ at top level
noexcept(noexcept(this->lower_bound() == rhs.lower_bound()) and noexcept(
^~~~
/usr/local/include/pqxx/range.hxx:267:7: error: invalid use of ‘this’ at top level
this->upper_bound() == rhs.upper_bound()) and noexcept(this->empty()))
^~~~
/usr/local/include/pqxx/range.hxx:267:62: error: invalid use of ‘this’ at top level
this->upper_bound() == rhs.upper_bound()) and noexcept(this->empty()))
^~~~
/usr/local/include/pqxx/range.hxx:275:24: error: invalid use of ‘this’ at top level
noexcept(noexcept(*this == rhs))
^~~~
/usr/local/include/pqxx/range.hxx:315:25: error: invalid use of ‘this’ at top level
noexcept(noexcept((*this & other) == other))
^~~~
In file included from /usr/local/include/pqxx/pqxx:17,
from PSQLConnector.h:5,
from ssh_connector.h:4,
from ssh_connector.cpp:1:
/usr/local/include/pqxx/range.hxx:143:24: error: invalid use of ‘this’ at top level
noexcept(noexcept(*this->value() == *rhs.value()))
^~~~
/usr/local/include/pqxx/range.hxx:154:24: error: invalid use of ‘this’ at top level
noexcept(noexcept(*this == rhs))
^~~~
/usr/local/include/pqxx/range.hxx:266:23: error: invalid use of ‘this’ at top level
noexcept(noexcept(this->lower_bound() == rhs.lower_bound()) and noexcept(
^~~~
/usr/local/include/pqxx/range.hxx:267:7: error: invalid use of ‘this’ at top level
this->upper_bound() == rhs.upper_bound()) and noexcept(this->empty()))
^~~~
/usr/local/include/pqxx/range.hxx:267:62: error: invalid use of ‘this’ at top level
this->upper_bound() == rhs.upper_bound()) and noexcept(this->empty()))
^~~~
/usr/local/include/pqxx/range.hxx:275:24: error: invalid use of ‘this’ at top level
noexcept(noexcept(*this == rhs))
^~~~
/usr/local/include/pqxx/range.hxx:315:25: error: invalid use of ‘this’ at top level
noexcept(noexcept((*this & other) == other))

@nairary
Copy link
Author

nairary commented Nov 21, 2023

Built g++-9 from source package.
Compile with g++-9 -o name -std=c++17 *.cpp -lssh -pthread -lstdc++fs -lpq -lpqxx
Got a lot of undefined references to std::to_chars(char*, char*, float) and std::from_chars(char const*, char const*, float&, std::chars_format)

/usr/bin/ld: /usr/local/lib/libpqxx.a(strconv.o): in function «long double (anonymous namespace)::from_string_arithmetic(std::basic_string_view<char, std::char_traits >)»:
/home/aleksandr/DEV/libpqxx-7.8.1/src/strconv.cxx:289:(.text._ZN12_GLOBAL__N_122from_string_arithmeticIeEET_St17basic_string_viewIcSt11char_traitsIcEE[_ZN4pqxx8internal12float_traitsIeE11from_stringESt17basic_string_viewIcSt11char_traitsIcEE]+0x68): undefined reference to std::from_chars(char const*, char const*, long double&, std::chars_format)' /usr/bin/ld: /usr/local/lib/libpqxx.a(strconv.o): in function «double (anonymous namespace)::from_string_arithmetic<double>(std::basic_string_view<char, std::char_traits<char> >)»: /home/aleksandr/DEV/libpqxx-7.8.1/src/strconv.cxx:289:(.text._ZN12_GLOBAL__N_122from_string_arithmeticIdEET_St17basic_string_viewIcSt11char_traitsIcEE[_ZN4pqxx8internal12float_traitsIdE11from_stringESt17basic_string_viewIcSt11char_traitsIcEE]+0x6b): undefined reference to std::from_chars(char const*, char const*, double&, std::chars_format)'
/usr/bin/ld: /usr/local/lib/libpqxx.a(strconv.o): in function «float (anonymous namespace)::from_string_arithmetic(std::basic_string_view<char, std::char_traits >)»:
/home/aleksandr/DEV/libpqxx-7.8.1/src/strconv.cxx:289:(.text._ZN12_GLOBAL__N_122from_string_arithmeticIfEET_St17basic_string_viewIcSt11char_traitsIcEE[_ZN4pqxx8internal12float_traitsIfE11from_stringESt17basic_string_viewIcSt11char_traitsIcEE]+0x6a): undefined reference to std::from_chars(char const*, char const*, float&, std::chars_format)' /usr/bin/ld: /usr/local/lib/libpqxx.a(strconv.o): in function «std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > pqxx::internal::to_string_float<long double>(long double)»: /home/aleksandr/DEV/libpqxx-7.8.1/src/strconv.cxx:131:(.text._ZN4pqxx8internal15to_string_floatIeEENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEET_[_ZN4pqxx8internal15to_string_floatIeEENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEET_]+0x6e): undefined reference to std::to_chars(char*, char*, long double)'
/usr/bin/ld: /usr/local/lib/libpqxx.a(strconv.o): в функции «std::__cxx11::basic_string<char, std::char_traits, std::allocator > pqxx::internal::to_string_float(double)»:
/home/aleksandr/DEV/libpqxx-7.8.1/src/strconv.cxx:131:(.text.ZN4pqxx8internal15to_string_floatIdEENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEET[ZN4pqxx8internal15to_string_floatIdEENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEET]+0x6a): undefined reference to std::to_chars(char*, char*, double)' /usr/bin/ld: /usr/local/lib/libpqxx.a(strconv.o): in function «std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > pqxx::internal::to_string_float<float>(float)»: /home/aleksandr/DEV/libpqxx-7.8.1/src/strconv.cxx:131:(.text._ZN4pqxx8internal15to_string_floatIfEENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEET_[_ZN4pqxx8internal15to_string_floatIfEENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEET_]+0x6a): undefined reference to std::to_chars(char*, char*, float)'
/usr/bin/ld: /usr/local/lib/libpqxx.a(strconv.o): in function «pqxx::internal::float_traits::into_buf(char*, char*, float const&)»:
/home/aleksandr/DEV/libpqxx-7.8.1/src/strconv.cxx:131:(.text._ZN4pqxx8internal12float_traitsIfE8into_bufEPcS3_RKf[_ZN4pqxx8internal12float_traitsIfE8into_bufEPcS3_RKf]+0x33): undefined reference to std::to_chars(char*, char*, float)' /usr/bin/ld: /usr/local/lib/libpqxx.a(strconv.o): in function «pqxx::internal::float_traits<double>::into_buf(char*, char*, double const&)»: /home/aleksandr/DEV/libpqxx-7.8.1/src/strconv.cxx:131:(.text._ZN4pqxx8internal12float_traitsIdE8into_bufEPcS3_RKd[_ZN4pqxx8internal12float_traitsIdE8into_bufEPcS3_RKd]+0x33): undefined reference to std::to_chars(char*, char*, double)'
/usr/bin/ld: /usr/local/lib/libpqxx.a(strconv.o): in function «pqxx::internal::float_traits::into_buf(char*, char*, long double const&)»:
/home/aleksandr/DEV/libpqxx-7.8.1/src/strconv.cxx:131:(.text._ZN4pqxx8internal12float_traitsIeE8into_bufEPcS3_RKe[_ZN4pqxx8internal12float_traitsIeE8into_bufEPcS3_RKe]+0x34): undefined reference to std::to_chars(char*, char*, long double)' /usr/bin/ld: /usr/local/lib/libpqxx.a(strconv.o): in function «pqxx::internal::float_traits<float>::to_buf(char*, char*, float const&)»: /home/aleksandr/DEV/libpqxx-7.8.1/src/strconv.cxx:131:(.text._ZN4pqxx8internal12float_traitsIfE6to_bufEPcS3_RKf[_ZN4pqxx8internal12float_traitsIfE6to_bufEPcS3_RKf]+0x33): undefined reference to std::to_chars(char*, char*, float)'
/usr/bin/ld: /usr/local/lib/libpqxx.a(strconv.o): in function «pqxx::internal::float_traits::to_buf(char*, char*, double const&)»:
/home/aleksandr/DEV/libpqxx-7.8.1/src/strconv.cxx:131:(.text._ZN4pqxx8internal12float_traitsIdE6to_bufEPcS3_RKd[_ZN4pqxx8internal12float_traitsIdE6to_bufEPcS3_RKd]+0x33): undefined reference to std::to_chars(char*, char*, double)' /usr/bin/ld: /usr/local/lib/libpqxx.a(strconv.o): in function «pqxx::internal::float_traits<long double>::to_buf(char*, char*, long double const&)»: /home/aleksandr/DEV/libpqxx-7.8.1/src/strconv.cxx:131:(.text._ZN4pqxx8internal12float_traitsIeE6to_bufEPcS3_RKe[_ZN4pqxx8internal12float_traitsIeE6to_bufEPcS3_RKe]+0x34): undefined reference to std::to_chars(char*, char*, long double)'

@tt4g
Copy link
Contributor

tt4g commented Nov 21, 2023

The error message "invalid use of 'this' at top level" is probably a bug in gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52869

I think the reason the error occurs when compiling by gcc 9 is that installed libpqxx is not compiled by gcc 9.
If you have built and installed libpqxx yourself, re-install it.

@nairary
Copy link
Author

nairary commented Nov 22, 2023

checking whether we need a link option for <filesystem> support... configure: error: There seems to be <filesystem> support, but I could not figure out now to make it work. You'll have to add set your own build options for this.
Now I'm getting this error, while trying to re-install library with
./configure CXX=gcc-9 CXXFLAGS="-lstdc++fs -std=c++17"
EDIT:
./configure CXX=gcc-9 CXXFLAGS="-std=c++17 -lstdc++fs" LDFLAGS=-L/usr/lib/gcc/x86_64-pc-linux-gnu/9.5.0/include/c++/filesystem
Trying to manually specify the library location does not help

@tt4g
Copy link
Contributor

tt4g commented Nov 22, 2023

Since gcc is C compiler, C++ compiler is g++, you are trying to build C++ source code with a C compiler.
That will never work.

And -lstdc++fs option is not required for GCC 9.

@jtv
Copy link
Owner

jtv commented Nov 22, 2023

Right - it may be possible to build C++ by calling "gcc", since gcc was originally a wrapper for various compilers, but you'd need a bunch of extra options and the simple solution is to call "g++" instead.

In addition to this, I don't think -lstdc++fs belongs in CXXFLAGS. I think it belongs in either LOADLIBES or LDFLAGS.

@jtv
Copy link
Owner

jtv commented Nov 26, 2023

@nairary, did using g++-9 instead of gcc-9 fix it?

@nairary
Copy link
Author

nairary commented Nov 27, 2023

Sorry for taking so long to respond, was busy.
Yes, if configured for g++-9 , then everything will work.
Unfortunately I need to use gcc8 and in the end I decided to switch to libp with C, but thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants