Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ CImg没有';无法识别png/jpeg macOS_C++_Macos_Cimg - Fatal编程技术网

C++ CImg没有';无法识别png/jpeg macOS

C++ CImg没有';无法识别png/jpeg macOS,c++,macos,cimg,C++,Macos,Cimg,我是新用户,CImg我已经使用brew安装CImg安装了CImg,然后我安装了XQuartz。当我试图在终端中运行此程序时,我收到以下错误: 代码: #包括 #包括“CImg.h” 使用名称空间cimg_库; 使用名称空间std; int main(){ CImg A(“img.png”); A.显示(); 返回0; } 错误: [CImg] *** CImgIOException *** [instance(0,0,0,0,0x0,non-shared)] CImg<unsigned

我是新用户,CImg我已经使用
brew安装CImg
安装了CImg,然后我安装了XQuartz。当我试图在终端中运行此程序时,我收到以下错误:

代码:

#包括
#包括“CImg.h”
使用名称空间cimg_库;
使用名称空间std;
int main(){
CImg A(“img.png”);
A.显示();
返回0;
}
错误:

[CImg] *** CImgIOException *** [instance(0,0,0,0,0x0,non-shared)] CImg<unsigned char>::load(): Failed to recognize format of file 'img.png'.
libc++abi.dylib: terminating with uncaught exception of type cimg_library::CImgIOException: [instance(0,0,0,0,0x0,non-shared)] CImg<unsigned char>::load(): Failed to recognize format of file 'img.png'.
[CImg]***CImgIOException***[实例(0,0,0,0,0x0,非共享)]CImg::load():无法识别文件“img.png”的格式。
libc++abi.dylib:以类型为cimg_library::CImgIOException:[实例(0,0,0,0,0x0,非共享)]的未捕获异常终止cimg::load():无法识别文件“img.png”的格式。
当我试着用
运行相同的代码时,定义cimg\u在
上使用png 1
,包括“cimg.h”
我得到链接器错误

解决方案: 这是编译文件的正确方法
g++-std=c++11 main.cpp-o main-I/opt/X11/include-L/opt/X11/lib-lX11-ljpeg-lpng-lz

而且应该有
#define cimg_use_png 1

面向Visual Studio,但基本上如果要加载jpg或png,需要与适当的库链接。这可能对Mac电脑有所帮助@退休的印第安解决了这个问题,谢谢。面向VisualStudio,但基本上,如果要加载jpg或png,则需要链接到适当的库。这可能对Mac电脑有所帮助@退休的印第安解决了这个问题,谢谢。
[CImg] *** CImgIOException *** [instance(0,0,0,0,0x0,non-shared)] CImg<unsigned char>::load(): Failed to recognize format of file 'img.png'.
libc++abi.dylib: terminating with uncaught exception of type cimg_library::CImgIOException: [instance(0,0,0,0,0x0,non-shared)] CImg<unsigned char>::load(): Failed to recognize format of file 'img.png'.