conan-center-index icon indicating copy to clipboard operation
conan-center-index copied to clipboard

[package] mongo-cxx-driver/3.7.0: Ubuntu 22.04.1LTS undefined reference errors

Open kmwagnera opened this issue 2 years ago • 6 comments

Description

If I use this package on Ubuntu+Cmake I have some undefined reference errors if I compile my c++ project. Conan detects prebuild binarys and download and use these if I call conan install --build missing... but it seems that there are some problems with the prebuild binarys, because if I manipulate my conan-profile/settings.yml so that conan not use the prebuild binarys but compile the package from source I do not have any problems and I can compile the c++ project.

Package and Environment Details

Package Name/Version: mongo-cxx-driver/3.7.0 Operating System+version: Linux Ubuntu 22.04.1 LTS Compiler+version: gcc (Ubuntu 11.3.0-1ubuntu122.04) 11.3.0 Conan version: conan 1.58.0 Python version: Python 3.10.6

Conan profile

[settings] os=Linux os_build=Linux arch=x86_64 arch_build=x86_64 compiler=gcc compiler.version=11 compiler.libcxx=libstdc++11 build_type=Release [options] [build_requires] [env]

Steps to reproduce

cd build/ conan install --build missing .. cmake -DCMAKE_BUILD_TYPE=Debug .. make

Cmake:

# ==========================================================
# Cmake configuration
# ============================================================
cmake_minimum_required(VERSION 3.8) # Cmake version
include(FetchContent)               # Enable Fetchcontent
set (CMAKE_CXX_STANDARD 20)         # C++ standard
project(lasal32test)                    # project name
add_compile_definitions(COMPILE_LINUX)

# ==========================================================
# Dependencies
# ==========================================================
# External includes
# Conan
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

# Lasal32 header
#include_directories(${CMAKE_SOURCE_DIR}/include/external/lasal32/src)

