我正在尝试使用以下命令从头文件中调用void process (uint8_t* I1,uint8_t* I2,float* D1,float* D2,const int32_t* dims);
int n=10;
size_t size=n*n*sizeof(uint8_t);
uint8_t* I1 = (uint8_t*)malloc(size);
uint8_t* I2 = (uint8_t*)malloc(size);
size=n*n*sizeof(float);
float* D1=(float*)malloc(size);
float* D2=(float*)malloc(size);
const int32_t dims[3] = {n,n,n};
process(I1,I2,D1,D2,dims);
但是当我在Linux上使用g ++进行编译时,收到消息undefined reference to process(unsigned char*, unsigned char*, float*, float*, int const*)
为什么会这样?
答案 0 :(得分:2)
,我得到消息未定义引用到进程(unsigned char *,unsigned char *,float *,float *,int const *)为什么会发生?
发生这种情况是因为链接器无法找到功能process(...)
的定义。如果此函数来自库,则意味着您未链接到包含此函数定义的库。
此外,uint8_t
只是gcc中unsigned char
的别名。
此外,如果您使用std::vector
格式的非常简单和安全的解决方案,则不应该手动管理内存。没有任何malloc
的代码:
size_t size = n * n;
std::vector <uint8_t> I1 (size);
std::vector <uint8_t> I2 (size);
std::vector <float> D1(size);
std::vector <float> D2(size);
const int32_t dims[3] = {n,n,n};
process(&I1[0], &I2[0], &D1[0], &D2[0], dims);
答案 1 :(得分:0)
uint8_t和无符号字符之间的混淆...为什么会发生这种情况?
仅因为uint8_t
是系统上unsigned char
的类型别名。这两个是同一类型。这是正常的。
未定义的过程引用...为什么会发生?
似乎您未能定义要调用的函数。
P.S。避免在C ++中使用malloc
。也要避免拥有裸露的指针。您的示例程序会泄漏内存。
还有什么更好的选择? (我是C ++的新手)
使用std::vector
。