在构建收集的性能监视包时链接到mongo-c-driver库时出错

时间:2014-06-23 20:46:31

标签: c compilation collectd mongo-c-driver

我正在尝试构建collectd系统性能监视包(版本5.4.1;在Fedora v20 VM上构建collectd)并希望使用write_mongodb插件。

我在collectd-5.4.1文件夹中运行./configure我已经下载了包源文件但由于以下错误而无法获得write_mongodb支持(如collectd文件夹的config.log文件中所示):< / p>

/home/user01/Documents/libs/collectd-5.4.1/conftest.c:181: undefined reference to 'mongo_run_command'

我正在尝试链接到mongo-c-driver库,我以前编译它来生成libmongoc-1.0.so.0.0.0(版本0.96.4)。

我在脚本configure中进行了以下修改,以链接到libmongoc:

LIBMONGOC_CPPFLAGS="$LIBMONGOC_CPPFLAGS -I/usr/local/include/libmongoc-1.0/ -I/usr/local/include/libbson-1.0/" 
LIBMONGOC_LDFLAGS="$LIBMONGOC_LDFLAGS -L/usr/local/lib/ -L/usr/local/lib/"

并将文件mongoc.h复制到/usr/local/include/libmongoc-1.0/mongo.h

文件夹中

以下是collectd文件夹中配置脚本config.log输出的片段,其中包含与mongo_run_command相关的错误。

