C/C++混合编程时爬过的坑(我的项目是vs2015写的,调ocr的代码进行编译,ocr这东西有点老,所以找的库都是.c的源文件)!

1.首先把单个的.c文件全部设置成不使用预编译头(坑一)。

2.然后编译一下,提示GifFilePrivateType 未声明的标识(坑二),找到源文件里的定义声明:

typedef struct GifFilePrivateType {
    GifWord FileState, FileHandle,  /* Where all this data goes to! */
      BitsPerPixel,     /* Bits per pixel (Codes uses at least this + 1). */
      ClearCode,   /* The CLEAR LZ code. */
      EOFCode,     /* The EOF LZ code. */
      RunningCode, /* The next code algorithm can generate. */
      RunningBits, /* The number of bits required to represent RunningCode. */
      MaxCode1,    /* 1 bigger than max. possible code, in RunningBits bits. */
      LastCode,    /* The code before the current code. */
      CrntCode,    /* Current algorithm code. */
      StackPtr,    /* For character stack (see below). */
      CrntShiftState;    /* Number of bits in CrntShiftDWord. */
    unsigned long CrntShiftDWord;   /* For bytes decomposition into codes. */
    unsigned long PixelCount;   /* Number of pixels in image. */
    FILE *File;    /* File as stream. */
    InputFunc Read;     /* function to read gif input (TVT) */
    OutputFunc Write;   /* function to write gif output (MRB) */
    GifByteType Buf[256];   /* Compressed input is buffered here. */
    GifByteType Stack[LZ_MAX_CODE]; /* Decoded pixels are stacked here. */
    GifByteType Suffix[LZ_MAX_CODE + 1];    /* So we can trace the codes. */
    GifPrefixType Prefix[LZ_MAX_CODE + 1];
    GifHashTableType *HashTable;
} GifFilePrivateType;

3.检查下发现这个文件头文件已经包含进去了,然后以为是C和C++ 结构体养发差异导致的,结果也没发现什么问题,然后把结构体里面的东西全删掉,编译通过,说明在结构体里定义的成员有没定义的,控制变量法最后发现只要有GifHashTableType *HashTable;就提示未声明标识的错误。

4.找到这个结构体的定义:

typedef struct GifHashTableType {
    UINT32 HTable[HT_SIZE];
} GifHashTableType;

这个地方没定义。

5.知道了问题所在就好办了,前面加上typedef unsigned __int32 UINT32;坑二搞定!

6.    然后      FileHandle = open(FileName, O_WRONLY | O_CREAT | O_EXCL(坑三
#if defined(__MSDOS__) || defined(WINDOWS32) || defined(_OPEN_BINARY)
                          | O_BINARY
#endif /* __MSDOS__ */
                          , S_IREAD | S_IWRITE);

又是未定义标识,这次真的有点慌,这好像是linux里面的东西,最后把代码注释掉,然后用windows的方法写一遍。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值