gpt4 book ai didi

c++ - 加载共享库时出错 : libbsoncxx. so._noabi:无法打开共享对象文件:没有这样的文件或目录

转载 作者:太空宇宙 更新时间:2023-11-04 12:46:52 25 4
gpt4 key购买 nike

我安装了mongocxx驱动,如图http://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation/所示和当我测试驱动程序时,一切看起来都很好,但是如果更改一点代码,我会在加载共享库时遇到错误:libbsoncxx.so._noabi:无法打开共享对象文件:没有这样的文件或目录

代码:

CMakeLists.txt

cmake_minimum_required(VERSION 3.10)

if(POLICY CMP0025)
cmake_policy(SET CMP0025 NEW)
endif()

project(test_mongodb LANGUAGES C CXX)

if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
endif()

set(CMAKE_PREFIX_PATH CMAKE_PREFIX_PATH "~/opt/mongo-cxx-driver/install")
set(CMAKE_CXX_EXTENSIONS OFF)

if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
endif()


add_executable(test_mongodb main.cpp)

find_package(libmongocxx REQUIRED)

target_include_directories(test_mongodb
PRIVATE ${LIBMONGOCXX_INCLUDE_DIRS}
)

target_link_libraries(test_mongodb
PRIVATE ${LIBMONGOCXX_LIBRARIES}
)

target_compile_definitions(test_mongodb
PRIVATE ${LIBMONGOCXX_DEFINITIONS}
)

add_custom_target(run
COMMAND test_mongodb
DEPENDS test_mongodb
WORKING_DIRECTORY ${CMAKE_PROJECT_DIR}
)

list(FIND LIBMONGOCXX_DEFINITIONS "BSONCXX_STATIC" LIST_IDX)
if (${LIST_IDX} GREATER -1)
message(FATAL_ERROR "Expected BSONCXX_STATIC to not be defined")
endif()
list(FIND LIBMONGOCXX_DEFINITIONS "MONGOCXX_STATIC" LIST_IDX)
if (${LIST_IDX} GREATER -1)
message(FATAL_ERROR "Expected MONGOCXX_STATIC to not be defined")
endif()

main.cpp

#include <iostream>

#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>

#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/cursor.hpp>


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

mongocxx::instance inst;

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

auto client = mongocxx::client{uri};
auto admin = client["admin"];
auto result = admin.run_command(make_document(kvp("isMaster", 1)));
std::cout << bsoncxx::to_json(result) << std::endl;

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

如果我从代码中删除 auto result = admin.run_command(make_document(kvp("isMaster", 1))); 我在加载共享库时得到错误:libbsoncxx.so。 _noabi,如果不能正常工作。知道为什么它会这样吗?

Ubuntu 18.04抄送 7.3.0,C++ 7.3.0,CMake 3.11.3

最佳答案

您在太低的级别进入 CMake find 子系统:Mongo C++ 驱动程序提供与 CMake find_package 子系统的集成,后者为您完成大部分工作。您应该能够简单地说出 find_package(libmongocxx REQUIRED),然后使用预填充的变量 LIIBMONGOCXX_{INCLUDE_DIRS,LIBRARIES,DEFINITIONS}

请查看源代码中的顶级 examples/projects 目录,了解许多示例项目,这些项目展示了如何通过 CMake 的 find_packagepkgconfig

我认为,鉴于您的上述用途,您应该从目录 examples/projects/mongocxx/cmake/shared 开始。

关于c++ - 加载共享库时出错 : libbsoncxx. so._noabi:无法打开共享对象文件:没有这样的文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51131114/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com