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

Cannot build using mingw on Ubuntu and conan #548

Closed
DerKnerd opened this issue Mar 19, 2022 · 41 comments
Closed

Cannot build using mingw on Ubuntu and conan #548

DerKnerd opened this issue Mar 19, 2022 · 41 comments

Comments

@DerKnerd
Copy link

Hey,

when I try to build an app that uses this library and wxWidgets. When ever I try to build the app using mingw on Ubuntu it fails with the following error:

/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x2b): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x4a): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x89): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0xa8): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainApp.cpp.obj):MainApp.cpp:(.text.startup+0x2b): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainApp.cpp.obj):MainApp.cpp:(.text.startup+0x4a): more undefined references to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)' follow
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x24b9): undefined reference to `pqxx::connection::init(char const*)'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x24f4): undefined reference to `pqxx::internal::basic_transaction::basic_transaction(pqxx::connection&, pqxx::zview)'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x253d): undefined reference to `pqxx::connection::esc[abi:cxx11](std::basic_string_view<char, std::char_traits<char> >) const'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x274a): undefined reference to `pqxx::transaction_base::exec(std::basic_string_view<char, std::char_traits<char> >, std::basic_string_view<char, std::char_traits<char> >)'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2782): undefined reference to `pqxx::result::begin() const'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x278a): undefined reference to `pqxx::result::size() const'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2794): undefined reference to `pqxx::result::columns() const'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x27b5): undefined reference to `pqxx::row::row(pqxx::result const&, int, int)'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2e23): undefined reference to `pqxx::row::operator[](pqxx::zview) const'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2e2b): undefined reference to `pqxx::field::is_null() const'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2e3b): undefined reference to `pqxx::field::size() const'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2e46): undefined reference to `pqxx::field::c_str() const &'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2e5e): undefined reference to `pqxx::internal::float_traits<float>::from_string(std::basic_string_view<char, std::char_traits<char> >)'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2e92): undefined reference to `pqxx::row::operator[](pqxx::zview) const'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2e9a): undefined reference to `pqxx::field::is_null() const'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2eaa): undefined reference to `pqxx::field::size() const'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2eb5): undefined reference to `pqxx::field::c_str() const &'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2ecd): undefined reference to `pqxx::internal::float_traits<float>::from_string(std::basic_string_view<char, std::char_traits<char> >)'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2f02): undefined reference to `pqxx::row::operator[](pqxx::zview) const'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2f0a): undefined reference to `pqxx::field::is_null() const'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2f1a): undefined reference to `pqxx::field::size() const'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2f25): undefined reference to `pqxx::field::c_str() const &'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2f3d): undefined reference to `pqxx::internal::float_traits<double>::from_string(std::basic_string_view<char, std::char_traits<char> >)'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2f73): undefined reference to `pqxx::row::operator[](pqxx::zview) const'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2f7b): undefined reference to `pqxx::field::is_null() const'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2f8b): undefined reference to `pqxx::field::size() const'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2f96): undefined reference to `pqxx::field::c_str() const &'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2fae): undefined reference to `pqxx::internal::float_traits<double>::from_string(std::basic_string_view<char, std::char_traits<char> >)'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2fed): undefined reference to `pqxx::row::operator[](pqxx::zview) const'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2ff5): undefined reference to `pqxx::field::c_str() const &'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x310d): undefined reference to `pqxx::row::operator[](pqxx::zview) const'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x3115): undefined reference to `pqxx::field::c_str() const &'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x3225): undefined reference to `pqxx::row::operator[](pqxx::zview) const'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x322d): undefined reference to `pqxx::field::c_str() const &'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x3aed): undefined reference to `pqxx::transaction_base::commit()'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x3c9e): undefined reference to `pqxx::transaction_base::close()'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x3ca6): undefined reference to `pqxx::internal::basic_transaction::~basic_transaction()'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x3cb3): undefined reference to `pqxx::connection::close()'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x3f2d): undefined reference to `pqxx::internal::check_pqxx_version_7_7()'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x422f): undefined reference to `pqxx::internal::throw_null_conversion(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x423b): undefined reference to `pqxx::internal::throw_null_conversion(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x4247): undefined reference to `pqxx::internal::throw_null_conversion(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x4253): undefined reference to `pqxx::internal::throw_null_conversion(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x43a5): undefined reference to `pqxx::transaction_base::close()'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x43ad): undefined reference to `pqxx::internal::basic_transaction::~basic_transaction()'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text$_ZN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EED1Ev[_ZN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EED1Ev]+0x14): undefined reference to `pqxx::transaction_base::close()'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text$_ZN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EED1Ev[_ZN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EED1Ev]+0x22): undefined reference to `pqxx::internal::basic_transaction::~basic_transaction()'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text$_ZN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EED0Ev[_ZN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EED0Ev]+0x14): undefined reference to `pqxx::transaction_base::close()'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text$_ZN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EED0Ev[_ZN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EED0Ev]+0x1c): undefined reference to `pqxx::internal::basic_transaction::~basic_transaction()'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text$_ZN4pqxx10connectionD1Ev[_ZN4pqxx10connectionD1Ev]+0xc): undefined reference to `pqxx::connection::close()'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text.startup+0x2b): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text.startup+0x4a): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text.startup+0x78): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text.startup+0xa6): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text.startup+0xd4): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text.startup+0xf3): more undefined references to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)' follow
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.rdata$_ZTVN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EEE[_ZTVN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EEE]+0x20): undefined reference to `pqxx::internal::basic_transaction::do_commit()'
/usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.rdata$_ZTVN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EEE[_ZTVN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EEE]+0x28): undefined reference to `pqxx::transaction_base::do_abort()'
collect2: error: ld returned 1 exit status
gmake[2]: *** [CMakeFiles/filament_manager.dir/build.make:151: bin/filament_manager.exe] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:526: CMakeFiles/filament_manager.dir/all] Error 2
gmake: *** [Makefile:149: all] Error 2
The command '/bin/sh -c cmake --build build/' returned a non-zero code: 2

The issue can be reproduced with the following Dockerfile:

FROM ubuntu:rolling

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get upgrade -y
RUN apt-get install mingw-w64 mingw-w64-x86-64-dev g++-mingw-w64-x86-64 gcc-mingw-w64-x86-64 binutils-mingw-w64-x86-64 build-essential cmake git wget -y
RUN wget https://github.com/conan-io/conan/releases/latest/download/conan-ubuntu-64.deb
RUN dpkg -i conan-ubuntu-64.deb
RUN git clone https://github.com/DerKnerd/filament-browser.git
WORKDIR /filament-browser
RUN git checkout e513b687d92de70bd83ad100b642032c8c44124c
RUN git submodule update --init --recursive
RUN cmake -DCMAKE_TOOLCHAIN_FILE=/filament-browser/mingw-w64-x86_64.cmake -B build -S /filament-browser -DCMAKE_BUILD_TYPE=Release
RUN cmake --build build/

And here is the CMakeList.txt I use:

cmake_minimum_required(VERSION 3.16)
project(filament_manager CXX)

set(CMAKE_CXX_STANDARD 20)

include(./ucm.cmake)
include(./conan.cmake)

ucm_set_runtime(STATIC)
if (WIN32 OR MINGW)
    add_compile_definitions(__WXMSW__ _UNICODE)
    set(BUILD_SHARED_LIBS false)
    set(CMAKE_SYSTEM_NAME Windows)
    set(CMAKE_SYSTEM_PROCESSOR x86_64)
    set(CONAN_ARCHITECTURE x86_64)
    set(CMAKE_WIN32_EXECUTABLE 1)
    set(options Poco:enable_netssl_win=True Poco:enable_netssl=False)

    conan_cmake_run(
            BASIC_SETUP
            ARCH ${CONAN_ARCHITECTURE}
            ENV CC=${CMAKE_C_COMPILER}
            ENV CXX=${CMAKE_CXX_COMPILER}
            ENV CFLAGS=${CMAKE_C_FLAGS}
            ENV CXXFLAGS=${CMAKE_CXX_FLAGS}
            SETTINGS os=Windows
            SETTINGS compiler.cppstd=20
    )
endif ()

set(wxUSE_STL ON)
set(wxBUILD_SHARED OFF)
add_subdirectory(libs/wxWidgets)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})

conan_cmake_configure(
        REQUIRES libpqxx/7.7.0
        GENERATORS cmake_find_package
)

conan_cmake_autodetect(settings)

conan_cmake_install(PATH_OR_REFERENCE .
        BUILD missing
        REMOTE conancenter
        SETTINGS ${settings}
        SETTINGS ${CONAN_SETTINGS}
        OPTIONS Poco:enable_netssl_win=True Poco:enable_netssl=False)

find_package(libpqxx)

add_executable(filament_manager ${target} main.cpp MainApp.h MainApp.cpp MainWindow.cpp MainWindow.h)
target_link_libraries(filament_manager PRIVATE libpqxx::libpqxx wx::core wx::base)

And this is the toolchain file:

# Sample toolchain file for building for Windows from an Ubuntu Linux system.
#
# Typical usage:
#    *) install cross compiler: `sudo apt-get install mingw-w64`
#    *) cd build
#    *) cmake -DCMAKE_TOOLCHAIN_FILE=~/mingw-w64-x86_64.cmake ..

set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)

# cross compilers to use for C, C++ and Fortran
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran)
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)

# target environment on the build host system
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})

# modify default behavior of FIND_XXX() commands
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

Do you by any chance know what causes this issue?

@jtv
Copy link
Owner

jtv commented Mar 19, 2022 via email

@DerKnerd
Copy link
Author

Thats interesting, building it with MSVC on Windows and using gcc on Arch Linux works fine. I might have to dig a bit into the conan config. Do you by any chance know anything how I can force conan to use the same compiler?

@jtv
Copy link
Owner

jtv commented Mar 19, 2022

Don't know conan, sorry.

But in general with C++ you can't expect to link two object files or libraries that were compiled with the same compiler. Some compilers may be binary-compatible with some other compilers, but IMHO tooling made for C++ should probably be designed to use the same compiler across everything that links into the same application.

Another complication by the way is debug mode. Many compilers will let you compile code for "debug" or for "release." The two modes produce different binaries, which you can't link together. It's also possible that that's what went wrong here.

@DerKnerd
Copy link
Author

Thank you for your fast replies. I dug the conan docs a bit deeper and found more details for cross compile. But when I use x86_64-w64-ming32-gcc-win32 for compilation, I get the following error:

/root/.conan/data/libpqxx/7.7.0/_/_/build/ba599f31ceb475d8920e5a73fcfc87943658e2a3/source_subfolder/src/util.cxx:227:3: error: 'select' was not declared in this scope
  227 |   select(0, nullptr, nullptr, nullptr, &tv);

After checking through existing issue I couldn't find a similar issue from anyone else, do you happen to know what is missing there?

@jtv
Copy link
Owner

jtv commented Mar 19, 2022 via email

@jtv
Copy link
Owner

jtv commented Mar 19, 2022

Found it. Turns out util.cxx also needs to include winsock2.h.

Could you try the latest commit? Should fix it.

@jtv
Copy link
Owner

jtv commented Mar 19, 2022

@DerKnerd I ended up making some pretty far-reaching changes today. Shouldn't affect binary compatibility, but there's always a risk of breaking compatibility with some systems. Could you try the very latest commit for me, to see if everything still works?

I think I managed to make compiles a bit faster in the process.

@DerKnerd
Copy link
Author

@jtv I would love to, but for that I would first need an update for the conan version. Since it isn't git based I can't change the branch :/

@jtv
Copy link
Owner

jtv commented Mar 19, 2022

Anything I can do to make that happen (bearing in mind though that I don't know the first thing about conan)?

@DerKnerd
Copy link
Author

AFAIK there needs to be a new conan release, they are managed in a different repo and usually update after you create a new release. So you would need to create a release and I have to wait til they update it.

@tt4g
Copy link
Contributor

tt4g commented Mar 20, 2022

@DerKnerd If you import the libpqxx project into your project with the git submodule command, you should be able to see it working with the latest sources.
Assuming you have imported libpqxx into libs/libpqxx, change your CMakeLists.txt as follows:

 set(wxUSE_STL  ON)
 set(wxBUILD_SHARED  OFF)
 add_subdirectory(libs/wxWidgets)
+add_subdirectory(libs/libpqxx)

 list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
 list(APPEND CMAKE_PREFIX_PATH  CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})

-conan_cmake_configure(
-        REQUIRES libpqxx/7.7.0        REQUIRES libpqxx/7.7.0
-        GENERATORS cmake_find_package        GENERATORS cmake_find_package
-)
+# conan_cmake_configure(
+#         REQUIRES libpqxx/7.7.0        REQUIRES libpqxx/7.7.0
+#         GENERATORS cmake_find_package        GENERATORS cmake_find_package
+# )
+conan_cmake_configure(
+    REQUIRES libpq/12.2        REQUIRES libpq/12.2
+    GENERATORS cmake_find_package        GENERATORS cmake_find_package
+)

@DerKnerd
Copy link
Author

@tt4g I updated the code and added the submodule, I now get a new error, but still only with mingw.

gmake[2]: stat: libs/libpqxx/src/libpqxx.a: Too many levels of symbolic links
gmake[2]: *** No rule to make target 'libs/libpqxx/src/libpqxx.a', needed by 'filament_manager.exe'.  Stop.
gmake[1]: *** [CMakeFiles/Makefile2:476: CMakeFiles/filament_manager.dir/all] Error 2
gmake: *** [Makefile:171: all] Error 2
The command '/bin/sh -c cmake --build build/' returned a non-zero code: 2

@tt4g
Copy link
Contributor

tt4g commented Mar 21, 2022

@DerKnerd I built the Dockerfile from filament-browser repository, but could not reproduce the error.

NOTE I installed the postgresql library with apt-get and specified the PostgreSQL 13 library path with the cmake command. and I also made some changes to CMakeLists.txt (e.g. remove find_package(pqxx)).

 cmake -DCMAKE_TOOLCHAIN_FILE=/filament-browser/mingw-w64-x86_64.cmake -B build -S /filament-browser -DCMAKE_BUILD_TYPE=Release -DWIN32=1 \
+	-DPostgreSQL_INCLUDE_DIR=/usr/include/postgresql \
+	-DPostgreSQL_TYPE_INCLUDE_DIR=/usr/include/postgresql \
+	-DPostgreSQL_LIBRARY=/usr/lib/x86_64-linux-gnu/libpq.so

The error message suggests that the symbolic link libs/libpqxx/src/libpqxx.a is a circular reference because it is a relative path.
It may only be reproduced on your machine.
Can you investigate the cause using the following URL link?
https://unix.stackexchange.com/questions/141436/too-many-levels-of-symbolic-links

If you are doing your work on a Docker container, recreating the container may stop the problem.

BTW, I cloned libpqxx repository (commit 20fc436) on a Docker container and successfully built it.
It may be easier to clone libpqxx repository and build it to see if the problem has been resolved.

Log
root@1360f6c471d4:/workspaces# mkdir _
root@1360f6c471d4:/workspaces# cd _
root@1360f6c471d4:/workspaces/_# git clone https://github.com/jtv/libpqxx.git
Cloning into 'libpqxx'...
remote: Enumerating objects: 38207, done.
remote: Counting objects: 100% (3807/3807), done.
remote: Compressing objects: 100% (1171/1171), done.
remote: Total 38207 (delta 2994), reused 3271 (delta 2608), pack-reused 34400
Receiving objects: 100% (38207/38207), 9.30 MiB | 8.44 MiB/s, done.
Resolving deltas: 100% (30994/30994), done.
root@1360f6c471d4:/workspaces/_# cd libpqxx/
root@1360f6c471d4:/workspaces/_/libpqxx/build# git rev-parse HEAD
20fc436375617c6549c6678b615c1b6fc768104e
root@1360f6c471d4:/workspaces/_/libpqxx# mkdir build
root@1360f6c471d4:/workspaces/_/libpqxx# cd build/
root@1360f6c471d4:/workspaces/_/libpqxx/build# cmake -DPostgreSQL_INCLUDE_DIR=/usr/include/postgresql -DPostgreSQL_TYPE_INCLUDE_DIR=/usr/include/postgresql -DPostgreSQL_LIBRARY=/usr/lib/x86_64-linux-gnu/libpq.so ..
-- Found PostgreSQL: /usr/lib/x86_64-linux-gnu/libpq.so (found version "13.6") 
-- Looking for poll
-- Looking for poll - found
-- Looking for PQencryptPasswordConn
-- Looking for PQencryptPasswordConn - found
-- Looking for PQenterPipelineMode
-- Looking for PQenterPipelineMode - not found
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Generating config.h
-- Generating config.h - done
-- Configuring done
-- Generating done
-- Build files have been written to: /workspaces/_/libpqxx/build
root@1360f6c471d4:/workspaces/_/libpqxx/build# cmake --build .
Scanning dependencies of target pqxx
[  0%] Building CXX object src/CMakeFiles/pqxx.dir/array.cxx.o
[  1%] Building CXX object src/CMakeFiles/pqxx.dir/binarystring.cxx.o
[  2%] Building CXX object src/CMakeFiles/pqxx.dir/blob.cxx.o
[  3%] Building CXX object src/CMakeFiles/pqxx.dir/connection.cxx.o
[  4%] Building CXX object src/CMakeFiles/pqxx.dir/cursor.cxx.o
[  5%] Building CXX object src/CMakeFiles/pqxx.dir/encodings.cxx.o
[  6%] Building CXX object src/CMakeFiles/pqxx.dir/errorhandler.cxx.o
[  7%] Building CXX object src/CMakeFiles/pqxx.dir/except.cxx.o
[  7%] Building CXX object src/CMakeFiles/pqxx.dir/field.cxx.o
[  8%] Building CXX object src/CMakeFiles/pqxx.dir/largeobject.cxx.o
[  9%] Building CXX object src/CMakeFiles/pqxx.dir/notification.cxx.o
[ 10%] Building CXX object src/CMakeFiles/pqxx.dir/params.cxx.o
[ 11%] Building CXX object src/CMakeFiles/pqxx.dir/pipeline.cxx.o
[ 12%] Building CXX object src/CMakeFiles/pqxx.dir/result.cxx.o
[ 13%] Building CXX object src/CMakeFiles/pqxx.dir/robusttransaction.cxx.o
[ 14%] Building CXX object src/CMakeFiles/pqxx.dir/row.cxx.o
[ 14%] Building CXX object src/CMakeFiles/pqxx.dir/sql_cursor.cxx.o
[ 15%] Building CXX object src/CMakeFiles/pqxx.dir/strconv.cxx.o
[ 16%] Building CXX object src/CMakeFiles/pqxx.dir/stream_from.cxx.o
[ 17%] Building CXX object src/CMakeFiles/pqxx.dir/stream_to.cxx.o
[ 18%] Building CXX object src/CMakeFiles/pqxx.dir/subtransaction.cxx.o
[ 19%] Building CXX object src/CMakeFiles/pqxx.dir/time.cxx.o
[ 20%] Building CXX object src/CMakeFiles/pqxx.dir/transaction.cxx.o
[ 21%] Building CXX object src/CMakeFiles/pqxx.dir/transaction_base.cxx.o
[ 21%] Building CXX object src/CMakeFiles/pqxx.dir/util.cxx.o
[ 22%] Building CXX object src/CMakeFiles/pqxx.dir/version.cxx.o
[ 23%] Building CXX object src/CMakeFiles/pqxx.dir/wait.cxx.o
[ 24%] Linking CXX static library libpqxx-7.7.a
[ 24%] Built target pqxx
Scanning dependencies of target runner
[ 25%] Building CXX object test/CMakeFiles/runner.dir/runner.cxx.o
[ 26%] Building CXX object test/CMakeFiles/runner.dir/test00.cxx.o
[ 27%] Building CXX object test/CMakeFiles/runner.dir/test01.cxx.o
[ 28%] Building CXX object test/CMakeFiles/runner.dir/test02.cxx.o
[ 28%] Building CXX object test/CMakeFiles/runner.dir/test04.cxx.o
[ 29%] Building CXX object test/CMakeFiles/runner.dir/test07.cxx.o
[ 30%] Building CXX object test/CMakeFiles/runner.dir/test10.cxx.o
[ 31%] Building CXX object test/CMakeFiles/runner.dir/test11.cxx.o
[ 32%] Building CXX object test/CMakeFiles/runner.dir/test13.cxx.o
[ 33%] Building CXX object test/CMakeFiles/runner.dir/test14.cxx.o
[ 34%] Building CXX object test/CMakeFiles/runner.dir/test16.cxx.o
[ 35%] Building CXX object test/CMakeFiles/runner.dir/test17.cxx.o
[ 35%] Building CXX object test/CMakeFiles/runner.dir/test18.cxx.o
[ 36%] Building CXX object test/CMakeFiles/runner.dir/test20.cxx.o
[ 37%] Building CXX object test/CMakeFiles/runner.dir/test21.cxx.o
[ 38%] Building CXX object test/CMakeFiles/runner.dir/test26.cxx.o
[ 39%] Building CXX object test/CMakeFiles/runner.dir/test29.cxx.o
[ 40%] Building CXX object test/CMakeFiles/runner.dir/test30.cxx.o
[ 41%] Building CXX object test/CMakeFiles/runner.dir/test32.cxx.o
[ 42%] Building CXX object test/CMakeFiles/runner.dir/test37.cxx.o
[ 42%] Building CXX object test/CMakeFiles/runner.dir/test39.cxx.o
[ 43%] Building CXX object test/CMakeFiles/runner.dir/test46.cxx.o
[ 44%] Building CXX object test/CMakeFiles/runner.dir/test56.cxx.o
[ 45%] Building CXX object test/CMakeFiles/runner.dir/test60.cxx.o
[ 46%] Building CXX object test/CMakeFiles/runner.dir/test61.cxx.o
[ 47%] Building CXX object test/CMakeFiles/runner.dir/test62.cxx.o
[ 48%] Building CXX object test/CMakeFiles/runner.dir/test69.cxx.o
[ 49%] Building CXX object test/CMakeFiles/runner.dir/test70.cxx.o
[ 50%] Building CXX object test/CMakeFiles/runner.dir/test71.cxx.o
[ 50%] Building CXX object test/CMakeFiles/runner.dir/test72.cxx.o
[ 51%] Building CXX object test/CMakeFiles/runner.dir/test74.cxx.o
[ 52%] Building CXX object test/CMakeFiles/runner.dir/test75.cxx.o
[ 53%] Building CXX object test/CMakeFiles/runner.dir/test76.cxx.o
[ 54%] Building CXX object test/CMakeFiles/runner.dir/test77.cxx.o
[ 55%] Building CXX object test/CMakeFiles/runner.dir/test78.cxx.o
[ 56%] Building CXX object test/CMakeFiles/runner.dir/test79.cxx.o
[ 57%] Building CXX object test/CMakeFiles/runner.dir/test82.cxx.o
[ 57%] Building CXX object test/CMakeFiles/runner.dir/test84.cxx.o
[ 58%] Building CXX object test/CMakeFiles/runner.dir/test87.cxx.o
[ 59%] Building CXX object test/CMakeFiles/runner.dir/test88.cxx.o
[ 60%] Building CXX object test/CMakeFiles/runner.dir/test89.cxx.o
[ 61%] Building CXX object test/CMakeFiles/runner.dir/test90.cxx.o
[ 62%] Building CXX object test/CMakeFiles/runner.dir/unit/test_array.cxx.o
[ 63%] Building CXX object test/CMakeFiles/runner.dir/unit/test_binarystring.cxx.o
[ 64%] Building CXX object test/CMakeFiles/runner.dir/unit/test_blob.cxx.o
[ 64%] Building CXX object test/CMakeFiles/runner.dir/unit/test_cancel_query.cxx.o
[ 65%] Building CXX object test/CMakeFiles/runner.dir/unit/test_column.cxx.o
[ 66%] Building CXX object test/CMakeFiles/runner.dir/unit/test_composite.cxx.o
[ 67%] Building CXX object test/CMakeFiles/runner.dir/unit/test_connection.cxx.o
[ 68%] Building CXX object test/CMakeFiles/runner.dir/unit/test_cursor.cxx.o
[ 69%] Building CXX object test/CMakeFiles/runner.dir/unit/test_encodings.cxx.o
[ 70%] Building CXX object test/CMakeFiles/runner.dir/unit/test_error_verbosity.cxx.o
[ 71%] Building CXX object test/CMakeFiles/runner.dir/unit/test_errorhandler.cxx.o
[ 71%] Building CXX object test/CMakeFiles/runner.dir/unit/test_escape.cxx.o
[ 72%] Building CXX object test/CMakeFiles/runner.dir/unit/test_exceptions.cxx.o
[ 73%] Building CXX object test/CMakeFiles/runner.dir/unit/test_field.cxx.o
[ 74%] Building CXX object test/CMakeFiles/runner.dir/unit/test_float.cxx.o
[ 75%] Building CXX object test/CMakeFiles/runner.dir/unit/test_largeobject.cxx.o
[ 76%] Building CXX object test/CMakeFiles/runner.dir/unit/test_nonblocking_connect.cxx.o
[ 77%] Building CXX object test/CMakeFiles/runner.dir/unit/test_notification.cxx.o
[ 78%] Building CXX object test/CMakeFiles/runner.dir/unit/test_pipeline.cxx.o
[ 78%] Building CXX object test/CMakeFiles/runner.dir/unit/test_prepared_statement.cxx.o
[ 79%] Building CXX object test/CMakeFiles/runner.dir/unit/test_range.cxx.o
[ 80%] Building CXX object test/CMakeFiles/runner.dir/unit/test_read_transaction.cxx.o
[ 81%] Building CXX object test/CMakeFiles/runner.dir/unit/test_result_iteration.cxx.o
[ 82%] Building CXX object test/CMakeFiles/runner.dir/unit/test_result_slicing.cxx.o
[ 83%] Building CXX object test/CMakeFiles/runner.dir/unit/test_row.cxx.o
[ 84%] Building CXX object test/CMakeFiles/runner.dir/unit/test_separated_list.cxx.o
[ 85%] Building CXX object test/CMakeFiles/runner.dir/unit/test_simultaneous_transactions.cxx.o
[ 85%] Building CXX object test/CMakeFiles/runner.dir/unit/test_sql_cursor.cxx.o
[ 86%] Building CXX object test/CMakeFiles/runner.dir/unit/test_stateless_cursor.cxx.o
[ 87%] Building CXX object test/CMakeFiles/runner.dir/unit/test_strconv.cxx.o
[ 88%] Building CXX object test/CMakeFiles/runner.dir/unit/test_stream_from.cxx.o
[ 89%] Building CXX object test/CMakeFiles/runner.dir/unit/test_stream_to.cxx.o
[ 90%] Building CXX object test/CMakeFiles/runner.dir/unit/test_string_conversion.cxx.o
[ 91%] Building CXX object test/CMakeFiles/runner.dir/unit/test_subtransaction.cxx.o
[ 92%] Building CXX object test/CMakeFiles/runner.dir/unit/test_test_helpers.cxx.o
[ 92%] Building CXX object test/CMakeFiles/runner.dir/unit/test_thread_safety_model.cxx.o
[ 93%] Building CXX object test/CMakeFiles/runner.dir/unit/test_time.cxx.o
[ 94%] Building CXX object test/CMakeFiles/runner.dir/unit/test_transaction.cxx.o
[ 95%] Building CXX object test/CMakeFiles/runner.dir/unit/test_transaction_base.cxx.o
[ 96%] Building CXX object test/CMakeFiles/runner.dir/unit/test_transaction_focus.cxx.o
[ 97%] Building CXX object test/CMakeFiles/runner.dir/unit/test_transactor.cxx.o
[ 98%] Building CXX object test/CMakeFiles/runner.dir/unit/test_type_name.cxx.o
[ 99%] Building CXX object test/CMakeFiles/runner.dir/unit/test_zview.cxx.o
[100%] Linking CXX executable runner
[100%] Built target runner
root@1360f6c471d4:/workspaces/_/libpqxx/build# 

@DerKnerd
Copy link
Author

@tt4g hey, under Linux it builds completly fine, only in my mingw environment it fails. I updated the code and pushed it to Github, would you mind checking if it builds now? I still get the same error. I adjusted the add_subdirectory calls to use absolute paths instead of relative ones, but no luck.

@tt4g
Copy link
Contributor

tt4g commented Mar 21, 2022

@DerKnerd Are stat: libs/libpqxx/src/libpqxx.a: Too many levels of symbolic links errors still being reported? If so, that is most likely a machine-specific problem, so I don't think it makes much sense to build in a Docker container.

Can you try to build a cloned libpqxx repository in your MinGW environment?
Because it would be easier to build the libpqxx project by itself and see if the MinGW header include issue is resolved than to build libpqxx with the complex your project issue resolved.

@tt4g
Copy link
Contributor

tt4g commented Mar 21, 2022

If you are using a network drive, it may be related to error Too many levels of symbolic links: msys2/msys2-runtime#58

@DerKnerd
Copy link
Author

@tt4g The mingw environment resides inside a Ubuntu docker container. So it shouldn't be a machine specific issue. As I said on the Arch Linux host it works just fine. The Dockerfile copies the files over to the container.

I updated the Dockerfile to clone the repo to make sure it is clean, but the issue persists.

This is the current Dockerfile:

FROM ubuntu:21.10

ENV CONAN_REVISIONS_ENABLED 1
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get upgrade -y
RUN apt-get install mingw-w64-x86-64-dev g++-mingw-w64-x86-64-posix gcc-mingw-w64-x86-64-posix binutils-mingw-w64-x86-64 build-essential cmake git wget -y
RUN wget https://github.com/conan-io/conan/releases/latest/download/conan-ubuntu-64.deb
RUN dpkg -i conan-ubuntu-64.deb
RUN git clone https://github.com/DerKnerd/filament-browser.git
WORKDIR /filament-browser
RUN git submodule update --init --recursive
RUN cmake -DCMAKE_TOOLCHAIN_FILE=/filament-browser/mingw-w64-x86_64.cmake -B build -S /filament-browser -DCMAKE_BUILD_TYPE=Release -DWIN32=1 -G "Unix Makefiles"
RUN cmake --build build/ -- -j12

And this is the CMakeLists.txt, I get the feeling something here is wrong, but I can't put my finger on the part that is wrong.

cmake_minimum_required(VERSION 3.16)
project(filament_manager CXX)


set(CMAKE_CXX_STANDARD 20)

include(./ucm.cmake)
include(./conan.cmake)

ucm_set_runtime(STATIC)
if (WIN32 OR MINGW)
    add_compile_definitions(__WXMSW__ _UNICODE)
    set(BUILD_SHARED_LIBS false)
    set(CMAKE_SYSTEM_NAME Windows)
    set(CMAKE_SYSTEM_PROCESSOR x86_64)
    set(CMAKE_WIN32_EXECUTABLE 1)
endif ()

set(wxUSE_STL ON)
set(wxBUILD_SHARED OFF)
set(wxUSE_AUI OFF)
set(wxUSE_RIBBON OFF)
set(wxUSE_RICHTEXT OFF)
set(wxUSE_XRC OFF)
set(wxUSE_ADV OFF)
set(wxUSE_OPENGL OFF)
set(wxUSE_PROPGRID OFF)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})

conan_add_remote(NAME conan.imanuel.dev
        URL https://conan.imanuel.dev/artifactory/api/conan/conan-virtual)

conan_cmake_configure(
        REQUIRES libpq/12.2
        GENERATORS cmake_find_package
)

conan_cmake_autodetect(settings)

if (MINGW)
    conan_cmake_install(PATH_OR_REFERENCE .
            BUILD missing
            REMOTE conan.imanuel.dev
            SETTINGS ${settings}
            PROFILE ${CMAKE_SOURCE_DIR}/linux_to_win64_conan)
else ()
conan_cmake_install(PATH_OR_REFERENCE .
        BUILD all
        REMOTE conan.imanuel.dev
        SETTINGS ${settings})
endif ()

find_package(PostgreSQL)
add_subdirectory(${CMAKE_SOURCE_DIR}/libs/wxWidgets)
add_subdirectory(${CMAKE_SOURCE_DIR}/libs/libpqxx)

add_executable(filament_manager ${target} main.cpp MainApp.h MainApp.cpp MainWindow.cpp MainWindow.h)
target_link_libraries(filament_manager PRIVATE PostgreSQL::PostgreSQL pqxx wx::core wx::base)

@tt4g
Copy link
Contributor

tt4g commented Mar 21, 2022

@DerKnerd I am using Docker on Windows OS machine so it may be a difference in host OS.
However, the original purpose should have been a symbol that select() could not solve with MinGW, there is no need to stick to the problem caused by adding libpqxx to your project by add_subdirectory().

As per this comment I was able to build the latest libpqxx in your Docker container.
After the next libpqxx release you can use conan to get libpqxx into your project if you build libpqxx in the same way.

Can you try attaching it to your Docker container and see if you can clone the libpqxx repository and build it?

@jtv
Copy link
Owner

jtv commented Mar 21, 2022

I'll try to do a release really soon then.

@DerKnerd
Copy link
Author

@tt4g I changed the mingw compiler back to the win32 version instead of posix. If it compiles using that settings I am all happy 🙂
@jtv That would be awesome, currently conan gives the same issue with mingw about the broken symlinks. So I get the feeling it is an issue with the posix mingw compiler.

@DerKnerd
Copy link
Author

@tt4g I was not able to build it using win32. You linked it against the Linux binary not the Windows binary which I need. Linking a Linux version was never an issue.

@tt4g
Copy link
Contributor

tt4g commented Mar 22, 2022

I was not able to build it using win32.

This Issue said MinGW on Ubuntu. What do you mean by "build it using win32"?.

EDIT: Meaning the Too many levels of symbolic links error is not resolved, I was able to reproduce it in the Docker container.
Please provide an error log or message as much as possible to avoid misunderstandings.

error log
gmake[3]: stat: libs/libpqxx/src/libpqxx.a: Too many levels of symbolic links
gmake[3]: *** No rule to make target 'libs/libpqxx/src/libpqxx.a', needed by 'filament_manager.exe'.  Stop.
gmake[2]: *** [CMakeFiles/Makefile2:454: CMakeFiles/filament_manager.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:461: CMakeFiles/filament_manager.dir/rule] Error 2
gmake: *** [Makefile:205: filament_manager] Error 2

@tt4g
Copy link
Contributor

tt4g commented Mar 22, 2022

@DerKnerd If the problem you are working on now is the Too many levels of symbolic links error, ignore it for now. The problem is probably caused by CMake (or Docker, MinGW), not libpqxx. That problem may not be solved by the libpqxx project.

The first issue I was working on in this Issue was "cannot be built libpqxx with MinGW".
The latest source code has been fixed and libpqxx will be released if you can build libpqxx with MinGW.
It should be sufficient to build only the libpqxx project for this purpose. There is no need to include libpqxx in your project and build it.

Attach to the Docker container and execute the following command (If comment out all the commands that fail in the Dockerfile and build the Docker image, you should be able to start the container).

$ apt-get install -y postgresql libpq-dev
$ git clone https://github.com/jtv/libpqxx.git /libpqxx
$ cd /libpqxx
$ cmake -DCMAKE_TOOLCHAIN_FILE=/filament-browser/mingw-w64-x86_64.cmake \
    -B build \
    -S /libpqxx \
    -DCMAKE_BUILD_TYPE=Release \
    -DWIN32=1 \
    -G "Unix Makefiles" \
    -DPostgreSQL_INCLUDE_DIR=/usr/include/postgresql \
    -DPostgreSQL_TYPE_INCLUDE_DIR=/usr/include/postgresql \
    -DPostgreSQL_LIBRARY=/usr/lib/x86_64-linux-gnu/libpq.so
$ cmake --build build/

Or modify Dockerfile as follows and build it.

 FROM ubuntu:21.10

 ENV CONAN_REVISIONS_ENABLED 1
 ENV DEBIAN_FRONTEND noninteractive
 RUN apt-get update && apt-get upgrade -y
 RUN apt-get install mingw-w64-x86-64-dev g++-mingw-w64-x86-64 gcc-mingw-w64-x86-64 binutils-mingw-w64-x86-64 build-essential cmake git wget -y
 RUN wget https://github.com/conan-io/conan/releases/latest/download/conan-ubuntu-64.deb
 RUN dpkg -i conan-ubuntu-64.deb
 RUN git clone https://github.com/DerKnerd/filament-browser.git
 WORKDIR /filament-browser
 RUN git submodule update --init --recursive
-RUN cmake -DCMAKE_TOOLCHAIN_FILE=/filament-browser/mingw-w64-x86_64.cmake -B build -S /filament-browser -DCMAKE_BUILD_TYPE=Release -DWIN32=1 -G "Unix Makefiles"
-RUN cmake --build build/ --target filament_manager
+# RUN cmake -DCMAKE_TOOLCHAIN_FILE=/filament-browser/mingw-w64-x86_64.cmake -B build -S /filament-browser -DCMAKE_BUILD_TYPE=Release -DWIN32=1 -G "Unix Makefiles"
+# RUN cmake --build build/ --target filament_manager
+RUN apt-get install -y postgresql libpq-dev
+RUN git clone https://github.com/jtv/libpqxx.git /libpqxx
+WORKDIR /libpqxx
+RUN cmake -DCMAKE_TOOLCHAIN_FILE=/filament-browser/mingw-w64-x86_64.cmake \
+    -B build \
+    -S /libpqxx \
+    -DCMAKE_BUILD_TYPE=Release \
+    -DWIN32=1 \
+    -G "Unix Makefiles" \
+    -DPostgreSQL_INCLUDE_DIR=/usr/include/postgresql \
+    -DPostgreSQL_TYPE_INCLUDE_DIR=/usr/include/postgresql \
+    -DPostgreSQL_LIBRARY=/usr/lib/x86_64-linux-gnu/libpq.so
+RUN cmake --build build/

UPDATE: I noticed that the src/libpqxx.a: Too many levels of symbolic links error occurs only when the -DCMAKE_TOOLCHAIN_FILE=/filament-browser/mingw-w64-x86_64.cmake option argument is specified in the cmake command.
There seems to be a problem with CMake's cross-compilation definitions. I am not an expert in cross-compilation, so I couldn't figure out the cause.

@DerKnerd
Copy link
Author

@tt4g I use mingw to cross compile for windows on Linux, what I thought would be obvious from the CMakeLists.txt. The sample that builds for you links against the Linux lib of libpq not the windows lib. That is what I mean. I will try to build only libpqxx in a mingw environment targeting Windows tomorrow. I will comment the result.

@tt4g
Copy link
Contributor

tt4g commented Mar 23, 2022

The sample that builds for you links against the Linux lib of libpq not the windows lib

If conan is properly integrated with CMake it should define CMake target PostgreSQL::PostgreSQL; if it is linked with libpq for Linux OS instead of conan generated libpq for Windows, I think it is a problem with conan's cross build configuration.

@DerKnerd
Copy link
Author

Why should it be an issue with Conan? Conan produces the correct binaries. The origin issue was, that a windows header was missing in libpqxx.

You are, explicitly, linking against a Linux .so file. The static linked libpq gets correctly generated by Conan and CMake. It fails to link the libpqxx library, which I will try isolated tomorrow.

@tt4g
Copy link
Contributor

tt4g commented Mar 23, 2022

Why should it be an issue with Conan? Conan produces the correct binaries. The origin issue was, that a windows header was missing in libpqxx.

This is because conan defines the CMake target PostgreSQL::PostgreSQL for compatibility with existing CMake projects.
If your CMake project is correctly integrated with conan, find_package(PostgreSQL) should find the binaries generated by conan.

@DerKnerd
Copy link
Author

It does find the binary, like I said. The commands you posted link against the libpq.so. Not the Conan generated binary. The libpq.a links fine it is libpqxx.a which doesn't link.

I will test if the symbolic link issue also happens when I build it without the rest of the app. The linking issue was always with libpqxx.a not libpq.a

@tt4g
Copy link
Contributor

tt4g commented Mar 23, 2022

I may have mistakenly thought you were doing a build of the filament-browser repository (from the word conan binary)..

Are you now running the command I wrote in my comment to build the libpqxx repository?
If so, sorry about that. The purpose of this command was to check if the object file described in this comment could be compiled.
I did not take into account the linking process.
Since I explicitly link to Linux libpq in the following CMake variable, the link error is expected behavior (I should have mentioned that one word).

+    -DPostgreSQL_INCLUDE_DIR=/usr/include/postgresql \
+    -DPostgreSQL_TYPE_INCLUDE_DIR=/usr/include/postgresql \
+    -DPostgreSQL_LIBRARY=/usr/lib/x86_64-linux-gnu/libpq.so

If you want the link to Windows libpq to succeed, you must change the path to the binary generated by conan.

-    -DPostgreSQL_INCLUDE_DIR=/usr/include/postgresql \
-    -DPostgreSQL_TYPE_INCLUDE_DIR=/usr/include/postgresql \
-    -DPostgreSQL_LIBRARY=/usr/lib/x86_64-linux-gnu/libpq.so
+    -DPostgreSQL_INCLUDE_DIR=<PATH_TO_CONAN>/include/postgresql \
+    -DPostgreSQL_TYPE_INCLUDE_DIR=<PATH_TO_CONAN>/include/postgresql \
+    -DPostgreSQL_LIBRARY=<PATH_TO_CONAN>/libpq.a

@DerKnerd
Copy link
Author

I managed to create a super minimal example which recreates the linking issue, which is not related to conan, since the linking issue affects libpqxx only.

This Dockerfile is the example:

FROM ubuntu:21.10

RUN apt-get update && apt-get upgrade -y
RUN apt-get install mingw-w64-x86-64-dev g++-mingw-w64-x86-64-posix gcc-mingw-w64-x86-64-posix binutils-mingw-w64-x86-64 build-essential cmake git wget -y
RUN wget https://github.com/conan-io/conan/releases/latest/download/conan-ubuntu-64.deb
RUN dpkg -i conan-ubuntu-64.deb
RUN mkdir /test
WORKDIR /test
RUN git init
RUN git submodule add https://github.com/jtv/libpqxx.git libs/libpqxx
RUN wget https://gist.github.com/DerKnerd/ab506480e32aab0d2b3e564fa2e67906/raw/0be5039549e71f5080ef15a7173730af0dd1f222/CMakeLists.txt
RUN wget https://gist.github.com/DerKnerd/ab506480e32aab0d2b3e564fa2e67906/raw/0be5039549e71f5080ef15a7173730af0dd1f222/conan.cmake
RUN wget https://gist.github.com/DerKnerd/ab506480e32aab0d2b3e564fa2e67906/raw/0be5039549e71f5080ef15a7173730af0dd1f222/linux_to_win64.conan
RUN wget https://gist.github.com/DerKnerd/ab506480e32aab0d2b3e564fa2e67906/raw/0be5039549e71f5080ef15a7173730af0dd1f222/main.cpp
RUN wget https://gist.github.com/DerKnerd/ab506480e32aab0d2b3e564fa2e67906/raw/0be5039549e71f5080ef15a7173730af0dd1f222/mingw.cmake

RUN cmake -DCMAKE_TOOLCHAIN_FILE=mingw.cmake -B build -S . -DCMAKE_BUILD_TYPE=Release
RUN cmake --build build/

These are the files pulled by wget: https://gist.github.com/DerKnerd/ab506480e32aab0d2b3e564fa2e67906

Executing the cmake commands yields the following output:

Log
Step 16/16 : RUN cmake --build build/
 ---> Running in bcabb632738b
Scanning dependencies of target pqxx
[  0%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/array.cxx.obj
[  1%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/binarystring.cxx.obj
[  2%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/blob.cxx.obj
[  3%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/connection.cxx.obj
[  4%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/cursor.cxx.obj
[  5%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/encodings.cxx.obj
[  6%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/errorhandler.cxx.obj
[  6%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/except.cxx.obj
[  7%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/field.cxx.obj
[  8%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/largeobject.cxx.obj
[  9%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/notification.cxx.obj
[ 10%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/params.cxx.obj
[ 11%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/pipeline.cxx.obj
[ 12%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/result.cxx.obj
[ 12%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/robusttransaction.cxx.obj
[ 13%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/row.cxx.obj
[ 14%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/sql_cursor.cxx.obj
[ 15%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/strconv.cxx.obj
[ 16%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/stream_from.cxx.obj
[ 17%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/stream_to.cxx.obj
[ 18%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/subtransaction.cxx.obj
[ 18%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/time.cxx.obj
[ 19%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/transaction.cxx.obj
[ 20%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/transaction_base.cxx.obj
[ 21%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/util.cxx.obj
[ 22%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/version.cxx.obj
[ 23%] Building CXX object libs/libpqxx/src/CMakeFiles/pqxx.dir/wait.cxx.obj
[91m/test/libs/libpqxx/src/wait.cxx: In function 'void pqxx::internal::wait_fd(int, bool, bool, unsigned int, unsigned int)':
/test/libs/libpqxx/src/wait.cxx:118:17: warning: narrowing conversion of 'seconds' from 'unsigned int' to 'long int' [-Wnarrowing]
  118 |   timeval tv = {seconds, microseconds};
      |                 ^~~~~~~
/test/libs/libpqxx/src/wait.cxx:118:26: warning: narrowing conversion of 'microseconds' from 'unsigned int' to 'long int' [-Wnarrowing]
  118 |   timeval tv = {seconds, microseconds};
      |                          ^~~~~~~~~~~~
[0m[ 24%] Linking CXX static library libpqxx.a
[91mgmake[2]: stat: libs/libpqxx/src/libpqxx.a: Too many levels of symbolic links
[0m[ 24%] Built target pqxx
Scanning dependencies of target test
[ 25%] Building CXX object CMakeFiles/test.dir/main.cpp.obj
[91mgmake[2]: stat: libs/libpqxx/src/libpqxx.a: Too many levels of symbolic links
gmake[2]: *** No rule to make target 'libs/libpqxx/src/libpqxx.a', needed by 'test.exe'.  Stop.
[0m[91mgmake[1]: *** [CMakeFiles/Makefile2:175: CMakeFiles/test.dir/all] Error 2
[0m[91mgmake: *** [Makefile:171: all] Error 2

The full log can be found in the gist.

@tt4g
Copy link
Contributor

tt4g commented Mar 23, 2022

The logs show that the link fails, so it appears that the problem with MinGW not being able to compile the object file, which was mentioned in this comment, has been resolved.

I am not sure if libpqxx is the cause of the error stat: libs/libpqxx/src/libpqxx.a: Too many levels of symbolic links. As I wrote in this comment, if removing -DCMAKE_TOOLCHAIN_FILE=mingw.cmake option from cmake command, will not reproduce this bug.
Therefore, I suspect that it is CMake cross-compilation bug.

NOTE Within the libpqxx project, the CMake command creates symbolic links (see the following permalink). Even after removing this line, the stat: libs/libpqxx/src/libpqxx.a: Too many levels of symbolic links error was reproduced as long as -DCMAKE_TOOLCHAIN_FILE=mingw.cmake was specified. I believe that the symbolic link causing the error is created by an implicit CMake rule.

add_custom_command(TARGET ${tgt} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink "${library_prefix}${output_name}${library_suffix}" "${library_prefix}${name}${library_suffix}"
VERBATIM
COMMAND_EXPAND_LISTS
)

@DerKnerd
Copy link
Author

Yes you are right, the compiling bug is fixed. The weird thing is though, I use the same settings in a different project without libpqxx and everything links fine. So I don't think it is a cmake bug, but rather an issue with the CMakeLists.txt.

@tt4g
Copy link
Contributor

tt4g commented Mar 23, 2022

I defined the CMake variable CMAKE_VERBOSE_MAKEFILE=1 to find the cause.
Unfortunately, the following permalink code was the cause (I don't know why commenting out this add_custom_command() the other day did not solve the problem).

add_custom_command(TARGET ${tgt} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink "${library_prefix}${output_name}${library_suffix}" "${library_prefix}${name}${library_suffix}"
VERBATIM
COMMAND_EXPAND_LISTS
)

I checked the variables in the Docker container and found that name:=pqxx, output_name=$<IF:$<PLATFORM_ID:Windows>,pqxx,pqxx-7.7> are assigned to the variables.
CMake target properties NAME and OUTPUT_NAME are compared in the if() statement, but they do not match because OUTPUT_NAME contains a generator expression (CMake target property OUTPUT_NAME may have a CMake generator expression assigned).
Since NAME and OUTPUT_NAME are the same string at CMake build time, the created symbolic link is a circular reference.

@DerKnerd
Copy link
Author

A perfect, we found the cause. Then lets hope the PR gets merged quick 🙂

@tt4g
Copy link
Contributor

tt4g commented Mar 23, 2022

I create PR #550, this change should avoid the stat: libs/libpqxx/src/libpqxx.a: Too many levels of symbolic links error.

@jtv
Copy link
Owner

jtv commented Mar 23, 2022

Merged #550. It's late but I'll start drafting a release.

@jtv
Copy link
Owner

jtv commented Mar 23, 2022

Just released 7.7.1, which includes the fix.

@jtv
Copy link
Owner

jtv commented Mar 23, 2022

Messed up 7.7.1, so did a new release: 7.7.2.

@tt4g
Copy link
Contributor

tt4g commented Mar 24, 2022

@DerKnerd I created PR (conan-io/conan-center-index#9898) to Add libpqxx 7.7.2 to conan package.

@DerKnerd
Copy link
Author

I can confirm, that the project now builds fine, so I will close this issue.

@jtv
Copy link
Owner

jtv commented Mar 26, 2022

Excellent.

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