Mongodb C驱动程序与我的程序
我从github.com下载了Mongodb-c-driver,并且编译它没有问题,但是,当我尝试编译我的c程序时,出现了以下问题:Mongodb C驱动程序与我的程序,c,mongodb,C,Mongodb,我从github.com下载了Mongodb-c-driver,并且编译它没有问题,但是,当我尝试编译我的c程序时,出现了以下问题: testmongo.c:(.text+0x20): undefined reference to 'mongo_client' testmongo.c:(.text+0x80): undefined reference to 'mongo_destroy' 我已经在ldconfig中链接了mongodb库,但是,这种情况没有改变 #include <std
testmongo.c:(.text+0x20): undefined reference to 'mongo_client'
testmongo.c:(.text+0x80): undefined reference to 'mongo_destroy'
我已经在ldconfig中链接了mongodb库,但是,这种情况没有改变
#include <stdio.h>
#include <mongo.h>
int main() {
mongo conn[1];
int status = mongo_client( conn, "127.0.0.1", 27017 );
if( status != MONGO_OK ) {
switch ( conn->err ) {
case MONGO_CONN_NO_SOCKET: printf( "no socket\n" ); return 1;
case MONGO_CONN_FAIL: printf( "connection failed\n" ); return 1;
case MONGO_CONN_NOT_MASTER: printf( "not master\n" ); return 1;
}
}
mongo_destroy( conn );
return 0;
}
有人能帮忙吗?
非常感谢 在提供更多信息之前,我想我应该将此作为答案提交。凭直觉,您可能缺少gcc命令中的-lmongoclient
gcc -o myprog -lmongoclient source.c
你用什么命令来编译它?非常感谢你的帮助!!!当我使用:gcc-omyprog-lmongocmysource.c编译时,它可以工作。但是,我是否可以只运行gcc-omyprog mysource.c来获得相同的结果??谢谢不,您需要告诉gcc要包含哪些库。您可以使用Makefile简化此过程: