gpt4 book ai didi

linker - 由于使用 g++ 时共享库中可用的头文件导致的编译错误

转载 作者:行者123 更新时间:2023-12-04 05:53:21 25 4
gpt4 key购买 nike

我有一个/usr/lib/libtiff.so.3 作为/usr/lib/i386-linux-gnu/libtiff.so.4.3.3 的符号链接(symbolic link)。我需要使用在名为 tiffio.h 的文件中声明的一些数据结构,该文件是上述 tiff 库的一部分,以处理我的 c++ 源代码中的 .tif 图像文件。 c++源码mycode.cpp如下:

#include <iostream>
#include <tiffio.h>
using namespace std;

int main(int argc, char *argv[]) {

if (argc < 2) {
cout << "USAGE: mycode <inputimage> <outputimage> "<< endl;
return (-1);
}
return 0;
}

我通过以下方式使用 g++ 编译源代码:
g++ -Wall -L/usr/lib mycode.cpp -ltiff -o mycode

我收到以下错误:
fatal error: tiffio: No such file or directory. compilation terminated.

我尝试使用以下选项来包含 tiffio.h,但错误仍然存​​在。
<tiffio>, "tiffio.h",  extern "C" {"tiffio.h"} and extern "C" {<tiffio.h>}

我做错什么了吗?如何编译和链接源代码?

最佳答案

这取决于您的 tiffio.h 文件的位置。
如果它位于您的 g++ 通常查找头文件的地方,您可以使用它包含它

#include <tiffio.h>

如果它与 .cpp 文件位于同一目录中,则可以使用
#include "tiffio.h"

如果它在其他地方,您有两种可能性:

通过将 -I pathToLocation 添加到您的 g++ 调用,将其位置添加到您的搜索路径

或使用包含它
#include "pathToLocation/tiffio.h"

g++通常搜索的目录是
/usr/local/include
libdir/gcc/target/version/include
/usr/target/include
/usr/include

如果 g++ 找不到库本身(.so 文件),您可以将它(带路径)直接添加到您的 g++ 调用中。

关于linker - 由于使用 g++ 时共享库中可用的头文件导致的编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9813508/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com