即使“PKG_CONFIG_PATH”设置正确,也找不到标头

即使“PKG_CONFIG_PATH”设置正确,也找不到标头

我已经安装了一个库~/.local。环境变量设置如下图:

$ echo $LD_LIBRARY_PATH
/home/saga//.local/lib
$ echo $PKG_CONFIG_PATH
/home/saga//.local/lib/pkgconfig

有一个 re2.pc 文件,/home/saga//.local/lib/pkgconfig其内容是:

prefix=/home/saga//.local
exec_prefix=/home/saga//.local
includedir=/home/saga//.local/include
libdir=/home/saga//.local/lib

Name: re2
Description: RE2 is a fast, safe, thread-friendly regular expression engine.
Version: 0.0.0
Cflags: -std=c++11 -pthread -I${includedir}
Libs: -pthread -L${libdir} -lre2

有一个re2目录,/home/saga//.local/include其中包含re2.h.但是当我尝试编译包含 re2.h 的程序时,出现以下错误:

$ g++ tst.cpp
tst.cpp:1:9: fatal error: re2/re2.h: No such file or directory
 #include<re2/re2.h>
         ^~~~~~~~~~~
compilation terminated.

$ g++ tst2.cpp
tst.cpp:1:9: fatal error: re2.h: No such file or directory
 #include<re2.h>
         ^~~~~~~
compilation terminated.

的输出pkg-config --libs re2-L/home/saga//.local/lib -pthread -lre2

我怎样才能解决这个问题?

答案1

你其实不是使用 pkg-config...

$ g++ $(pkg-config --cflags re2) tst.cpp

答案2

您可以尝试在调试模式下运行 pkg-config:

$ pkg-config --cflags-only-I re2 --debug

它应该打印如下内容:

< cut >
Looking for package 're2'
Looking for package 're2-uninstalled'
Reading 're2' from file '/home/saga/.local/lib/pkgconfig/re2.pc'
Parsing package file '/home/saga/.local/lib/pkgconfig/re2.pc'
  line>prefix=/home/saga//.local
 Variable declaration, 'prefix' has value '/home/saga//local'
  line>exec_prefix=/home/saga//.local
 Variable declaration, 'exec_prefix' has value '/home/saga//local'
  line>includedir=/home/saga//.local/include
 Variable declaration, 'includedir' has value '/home/saga//.local/include'
  line>libdir=/home/saga//.local/lib
 Variable declaration, 'libdir' has value '/home/saga//.local/lib'
  line>
  line>Name: re2
  line>Description: RE2 is a fast, safe, thread-friendly regular expression engine.
  line>Version: 0.0.0
  line>Cflags: -std=c++11 -pthread -I${includedir}
  line>Libs: -pthread -L${libdir} -lre2
Path position of 're2' is 1
Adding 're2' to list of known packages
  pre-remove: re2
 post-remove: re2
 original: re2
   sorted: re2
adding CFLAGS_I string "-I/home/saga//.local/include "
returning flags string "-I/home/saga//.local/include "
-I/home/saga//.local/include

您可以看到最后一行是您当前缺少的内容。

相关内容