-
Notifications
You must be signed in to change notification settings - Fork 240
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
pqxx library build error for crosscompiling on linux for Windows target with Mingw64 #336
Comments
You should be able to use libpqxx 7.1 with postgres 9.3.5, just not with versions older than 9.3. You could even use a newer libpq with an older postgres server. There have been a lot of changes to the CMake build since libpqxx 6.2, so an upgrade may just solve this problem. Another thing you can try is explicitly link to the Windows |
@jtv is right. As far as my search for "undefined reference to pqxx version 6.3.0 and above, The following pqxx 6.3.0 permalink have been added for linking target (this code did not exist earlier than pqxx version 6.2.5): Lines 28 to 30 in d6ffb1a
The best solution is to upgrade pqxx version. |
Wow, thank you so much!
…On Sun, Jun 14, 2020 at 20:44 tt4g ***@***.***> wrote:
@jtv <https://github.com/jtv> is right.
As far as my search for "undefined reference to __imp_select'" goes, it
seems to be a missing link to ws2_32`.
pqxx version 6.3.0 and above, ws2_32 is automatically added to the link
target when the CMake target OS is Windows.
However, pqxx 6.2.5 does not automatically add it to the link target (this
problem fixed by #126 <#126>).
The following pqxx 6.3.0 permalink have been added for linking target
(this code did not exist earlier than pqxx version 6.2.5):
https://github.com/jtv/libpqxx/blob/d6ffb1a13e76995253ef698fb8a6b3d4c6499179/src/CMakeLists.txt#L28-L30
The best solution is to upgrade pqxx version.
Alternatively, add the same code as the above permalink to CMakeLists.txt
in pqxx 6.2.5.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#336 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AE4UHIW2N7EC5M6PC76C2J3RWV4I5ANCNFSM4N5TPFIQ>
.
|
Could you please advise if my understanding of 7.1 build process is correct. I have to use custom location (not one of well-knowns) of PostgreSQL In both 6.2.5 and 7.1.0 the CMakeLists.txt attempts to find_package(PostgreSQL REQUIRED) but since it relies on cmake PostgreSQLConfig.cmake/ postgresql-config.cmake which are not provided with PostgreSQL as it does not have support for CMake fbuild. So custom file would need to be created to use libpqxx CMake build or path to modules would need to to change to avoid using cmake-3.17/Modules/ and use custom FindPostgreSQL/FindPQ.cmake. This is only needed for the sake of setting 1 (or 2 vars) PostgreSQL_LIBRARIES as PostgreSQL_INCLUDE_DIRS could be derived as ../include. So all this could have been done by using find_path or find_library with PATHS set to location of libpq.dll (or .a). Note, aside from this the find_package(PostgreSQL ..) is being called in multiple places config.cmake and src/CMakeLists.txt (plus 2 code locations in test) and I wonder why not in 1 place. I could bypass 2nd by setting PostgreSQL_FOUND |
Now I realized I cant use 7.1 as it requires C++17 so I need to find one that allows C++1 . |
pqxx 7.1.0 required C++17 standard, you don't remove |
Thx, but which one is latest supporting C++11 ? 6.4.0 seems it is |
pqxx 6.4.0 (6.4.6 better) supports C++11 standard. |
ok, thx, still question of bypassing find_package and way of cross- building dll remains. |
Try Example: mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DPostgreSQL_LIBRARY="<PATH_TO_POSTGRES>/lib/libpq.lib" -DPostgreSQL_INCLUDE_DIR="<PATH_TO_INCLUDE_DIR>\include" -DPostgreSQL_TYPE_INCLUDE_DIR="<PATH_TO_INCLUDE_DIR>\include"
cmake --build . --config Debug --target -j 8 Another way, mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DPostgreSQL_ROOT="<PATH_TO_POSTGRES>"
cmake --build . --config Debug --target -j 8 |
I just used find_library and set all necessary variables based on that: SAme error with NOTE: When I built PostgreSQL libpq.lib was not built only .dll, .a, .pc, .rc etc were built |
What compiler and compiler version?
Problem code: libpqxx/include/pqxx/connection_base.hxx Lines 738 to 739 in b20d2f1
Called by: libpqxx/include/pqxx/basic_connection.hxx Lines 49 to 53 in b20d2f1
But libpqxx/include/pqxx/basic_connection.hxx Line 79 in b20d2f1
I ran a very similar code in Wandbox and was able to compile it: https://wandbox.org/permlink/OpB5Iqr9jaQb7sfc It looks like a compiler problem. |
Compiler is mingw64x86_64-w64-mingw32-gcc (GCC) 4.8.2 /x86_64-w64-mingw32-g++ (GCC) 4.8.2
running on ubuntu14.0
cmake generated files show:
CMakeOutput.log
The target system is: Windows - 1 - x86_64
The host system is: Linux - 4.4.0-184-generic - x86_64
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded.
Compiler: /usr/bin/x86_64-w64-mingw32-g++
Building CXX object CMakeFiles/cmTC_3ae0c.dir/CMakeCXXCompilerABI.cpp.obj
/usr/bin/x86_64-w64-mingw32-g++ -v -o CMakeFiles/cmTC_3ae0c.dir/CMakeCXXCompilerABI.cpp.obj -c /opt/cmake/share/cmake-3.17/Modules/CMakeCXXCompilerABI.cpp
Using built-in specs.
COLLECT_GCC=/usr/bin/x86_64-w64-mingw32-g++
Target: x86_64-w64-mingw32
Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --enable-version-specific-runtime-libs --enable-threads=posix --enable-fully-dynamic-string --enable-sjlj-exceptions --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++ --enable-lto --with-plugin-ld --target=x86_64-w64-mingw32 --with-gxx-include-dir=/usr/include/c++/4.8 --with-as=/usr/bin/x86_64-w64-mingw32-as --with-ld=/usr/bin/x86_64-w64-mingw32-ld
Thread model: posix
gcc version 4.8.2 (GCC)
COLLECT_GCC_OPTIONS='-v' '-o' 'CMakeFiles/cmTC_3ae0c.dir/CMakeCXXCompilerABI.cpp.obj' '-c' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-w64-mingw32/4.8/cc1plus -quiet -v -D_REENTRANT /opt/cmake/share/cmake-3.17/Modules/CMakeCXXCompilerABI.cpp -quiet -dumpbase CMakeCXXCompilerABI.cpp -mtune=generic -march=x86-64 -auxbase-strip CMakeFiles/cmTC_3ae0c.dir/CMakeCXXCompilerABI.cpp.obj -version -o /tmp/ccEGdgxs.s
GNU C++ (GCC) version 4.8.2 (x86_64-w64-mingw32)
compiled by GNU C version 4.8.2, GMP version 5.1.2, MPFR version 3.1.2-p3, MPC version 1.0.1
warning: GMP header version 5.1.2 differs from library version 5.1.3.
warning: MPFR header version 3.1.2-p3 differs from library version 3.1.3.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
...
…On Mon, Jun 15, 2020 at 8:02 PM tt4g ***@***.***> wrote:
What compiler and compiler version?
pqxx::connectionpolicy& argument of pqxx::connection_base constructor is
provided by pqxx::basic_connection_base::m_policy.
Problem code:
https://github.com/jtv/libpqxx/blob/b20d2f13cdd74ba4e7f78c7e5d483326197f8f21/include/pqxx/connection_base.hxx#L738-L739
Called by:
https://github.com/jtv/libpqxx/blob/b20d2f13cdd74ba4e7f78c7e5d483326197f8f21/include/pqxx/basic_connection.hxx#L49-L53
But m_policy is member variable of pqxx::basic_connection_base, it should
be able to be an lvalue.
This is not rvalue.
https://github.com/jtv/libpqxx/blob/b20d2f13cdd74ba4e7f78c7e5d483326197f8f21/include/pqxx/basic_connection.hxx#L79
I ran a very similar code in Wandbox and was able to compile it:
https://wandbox.org/permlink/OpB5Iqr9jaQb7sfc
It looks like a compiler problem.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#336 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AE4UHIRNOACPXVHYMW6574TRW3ADHANCNFSM4N5TPFIQ>
.
|
Please also look at the question about building .dll & .lib for Windows rather than .a |
Isn't that a very old compiler? By the way, MinGW might just be enough of a GNU environment that you could perhaps use the But that's just me talking, as a not-a-CMake-expert. Thanks once again @tt4g for taking the reins where I'm out of my depth! |
Switched to newer compiler , trying 5.3.0, 5.3.1 |
Build option Using configure(please add these option to --help) --with-postgres-include and --with-postgres-lib= ... set and configure completed with no errors. ...libpqxx$ make |
@yscontrol Did you build pqxx 6.3.0? If so, Update pqxx 6.3.1 because this issue fixed: #153 |
yes, I upgraded to 6.4.6 and this issue went away. However we are back with the original issue: |
@yscontrol I found the following issue reports:
It seems to be a bug brought about by the C++11 standard. |
I can reproduce " invalid initialization of non-const reference of type ..." error with gcc 4.8.5: https://wandbox.org/permlink/mQr8Olis4MLXrH8O When using gcc 4.9.3, I can compile same code: https://wandbox.org/permlink/aKrhTuuctUA1JUBl @yscontrol There are two solutions. Example: protected:
explicit connection_base(connectionpolicy &pol) :
- m_policy{pol}
+ m_policy(pol) |
That’s great. As I bound to 4.8.5 by the version of mingw64 supported on
ubuntu14.04, I need to do the replacement. Is there an issue logged for
this fix as I assume it would be found before compiler 4.9.3 was released ?
I just want to better understand the issue and see if script made available
to fix it
…On Tue, Jun 16, 2020 at 10:31 PM tt4g ***@***.***> wrote:
I can reproduce " invalid initialization of non-const reference of type
..." error with gcc 4.8.5: https://wandbox.org/permlink/mQr8Olis4MLXrH8O
When using gcc 4.9.3, I can compile same code:
https://wandbox.org/permlink/aKrhTuuctUA1JUBl
@yscontrol <https://github.com/yscontrol> There are two solutions.
The first is to update gcc to at least version 4.9.
The second is to apply a patch that replaces all of the
List-initialization in the source code with parentheses.
Example:
protected:
explicit connection_base(connectionpolicy &pol) :- m_policy{pol}+ m_policy(pol)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#336 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AE4UHIVSOFJRIT6JAOTJVZTRXA2KFANCNFSM4N5TPFIQ>
.
|
From reading the comments on the above link, I'd say that up to gcc 4.8, It was in compliance with the FDIS (final draft international standard) of C++ standard specification. |
Many thanks for your investigation, tt4g. I tried changing instances flagged above and other places causing error got next error in the code:
-So for the sake of compiling I made it public and got next error: pqxx::dbtransaction::dbtransaction( and in ./include/pqxx/transaction_base.hxx |
Have you tried removing the PQXX_NOVTABLE? The error as given is definitely nonsensical — you can't allocate an object of an abstract type, but of course you should be able to base-class-initialise it. |
How do I do that safely? I see |
It's possible that in your case it already happens, but the simplest way to make sure would be to edit |
no, line 60 is under _MSC_VER while I am cross-compiling on linux for Windows |
meanwhile, I tried to build with newer compiler: |
That' s MinGW problem. Maybe this solution will help you: apt - How do I install mingw-std-threads on Ubuntu? - Unix & Linux Stack Exchange Another solutions: |
tt4g, thank you very much , I will have to use cmake /modify libpqxx to include https://github.com/meganz/mingw-std-threads header only lib. However the main approach still requires use of ubuntu 14.04 - gcc 4.8.2 and so resolving issue with "dbtransaction.cxx:45:60: error: cannot allocate an object of abstract type ‘pqxx::transaction_base’ |
Yes. replace
@jtv has commented on that as well.: #336 (comment) |
@jtv Thank you but such change would not have any effect because is under _MSC_VER while I am cross-compiling on Linux for Windows |
@yscontrol yes, I'm just bringing it up because sometimes the lines between "Windows" and "MSVC" get a little blurred. And I've got no other idea why gcc (even version 2.7 if it came to that!) would object to base-class-initialising an abstract class! |
It all depends. If threading is the problem, 7.x can build without thread support. In 6.4 I think you could just remove the two instances of the keyword |
@yscontrol are we done with this ticket? I'm trying to clean up a bit so we can keep a good overview of what the problems are. |
Thank you for your support, but based on more resent attempts to build with different build parameters I think suggested code change (Yes. replace #define PQXX_NOVTABLE __declspec(novtable) with#define PQXX_NOVTABLE.) would be unnecessary with mingw64 gcc 5.3.0/5.3.1 |
Fixes #336, #398, #424, #441 For years now, MinGW has had trouble compiling files which `#include <thread>`. The exact errors seem to have evolved over that time, but MinGW users still can't compile libpqxx without editing the standard header. Luckily we don't use this header much yet. It's just `sleep_for()`. We used to have our own function for this, which would use one of a bunch of platform-specific alternatives. I basically revived it, except that `sleep_for` is in `std` and most compilers implement it, so it's basically MinGW versus everyone else. And therefore, we really only need the one alternate implementation.
I built PostrgeSQL libpq (.dll, .a, ,..) v9.3.6 on ubuntu 14.04 and then tried building libpqxx v6.2.5 using cmake. It failed with error below:
[ 35%] Linking CXX shared library libpqxx.dll
CMakeFiles/pqxx_shared.dir/objects.a(connection_base.cxx.obj):connection_base.cxx:(.text+0x8eac): undefined reference to `__imp_select'
collect2: error: ld returned 1 exit status
make[2]: *** [src/libpqxx.dll] Error 1
make[1]: *** [src/CMakeFiles/pqxx_shared.dir/all] Error 2
make: *** [all] Error
Since PostgreSQL distro doers not have support for find_PQ.cmake, I replaced find_package with find_library and cmake funds static libpq.a while I am trying to build for .dll Windows
I am not sure how to figure out the issue. Changing versions to later is not desirable as I am porting code that works with v9.3.5 on linux (arm or x86).
The text was updated successfully, but these errors were encountered: