【问题标题】:Linking (or proper installation and linking) of jpeg-8d libraryjpeg-8d库的链接(或正确安装和链接)
【发布时间】:2012-10-28 19:35:33
【问题描述】:

我的项目需要 JPEG 处理能力,所以我决定使用 jpeg-8d 库,下载包后,我通常使用./configure; make and make installmake test 没有返回任何错误,整个过程也没有报告任何问题,但是当我在 Code Blocks 10.05 中打开 example.c 时编译失败。我已经“搜索”了一些解决方案并添加了

#ifdef __cplusplus
extern "C" {
#endif
...
#ifdef __cplusplus
}
#endif

jpeglib.h 文件中,重新编译,然后将这些行添加到代码块的链接器部分: /usr/local/lib/libjpeg.a /usr/local/lib/libjpeg.so 还根据目录添加到目录部分。 但是编译器仍然无法编译example.c,以下是一些错误:

> /home/raff/CodeBlocks/jpeg-8d/example.c|116|warning: incompatible implicit declaration of built-in function ‘exit’|
> example.c|| undefined reference to 'image_width'
> example.c|| undefined reference to 'image_height'

如果有人成功安装和使用 jpeg 库请帮忙,我在切换 IDE 和/或 linux 发行版时没有问题。

【问题讨论】:

    标签: c++ jpeg static-libraries codeblocks libjpeg


    【解决方案1】:

    您的库安装似乎没问题(否则它会在编译期间抱怨缺少jpeglib.h

    文件example.c 应该是文档的一部分,而不是您可以编译和使用的代码。请注意,例如,没有main()。您应该将其作为参考,了解如何编写压缩和解压缩 jpeg 文件的方法。

    变量image_widthimage_height(和image_buffer)被声明为extern,因此假定它们是在其他文件中定义的。您可以编写程序来定义这些变量并填充缓冲区,然后才能使用提供的方法(write_JPEG_fileread_JPEG_file)。

    【讨论】:

      【解决方案2】:
      1. 您是在链接静态库还是共享库?
      2. 如果它是静态的,您是否将它放在链接器命令行中的目标文件之后?
      3. 如果它是共享的,并且您使用的是较新的工具链,这也可能是问题所在。
      4. 如果链接正确,那么 readelf -s 会在共享库上显示什么? nm 在静态库上显示什么?

      【讨论】:

        【解决方案3】:

        我非常确定 example.c 实际上是使用这个库的一个例子,所以我没有检查它的内容。此外还有一些问题。 编写正确的程序后,我遇到了一个错误:

        error while loading shared libraries libjpeg.so.8: cannot open shared object file: No such file or directory
        

        但这对 shell 命令已经解决了:

        ranlib /usr/local/lib/libjpeg.a
        ldconfig /usr/local/lib
        

        希望这会有所帮助。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2023-01-24
          • 1970-01-01
          • 2011-05-28
          • 1970-01-01
          • 2013-08-04
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多