鉴于您提供的输出,正如@gcbenison 所说,链接器似乎没有找到 libtiff。
此外,鉴于它显示了两行输出,我假设您的 libtiff 库位于“E:\Image Transforms\Libraries\tifflib\libs\libtiff”内,对吧?
好吧,Code::Blocks doesn't seem to like 带有空格的路径。因此尝试将“Image Transforms”重命名为“Image_Transforms”,更正 Code::Blocks 中的库路径,然后重试。
编辑:详细说明答案
另外,请确保您可以拥有已编译的 libtiff 库。我从GNUwin32 项目中下载了libtiff 3.8.2-1.exe 进行测试,它运行良好。尝试执行以下操作来构建使用 libtiff 的最小工作程序:
- 在 C:\GnuWin32 中安装上述 libtiff 库。安装后,里面会有很多目录,包括bin、contrib、doc、include、lib等;
- 在 Code::Blocks 中创建一个新的控制台应用程序项目;
- 告诉 Code::Blocks 它是一个 C 程序;
- 创建项目后,通过单击您的项目,然后单击“构建选项...”访问“构建选项”对话框;
- 在“链接器设置”选项卡的“链接库”框架中,单击“添加”并添加 libtiff.dll.a。如果你在 C:\GnuWin32 中安装了 libtiff,你想要的库是 C:\GnuWin32\lib\libtiff.dll.a;
- 在“搜索目录”选项卡中,您将:
- 选择“编译器”选项卡并在其中添加“C:\GnuWin32\include”;
- 选择“链接器”选项卡并在其中添加“C:\GnuWin32\lib”;
- 在“构建选项”对话框中单击“确定”,现在一切都应该没问题了。
您现在可以尝试构建您的程序,看看构建是否成功。我用Graphics programming with libtiff, Part 2中的第一个例子作为测试程序:
#include <stdio.h>
#include <stdlib.h>
#include <tiffio.h>
int main()
{
TIFF *output;
uint32 width, height;
char *raster;
printf("Trying to write TIFF...\n");
if((output = TIFFOpen("output.tif", "w")) == NULL){
fprintf(stderr, "Could not open outgoing image\n");
exit(42);
}
width = 42;
height = 42;
if((raster = (char *) malloc(sizeof(char) * width * height * 3)) == NULL){
fprintf(stderr, "Could not allocate enough memory\n");
exit(42);
}
TIFFSetField(output, TIFFTAG_IMAGEWIDTH, width);
TIFFSetField(output, TIFFTAG_IMAGELENGTH, height);
TIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);
TIFFSetField(output, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField(output, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
TIFFSetField(output, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(output, TIFFTAG_SAMPLESPERPIXEL, 3);
if(TIFFWriteEncodedStrip(output, 0, raster, width * height * 3) == 0){
fprintf(stderr, "Could not write image\n");
exit(42);
}
TIFFClose(output);
printf("TIFF written successfully.\n");
return 0;
}
现在尝试构建 (Ctrl+F9) 并运行您的程序。我按照上面提到的步骤,编译并运行了我的程序。
对于构建,Code::Blocks 的输出是(我将我的程序命名为 libtiff):
-------------- Build: Debug in libtiff ---------------
Compiling: main.c
Linking console executable: bin\Debug\libtiff.exe
Output size is 27,93 KB
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings
为了运行,它输出:
Trying to write TIFF...
TIFF written successfully.
Process returned 0 (0x0) execution time : 0.125 s
Press any key to continue.