linux c++ sds库 提示 undefined reference to `sdsempty()'

报错:
/tmp/cc3R3ayZ.o: In function 'main'
c.cpp:(.text+0x9): undefined reference to 'sdsempty()'
collect2: error: ld returned 1 exit status**

#include <iostream>
#include <unistd.h>
#include <sds.h>
using namespace std;

int main(){

    sds s= sdsempty();

    return 0;
}

我更新了sds文件,然后:

[root@localhost c4]# g++ -std=c++11 -o test -I/wgs/sds  c.cpp
In file included from c.cpp:3:0:
/wgs/sds/sds.h: In function ‘size_t sdsavail(sds)’:
/wgs/sds/sds.h:83:87: error: invalid conversion from ‘void*’ to ‘sdshdr8*’ [-fpermissive]
 #define SDS_HDR_VAR(T,s) struct sdshdr##T *sh = (void*)((s)-(sizeof(struct sdshdr##T)));
                                                                                       ^
/wgs/sds/sds.h:111:13: note: in expansion of macro ‘SDS_HDR_VAR’
             SDS_HDR_VAR(8,s);
             ^
/wgs/sds/sds.h:83:87: error: invalid conversion from ‘void*’ to ‘sdshdr16*’ [-fpermissive]
 #define SDS_HDR_VAR(T,s) struct sdshdr##T *sh = (void*)((s)-(sizeof(struct sdshdr##T)));
                                                                                       ^
/wgs/sds/sds.h:115:13: note: in expansion of macro ‘SDS_HDR_VAR’
             SDS_HDR_VAR(16,s);
             ^
/wgs/sds/sds.h:83:87: error: invalid conversion from ‘void*’ to ‘sdshdr32*’ [-fpermissive]
 #define SDS_HDR_VAR(T,s) struct sdshdr##T *sh = (void*)((s)-(sizeof(struct sdshdr##T)));
                                                                                       ^
/wgs/sds/sds.h:119:13: note: in expansion of macro ‘SDS_HDR_VAR’
             SDS_HDR_VAR(32,s);
             ^
/wgs/sds/sds.h:83:87: error: invalid conversion from ‘void*’ to ‘sdshdr64*’ [-fpermissive]
 #define SDS_HDR_VAR(T,s) struct sdshdr##T *sh = (void*)((s)-(sizeof(struct sdshdr##T)));
                                                                                       ^
/wgs/sds/sds.h:123:13: note: in expansion of macro ‘SDS_HDR_VAR’
             SDS_HDR_VAR(64,s);
             ^

这个是啥原因啊?

LucifeR_Shun
LucifeR_Shun 回复LucifeR_Shun: c++还需要多加#if defined(__cplusplus) extern "C" { #endif #include <sds.h> #if defined(__cplusplus) } #endif
7 个月之前 回复
LucifeR_Shun
LucifeR_Shun 去看了官方git 不支持c++ 而支持c 改动一下就行了,,而且有安装版了,,
7 个月之前 回复

1个回答

#include  <stdarg.h>  //加这个头文件试试,不知道刚刚为啥没显示

u010092517
裸奔的可比克 回复LucifeR_Shun: 感觉你是redis的依赖库没有安装,劝你先确认安装正确
7 个月之前 回复
LucifeR_Shun
LucifeR_Shun 还是不行 undefined reference to.....
7 个月之前 回复
LucifeR_Shun
LucifeR_Shun #include <sds.h> 加了啊
7 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