通过xcode编译我的代码在OSX中使用mongodb c驱动程序

compiling my code to use mongodb c driver in OSX via xcode

本文关键字:mongodb 驱动程序 OSX 编译 xcode 我的 代码 通过      更新时间:2023-10-16

我试图在OSX(10.9.5)上做一个C应用程序,它将连接到mongodb并执行CRUD操作。我正在使用从https://github.com/mongodb/mongo-c-driver/releases/tag/1.3.5下载的1.3.5版本我成功地在我的系统上安装了mongo。我正在制作我的应用程序,它将使用库来执行CRUD操作。我使用Xcode 6.1.1作为我的IDEon osx。我已经为ide中的头文件提供了适当的路径,并且在运行之前没有警告或错误。我已经给出了动态库的搜索路径,所以我认为链接也应该发生得很好。但是,当我尝试运行时,我得到以下错误:

架构的未定义符号x86_64:

"_bson_as_json",引用自:

  _main in find.o   "_bson_destroy", referenced from:
  _main in find.o   "_bson_free", referenced from:
  _main in find.o   "_bson_new", referenced from:
  _main in find.o   "_mongoc_cleanup", referenced from:
  _main in find.o   "_mongoc_client_destroy", referenced from:
  _main in find.o   "_mongoc_client_get_collection", referenced from:
  _main in find.o   "_mongoc_client_new", referenced from:
  _main in find.o   "_mongoc_collection_destroy", referenced from:
  _main in find.o   "_mongoc_collection_find", referenced from:
  _main in find.o   "_mongoc_cursor_destroy", referenced from:
  _main in find.o   "_mongoc_cursor_next", referenced from:
  _main in find.o   "_mongoc_init", referenced from:
  _main in find.o ld: symbol(s) not found for architecture x86_64 clang:error: linker command failed with exit code 1 (use -v to see invocation)

我哪里错了?

看起来您已经为libmongoc-1.0指定了动态库路径。但不是它所依赖的库libson -1.0. So。这两个库都是在您构建驱动程序时安装的,因此您应该能够指定一个额外的路径,并且您的程序将正确链接。