# Local includes
include_directories(include ~/.conan/data/** ${CMAKE_SOURCE_DIR}/include/external/lasal32/src) # include local header files
file(GLOB SRC_Files CONFIGURE_DEPENDS # Add all source files
    "src/*.cpp"
    )


# ==========================================================
# create executable
# ==========================================================
add_executable(mw_lasal32test ${SRC_Files})


# ==========================================================
# link nessessary librarys
# ==========================================================
# => pthread
target_link_libraries(mw_lasal32test PRIVATE ${CONAN_LIBS} pthread ${CMAKE_SOURCE_DIR}/include/external/lasal32/build/Linux-x86-64/Lasal64/Release/libLasal64.so)

Main:

#include <cstdlib>
#include <iostream>
#include <string>

#include <bsoncxx/builder/basic/document.hpp>
#include <bsoncxx/builder/basic/kvp.hpp>
#include <bsoncxx/json.hpp>
#include <bsoncxx/stdx/make_unique.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/logger.hpp>
#include <mongocxx/options/client.hpp>
#include <mongocxx/uri.hpp>

namespace {

class logger final : public mongocxx::logger {
   public:
    explicit logger(std::ostream* stream) : _stream(stream) {}

    void operator()(mongocxx::log_level level,
                    bsoncxx::stdx::string_view domain,
                    bsoncxx::stdx::string_view message) noexcept override {
        if (level >= mongocxx::log_level::k_trace)
            return;
        *_stream << '[' << mongocxx::to_string(level) << '@' << domain << "] " << message << '\n';
    }

   private:
    std::ostream* const _stream;
};

}  // namespace

int main(int argc, char* argv[]) {
    using bsoncxx::builder::basic::kvp;
    using bsoncxx::builder::basic::make_document;

    // The mongocxx::instance constructor and destructor initialize and shut down the driver,
    // respectively. Therefore, a mongocxx::instance must be created before using the driver and
    // must remain alive for as long as the driver is in use.
    mongocxx::instance inst{bsoncxx::stdx::make_unique<logger>(&std::cout)};

    try {
        const auto uri = mongocxx::uri{(argc >= 2) ? argv[1] : mongocxx::uri::k_default_uri};

        mongocxx::options::client client_options;
        if (uri.tls()) {
            mongocxx::options::tls tls_options;
            // NOTE: To test TLS, you may need to set options.
            //
            // If the server certificate is not signed by a well-known CA,
            // you can set a custom CA file with the `ca_file` option.
            // tls_options.ca_file("/path/to/custom/cert.pem");
            //
            // If you want to disable certificate verification, you
            // can set the `allow_invalid_certificates` option.
            // tls_options.allow_invalid_certificates(true);
            client_options.tls_opts(tls_options);
        }

        auto client = mongocxx::client{uri, client_options};

        auto admin = client["admin"];

        auto result = admin.run_command(make_document(kvp("ping", 1)));

        std::cout << bsoncxx::to_json(result) << "\n";

        return EXIT_SUCCESS;

    } catch (const std::exception& xcp) {
        std::cout << "connection failed: " << xcp.what() << "\n";
        return EXIT_FAILURE;
    }
}

Logs

worker@UbuntuDev:~/Entwicklung/Datenhaltung/DatabaseManager/build$ make
[ 50%] Building CXX object CMakeFiles/mw_lasal32test.dir/src/main.cpp.o
[100%] Linking CXX executable bin/mw_lasal32test
/usr/bin/ld: /home/worker/.conan/data/mongo-c-driver/1.23.2/_/_/package/1bb61c524f20f7c0b6017e5a4d422a28f1a5f10f/lib/libmongoc-static-1.0.a(mongoc-client.c.o): in function `_mongoc_get_rr_search':
mongoc-client.c:(.text+0xb5): undefined reference to `__res_nsearch'
/usr/bin/ld: /home/worker/.conan/data/mongo-c-driver/1.23.2/_/_/package/1bb61c524f20f7c0b6017e5a4d422a28f1a5f10f/lib/libmongoc-static-1.0.a(mongoc-client.c.o): in function `srv_callback':
mongoc-client.c:(.text+0xcf7): undefined reference to `__dn_expand'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/mw_lasal32test.dir/build.make:99: bin/mw_lasal32test] Fehler 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/mw_lasal32test.dir/all] Fehler 2
make: *** [Makefile:91: all] Fehler 2

kmwagnera avatar Feb 01 '23 21:02 kmwagnera

I have the exact same issue. Is there a solution for this?

sirasjad avatar Mar 10 '23 23:03 sirasjad

I got the same issue. It seems that the symbols in libresolv is not exposed to the mongo-c-driver according to the troubleshooting discussion on the Internet but I'm not sure if it is possible to change that for a conan package.

ProNeverFake avatar Jul 27 '23 16:07 ProNeverFake

Got the same issue on 3.8.1. Solved by building the package from source: conan install --build=mongo-*

@kmwagnera @sirasjad @ProNeverFake

kormanowsky avatar Feb 18 '24 11:02 kormanowsky

I have the same issue too

jeremy-rifkin avatar Jul 26 '24 04:07 jeremy-rifkin

Got the same issue on 3.8.1. Solved by building the package from source: conan install --build=mongo-*

@kmwagnera @sirasjad @ProNeverFake

Nice! I finally downgraded my ubuntu to 20.04 for other projects' requirements and this issue was not there anymore. But thanks!

ProNeverFake avatar Jul 28 '24 08:07 ProNeverFake

Hi there! Is the problem solved?

perseoGI avatar Aug 16 '24 09:08 perseoGI

@perseoGI this problem won't be solved until conan-center CI uses a more recent version of libc. This would also have the benefit of allowing conan-center to build linux binaries for qt, and to stop using a long EOLed distribution (ubuntu 16.04 which subscription-less maintenance stopped 4 years ago, and which docker image's last update is 2.5 years ago see also https://github.com/conan-io/conan-center-index/issues/13472

ericLemanissier avatar Mar 27 '25 13:03 ericLemanissier