gcc - 编译期间出现“libcephfs.so:undefined reference to 'blablabla'”错误。如何解决这个问题?
问题描述
我有一个 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
解决方案
#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 进行编译。
推荐阅读
- python - 从python中的内置未知字符替换字符串
- ruby-on-rails - Rails 活动记录中的委托
- java - 回复 kafka 模板连接标头(CorrelationId)未发送到 Google pub sub
- r - 如何使用 ggplot2 R 在同一级别制作时间序列线和直方图?
- python - 在熊猫数据框中拆分一列不删除 na
- javascript - 在 iOS 上调用“fetch”时出现 Javascript“TypeError:cancelled”错误
- ruby-on-rails - Adding font awesome icon dynamically causes page to scroll to top
- c - 为什么 printf("%s\n", "123456789" + 3); //输出:“456789”
- c++ - QT,我做了无模式对话框,现在我想通过单击一个按钮来关闭所有对话框
- html - Windows 10 - HTTP 错误 500.19 - 内部服务器错误