进程以状态1终止

时间:2012-05-29 21:38:47

标签: c++ c codeblocks

我正在编写代码:: blocks 10.05,我想用c / c ++读取TIFF图像文件。为此,我使用LibTiff库,因此我将tiffio.h作为头文件包含在内。现在当我编译时,我得到一个错误“进程以状态1终止。而且我还给了链接器库的完整路径。

整个构建日志说:

链接控制台可执行文件:bin \ Release \ tifff.exe

mingw32-g ++。exe:E:\ Image:没有这样的文件或目录

mingw32-g ++。exe:Transforms \ Libraries \ tifflib \ libs \ libtiff:没有这样的文件或目录

进程终止,状态为1(0分8秒) 0错误,0警告

1 个答案:

答案 0 :(得分:2)

鉴于您提供的输出,看起来链接器,如@gcbenison所说,并没有找到libtiff。

更重要的是,鉴于它显示了两行输出,我想你的libtiff库位于“E:\ Image Transforms \ Libraries \ tifflib \ libs \ libtiff”里面,对吗?

好吧,Code ::阻止doesn't seem to like个带空格的路径。因此,尝试将“Image Transforms”重命名为“Image_Transforms”,更正Code :: Blocks中的库路径,然后重试。

编辑:详细阐述了答案

另外,请确保您可以拥有已编译的libtiff库。我从libtiff 3.8.2-1.exe项目中下载了GNUwin32进行测试,它运行得很完美。尝试执行以下操作以构建使用libtiff的最低工作程序:

  • 在C:\ GnuWin32中安装上述的libtiff库。安装之后,你将拥有许多目录,包括bin,contrib,doc,include,lib等;
  • 在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.