作为 C++ 的新手,我并不完全理解这种链接和其他东西。
我认为这是关于 extern "C"
链接。
extern "C"
{
int loadbmp(char *filename, unsigned char **buf,
int *w, int *h, int pf, int bottomup);
const char *bmpgeterr(void);
}
unsigned char *srcBuf=NULL, **jpegBuf=NULL;
unsigned long jpegsize=0;
int width, height;
char *filename={"Screenshot158139.bmp"};
tjhandle handle=NULL;
void main(){
if(loadbmp(filename, &srcBuf, &width, &height,TJPF_RGB, 0)==-1){
//printf("Could not load bitmap: %s\n", bmpgeterr());
exit(1);
}
if((handle=tjInitCompress())==NULL) {
printf("Could not initialize compressor: %s\n", tjGetErrorStr());
free(srcBuf);
exit(1);
}
if((tjCompress2(handle, srcBuf, width, 0, height, TJPF_RGB,
jpegBuf, &jpegsize, TJSAMP_444,10, 0))==-1) {
printf("Could not compress: %s\n", tjGetErrorStr());
free(&srcBuf);
tjDestroy(handle);
exit(1);
}
}
我从中得到的问题是我需要解析我认为的 extern "C"
代码:
error LNK2001: unresolved external symbol loadbmp
遗憾的是,我不知道该怎么做,并且由于此错误在 C++ 世界中极为常见,因此找到答案并不容易,因为它们可能有所不同。
希望解决这个问题很容易,因为我想我必须将它定义为外部代码。
最佳答案
您似乎已经声明了 loadbmp()
但您还没有定义它。函数在哪里定义的?如果它应该来自一个库,不要自己声明这个函数,而是包含相关的头文件。该函数的文档应该告诉您哪个是相关的 header ,并且应该提到您可能需要包含哪些额外的库。
如果 loadbmp()
不是您想从库中获取的函数,则需要定义(实现)它。
关于c++ - 未解析的外部和外部 "C"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18175279/