从 eclipse 运行时 pkg-config 无法找到包
我有一个恼人的问题。 我在项目中使用 pkg-config 。它工作得很好,但现在不行了(不知道已经改变了) 当我从 eclipse 内部使用此行链接时:
g++ `pkg-config --libs opencv` -o"RawConverterTgi" ./main.o
我收到错误:
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found
但是当我
pkg-config --libs opencv
在控制台中运行时,我得到的
-L/usr/local/opencv2.3.1/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
结果正是我所期望的
如果我使用 eclipse 生成的 makefile 从控制台编译/链接,它工作正常。
如果我通过在 eclipse 中设置 $PKG_CONFIG_PATH 来指定 opencv.pc 文件的位置,它就可以工作(这是通过附加到 $PKG_SEARCH_PATH 来完成的)。因此,出于某种原因,当从 eclipse 调用时,pkg-config 不会在默认的 /usr/lib/pkgconfig 目录中搜索,但从命令行调用时会搜索。
有人可以帮助我纠正这个问题,以便 pkg-config 在从 eclipse 调用时也搜索默认目录吗? (将默认目录添加到 $PKG_SEARCH_PATH 是一个解决方案,但这似乎不是必需的或正确的方法)
我的设置如下
Eclipse Helios
CDT 7.0
pkg-config version 0.25
I have an annoying problem.
I use pkg-config in a project. It has worked fine but now it doesn't (dont know that has changed)
When I link from inside eclipse with this line:
g++ `pkg-config --libs opencv` -o"RawConverterTgi" ./main.o
I get the error:
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found
But when I run
pkg-config --libs opencv
in a console I get
-L/usr/local/opencv2.3.1/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
which is what I would expect
If I compile/link from the console by using the makefile that eclipse has generated, it works fine.
If I specify where the opencv.pc file is by setting $PKG_CONFIG_PATH inside eclipse it works (This is done by appending to $PKG_SEARCH_PATH). So for some reason pkg-config doesn't search in the default /usr/lib/pkgconfig directory when invoked from eclipse but when invoked from command line is does.
Can someone help me correct this so that pkg-config searches the default dir also when invoked from eclipse? (adding the default dir to $PKG_SEARCH_PATH is a solution but this doesn't seem to be necessary or the correct way)
My setup is as follows
Eclipse Helios
CDT 7.0
pkg-config version 0.25
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决问题的方法。
我不知道为什么,但在 eclipse Helios 中,eclipse 似乎自动定义了一个名为 $PKG_CONFIG_LIBDIR 的环境变量。如果此变量存在,则 pkg-config 的默认搜索路径将更改为此变量中的任何内容。解决方案很简单,取消定义该变量即可。
从 Eclipse 转到:
项目属性 -> C/C++ 构建 -> 环境
取消设置变量的
I found the solution to my problem.
I'm not sure why but in eclipse Helios it seems that eclipse automatically defines an environment variable called $PKG_CONFIG_LIBDIR. If this variable exists the default search path for pkg-config is changed to whatever is in this variable. The solution is simply to undefine this variable.
from eclipse go to:
Project properties->C/C++ build -> Environment
to unset the variable