0

我有一个 cephfs,我正在使用 libcephfs.h 库用 c 语言编写客户端代码。

注意:安装了 libcephfs-dev 和 libcephfs2,但在任何版本(12.2.12 或 12.2.4)上都不起作用我使用的是 ubuntu 18.04.3。

#include "/usr/include/cephfs/libcephfs.h"
#include <stdlib.h>
#include <stdio.h>

int main (int argc, const char* argv[]){

    struct ceph_mount_info *cmount;

    const char id[] = "client.admin";

    int err = ceph_create(&cmount, id);

    printf("%d", err);

    return 0;
}

$ g++ -o 示例 example.c -lcephfs

/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `AdminSocket::unregister_command(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `ceph_clock_now()'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `AdminSocket::register_command(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, AdminSocketHook*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `PerfCountersBuilder::add_u64_counter(int, char const*, char const*, char const*, int)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `md_config_t::set_val(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*, bool, std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >*)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `CrushWrapper::get_full_location_ordered(int, std::vector<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `PerfCounters::tinc(int, utime_t, unsigned int)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `md_config_t::parse_env()'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `md_config_t::parse_argv(std::vector<char const*, std::allocator<char const*> >&)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `ceph::Formatter::create(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `PerfCounters::tinc(int, std::chrono::duration<unsigned long, std::ratio<1l, 1000000000l> >, unsigned int)'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcephfs.so: undefined reference to `FSMap::parse_role(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, mds_role_t*, std::ostream&) const'
collect2: error: ld returned 1 exit status
4

2 回答 2

1
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#define _FILE_OFFSET_BITS 64

#include <cephfs/libcephfs.h>
#include <stdlib.h>
#include <stdio.h>

int main (int argc, const char* argv[]){

    struct ceph_mount_info *cmount;

    const char id[] = "client.admin";

    int err = ceph_create(&cmount, id);

    printf("%d", err);

    return 0;
}

此代码使用 GCC 7 编译器在 Ubuntu 18.04 上为我编译。我用来编译的命令是:

g++ -o example example.c -lcephfs

事实上,即使您的源代码也可以在我的系统上使用我使用的添加的#defines 进行编译。

于 2019-10-15T14:59:19.983 回答
-1

有效 !在升级我的 ubuntu 版本(从 16.04 到 18.04)之前,我已经安装了 librados。现在,我重新安装 librados 和 libcephfs。它成功地工作了。

于 2019-10-16T12:31:53.270 回答