configure:21551: libmongoc CPPFLAGS:  -I/usr/local/include/libmongoc-1.0/ -I/usr/local/include/libbson-1.0/
configure:21556: checking for mongo.h
configure:21556: gcc -c -g -O2   -I/usr/local/include/libmongoc-1.0/ -I/usr/local/include/libbson-1.0/ conftest.c >&5
configure:21556: $? = 0
configure:21556: result: yes
configure:21579: libmongoc LDFLAGS:  -L/usr/local/lib/ -L/usr/local/lib/
configure:21582: checking for mongo_run_command in -lmongoc
configure:21607: gcc -o conftest -g -O2   -I/usr/local/include/libmongoc-1.0/ -I/usr/local/include/libbson-1.0/   -L/usr/local/lib/ -L/usr/local/lib/ conftest.c -lmongoc  -ldl  >&5
/tmp/ccyc9VGB.o: In function 'main':
/home/user01/Documents/libs/collectd-5.4.1/conftest.c:181: undefined reference to 'mongo_run_command'
collect2: error: ld returned 1 exit status
configure:21607: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "collectd"
| #define PACKAGE_TARNAME "collectd"
| #define PACKAGE_VERSION "5.4.1"
| #define PACKAGE_STRING "collectd 5.4.1"
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| #define STDC_HEADERS 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_DLFCN_H 1
| #define LT_OBJDIR ".libs/"
| #define LT_MODULE_EXT ".so"
| #define LT_MODULE_PATH_VAR "LD_LIBRARY_PATH"
| #define LT_DLSEARCH_PATH "/lib:/usr/lib:/usr/lib64/dyninst:/usr/lib64/iscsi:/usr/lib64/llvm:/usr/local/lib/usr/lib64/tracker-0.16:/usr/lib64/xulrunner:/usr/local/lib"
| #define HAVE_LIBDL 1
| #define HAVE_DLERROR 1
| #define HAVE_LIBDLLOADER 1
| #define HAVE_ARGZ_H 1
| #define HAVE_ERROR_T 1
| #define HAVE_ARGZ_ADD 1
| #define HAVE_ARGZ_APPEND 1
| #define HAVE_ARGZ_COUNT 1
| #define HAVE_ARGZ_CREATE_SEP 1
| #define HAVE_ARGZ_INSERT 1
| #define HAVE_ARGZ_NEXT 1
| #define HAVE_ARGZ_STRINGIFY 1
| #define HAVE_WORKING_ARGZ 1
| #define HAVE_PRELOADED_SYMBOLS 1
| #define HAVE_UNISTD_H 1
| #define HAVE_DIRENT_H 1
| #define HAVE_CLOSEDIR 1
| #define HAVE_OPENDIR 1
| #define HAVE_READDIR 1
| #define LT_LIBEXT "a"
| #define LT_LIBPREFIX "lib"
| #define LIBTOOL_VERSION 2
| #define PACKAGE "collectd"
| #define VERSION "5.4.1"
| #define KERNEL_LINUX 1
| #define STDC_HEADERS 1
| #define HAVE_SYS_WAIT_H 1
| #define HAVE_DIRENT_H 1
| #define HAVE__BOOL 1
| #define HAVE_STDBOOL_H 1
| #define HAVE_STDIO_H 1
| #define HAVE_ERRNO_H 1
| #define HAVE_MATH_H 1
| #define HAVE_STDARG_H 1
| #define HAVE_SYSLOG_H 1
| #define HAVE_FCNTL_H 1
| #define HAVE_SIGNAL_H 1
| #define HAVE_ASSERT_H 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_SOCKET_H 1
| #define HAVE_SYS_SELECT_H 1
| #define HAVE_POLL_H 1
| #define HAVE_NETDB_H 1
| #define HAVE_ARPA_INET_H 1
| #define HAVE_SYS_RESOURCE_H 1
| #define HAVE_SYS_PARAM_H 1
| #define HAVE_REGEX_H 1
| #define HAVE_SYS_IOCTL_H 1
| #define HAVE_ENDIAN_H 1
| #define HAVE_FNMATCH_H 1
| #define HAVE_LIBGEN_H 1
| #define HAVE_NETINET_IN_SYSTM_H 1
| #define HAVE_NETINET_IN_H 1
| #define HAVE_NETINET_IP_H 1
| #define HAVE_NETINET_IP_ICMP_H 1
| #define HAVE_NETINET_IP6_H 1
| #define HAVE_NETINET_ICMP6_H 1
| #define HAVE_NETINET_TCP_H 1
| #define HAVE_NETINET_UDP_H 1
| #define HAVE_SYS_SYSCTL_H 1
| #define HAVE_LINUX_MAJOR_H 1
| #define HAVE_LINUX_RAID_MD_U_H 1
| #define HAVE_LINUX_WIRELESS_H 1
| #define HAVE_SYS_SWAP_H 1
| #define HAVE_UTMP_H 1
| #define HAVE_UTMPX_H 1
| #define HAVE_IFADDRS_H 1
| #define HAVE_NET_IF_H 1
| #define HAVE_LINUX_IF_H 1
| #define HAVE_LINUX_NETDEVICE_H 1
| #define HAVE_LINUX_SOCKIOS_H 1
| #define HAVE_LINUX_ETHTOOL_H 1
| #define HAVE_LINUX_IP_VS_H 1
| #define HAVE_SYS_MOUNT_H 1
| #define HAVE_LINUX_UN_H 1
| #define HAVE_PWD_H 1
| #define HAVE_GRP_H 1
| #define HAVE_SYS_UN_H 1
| #define HAVE_CTYPE_H 1
| #define HAVE_LIMITS_H 1
| #define HAVE_PATHS_H 1
| #define HAVE_MNTENT_H 1
| #define HAVE_SYS_STATFS_H 1
| #define HAVE_SYS_STATVFS_H 1
| #define HAVE_SYS_VFS_H 1
| #define HAVE_WORDEXP_H 1
| #define HAVE_ARPA_NAMESER_H 1
| #define HAVE_ARPA_NAMESER_COMPAT_H 1
| #define HAVE_NET_IF_ARP_H 1
| #define HAVE_NET_PPP_DEFS_H 1
| #define HAVE_NET_IF_PPP_H 1
| #define HAVE_NETINET_IF_ETHER_H 1
| #define HAVE_TERMIOS_H 1
| #define TIME_WITH_SYS_TIME 1
| #define HAVE_GETTIMEOFDAY 1
| #define HAVE_SELECT 1
| #define HAVE_STRDUP 1
| #define HAVE_STRTOL 1
| #define HAVE_GETADDRINFO 1
| #define HAVE_GETNAMEINFO 1
| #define HAVE_STRCHR 1
| #define HAVE_MEMCPY 1
| #define HAVE_STRSTR 1
| #define HAVE_STRCMP 1
| #define HAVE_STRNCMP 1
| #define HAVE_STRNCPY 1
| #define HAVE_STRLEN 1
| #define HAVE_STRNCASECMP 1
| #define HAVE_STRCASECMP 1
| #define HAVE_OPENLOG 1
| #define HAVE_CLOSELOG 1
| #define HAVE_SYSCONF 1
| #define HAVE_SETENV 1
| #define HAVE_IF_INDEXTONAME 1
| #define HAVE_DECL_STRERROR_R 1
| #define HAVE_STRERROR_R 1
| #define HAVE_GETPWNAM_R 1
| #define HAVE_GETGRNAM_R 1
| #define HAVE_SETGROUPS 1
| #define HAVE_REGCOMP 1
| #define HAVE_REGERROR 1
| #define HAVE_REGEXEC 1
| #define HAVE_REGFREE 1
| #define HAVE_SOCKET 1
| #define HAVE_CLOCK_GETTIME 1
| #define HAVE_CLOCK_GETTIME 1
| #define HAVE_NANOSLEEP 1
| #define HAVE_SYSCTL 1
| #define HAVE_STATFS 1
| #define HAVE_STATVFS 1
| #define HAVE_GETIFADDRS 1
| #define HAVE_GETLOADAVG 1
| #define HAVE_SYSLOG 1
| #define HAVE_GETUTENT 1
| #define HAVE_GETUTXENT 1
| #define HAVE_STRPTIME 1
| #define STRPTIME_NEEDS_STANDARDS 1
| #define NAN_STATIC_DEFAULT 1
| #define FP_LAYOUT_NEED_NOTHING 1
| #define HAVE_GETMNTENT 1
| #define HAVE_ONE_GETMNTENT 1
| #define HAVE_STRUCT_IP_MREQN_IMR_IFINDEX 1
| #define HAVE_STRUCT_UDPHDR_UH_DPORT 1
| #define HAVE_STRUCT_UDPHDR_UH_SPORT 1
| #define COLLECT_LIBESMTP 0
| #define HAVE_MONGO_H 1
| /* end confdefs.h.  */
| 
| /* Override any GCC internal prototype to avoid an error.
|    Use char because int might match the return type of a GCC
|    builtin and then its argument prototype would still apply.  */
| #ifdef __cplusplus
| extern "C"
| #endif
| char mongo_run_command ();
| int
| main ()
| {
| return mongo_run_command ();
|   ;
|   return 0;
| }
configure:21616: result: no

