我在尝试编译时遇到以下错误....
Undefined symbols for architecture x86_64: "_png_sig_cmp", referenced from: RenderUtils::isValidPng(std::istream&) in RenderUtils.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
我的代码如下:
//called from here
ifstream s;
s.open("/Users/tmg06qyu/Desktop/texture_512.png", ios::binary);
if(!RenderUtils::isValidPng(s)){
throw 20;
}
//header
class RenderUtils{
public:
static bool isValidPng(std::istream &source);
};
//implementation
#include <iostream>
#include "RenderUtils.h"
#include "png.h"
#define PNGSIGSIZE 8
using namespace std;
bool RenderUtils::isValidPng(std::istream &source){
//Allocate a buffer of 8 bytes, where we can put the file signature.
png_byte pngsig[PNGSIGSIZE];
int is_png = 0;
//Read the 8 bytes from the stream into the sig buffer.
source.read((char*)pngsig, PNGSIGSIZE);
//Check if the read worked...
if (!source.good()) return false;
//Let LibPNG check the sig. If this function returns 0, everything is OK.
is_png = png_sig_cmp(pngsig, 0, PNGSIGSIZE);
return (is_png == 0);
}
最佳答案
我的猜测是您构建了一个 32 位版本的 libpng,但现在您正试图将 64 位代码与其链接。尝试使用 file *
或 otool -L *
检查(从内存中)
关于C++ libPNG - 简单的初始化错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11670371/