简单的问题,我添加了一个第三方库,它是用C语言完成的,我的C ++项目。无论出于何种原因,它都会导致LINK2019错误,包含C文件附带的标头并定义所有内容。但是每次我尝试使用任何函数时,编译器都会翻转。
main.cpp,创建一个const char指针并传递给初始化器:
const char * testTexture = "test_png.png";
graphicsTextureAsset * textureAsset1 = new graphicsTextureAsset(1, testTexture);
some_class.cpp,初始化程序调用该函数将指针传递给它:
#include "graphicsAllLibs.h"
graphicsTextureAsset::graphicsTextureAsset(int textureAssetID, const char * fileNameAddr)
{
this->readFilePNG(fileNameAddr);
}
void graphicsTextureAsset::readFilePNG(const char * fileNameAddr)
{
int errorVal = 0;
this->textureBuffer = upng_new_from_file(fileNameAddr);
}
graphicsAllLibs.h包含所有标题,包括包含函数的标题,它从不会导致其他库出现问题。
消息是:
1>graphicsTextureAsset.obj : error LNK2019: unresolved external symbol upng_new_from_file referenced in function "public: void __cdecl graphicsTextureAsset::readFilePNG(char const *)" (?readFilePNG@graphicsTextureAsset@@QEAAXPEBD@Z)
1>graphicsTextureAsset.obj : error LNK2019: unresolved external symbol upng_free referenced in function "public: __cdecl graphicsTextureAsset::~graphicsTextureAsset(void)" (??1graphicsTextureAsset@@QEAA@XZ)
C函数描述为:
upng_t* upng_new_from_bytes (const unsigned char* buffer, unsigned long size); // the header
upng_t* upng_new_from_file(const char *filename)
{
upng_t* upng;
unsigned char *buffer;
FILE *file;
long size;
upng = upng_new();
if (upng == NULL) {
return NULL;
}
file = fopen(filename, "rb");
if (file == NULL) {
SET_ERROR(upng, UPNG_ENOTFOUND);
return upng;
}
/* get filesize */
fseek(file, 0, SEEK_END);
size = ftell(file);
rewind(file);
/* read contents of the file into the vector */
buffer = (unsigned char *)malloc((unsigned long)size);
if (buffer == NULL) {
fclose(file);
SET_ERROR(upng, UPNG_ENOMEM);
return upng;
}
fread(buffer, 1, (unsigned long)size, file);
fclose(file);
/* set the read buffer as our source buffer, with owning flag set */
upng->source.buffer = buffer;
upng->source.size = size;
upng->source.owning = 1;
return upng;
}
有什么想法?为了使用我的程序,是否需要对C头/文件进行任何更改?任何编译器都会改变吗?
编辑:我正在使用Visual Studio 2015.I修改了C函数的标题:
#ifdef __cplusplus
extern "C" {
#endif
stuff here
#ifdef __cplusplus
}
#endif
!!!已解决:解决方案是强制.c文件编译为c ++文件。否则它会崩溃并烧伤。