我在文件夹mongo-c-driver-0.96.4中的文件中找不到函数mongo_run_command

mongo-c-driver-0.96.4/src/mongoc/.*
mongo-c-driver-0.96.4/src/libmongoc.symbols

感谢。

1 个答案:

答案 0 :(得分:1)

以下步骤修复了在为collectd系统性​​能监视包构建Write MongoDB插件支持时遇到的问题。

编译Mongo-C-Driver并收集

需要以下步骤和代码更新来构建和使用collectd中的write_mongodb插件,以将系统性能数据直接发送到MongoDB数据库。

  • 将collectd-5.4.1下载到比如说

    • COLLECTD_DIR=/home/user01/libs/collectd-5.4.1

    不要编译/构建collectd,但

  • 从GitHub下载mongo-c-driver版本0.8.1。最新版本的mongo-c-driver与collectd版本5.4.1

  • 不兼容
  • 将Mongo 0.8.1构建到文件夹:    MONGOC_DIR=/home/user01/libs/mongo-c-driver-0.8.1

  • 将库libbson.so和libmongoc.so从MONGOC_DIR复制到/usr/local/lib/usr/local/lib64

  • 将libmongoc.so库复制到以下位置: sudo cp /usr/local/lib/libmongoc.so /lib64/libmongoc.so.0.8 sudo cp /usr/local/lib/libmongoc.so /lib/libmongoc.so.0.8

  • 将.h标题文件从文件夹MONGOC_DIR/src复制到/usr/local/include

  • 转到COLLECTD_DIR并对配置脚本进行以下更改

    // Comment the lines with -I$withval/include and -I$withval/lib and replace them with following // Before > LIBMONGOC_CPPFLAGS="$LIBMONGOC_CPPFLAGS -I$withval/include" LIBMONGOC_LDFLAGS="$LIBMONGOC_LDFLAGS -L$withval/lib" // After > LIBMONGOC_CPPFLAGS="$LIBMONGOC_CPPFLAGS -I/usr/local/include/" LIBMONGOC_LDFLAGS="$LIBMONGOC_LDFLAGS -L/usr/local/lib/"

  • 运行脚本./configure

  • 对文件COLLECTD_DIR / src / write_mongodb.c进行以下更改;本期提到了这些变化。
    • bson_create更改为bson_alloc
    • bson_dispose更改为bson_dealloc
  • 编译collectd:运行sudo make clean然后sudo make重新编译collectd。
  • 通过运行sudo make install
  • 收集安装

使用MongoDB运行收集和测试

  • 启动MongoDB服务器
  • 运行已收集:/opt/collectd/sbin/collectd
  • 启动mongo服务器
  • 在mongo会话中运行以下命令以检查与collectd的连接 show dbs use collectd db.getCollectionNames() db.load.find().sort({x:1}).limit(3).pretty()