C++ libPNG - 简单的初始化错误

标签 c++ macos clang libpng

我在尝试编译时遇到以下错误....

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/

相关文章:

macos - 获取 Mac 上的 'Friendly interface names' 列表(机场、以太网等)

c++ - 为什么不能在 c++0x 模式下使用 libc++ 连接这个 boost::program_options 示例?

c++ - 实际使用捕获时未使用的 lambda 捕获警告

javascript - Mousemove 回调事件不显示按下哪个鼠标按钮 safari

ios - 如何让我的 Realm 文件显示在 MAC 上的 Realm 浏览器中?

c++ - 为什么clang不能启用所有的 sanitizer ?

c# - 针对 C++ 和 C# 的代码生成工具

c++ - 了解 Valgrind 输出

c++ - 为什么不能在 C++ 模板参数中定义新类型?

c++ - 删除tensorflow层