pkg-config fails to find packages when run from eclipse

主宰稳场 提交于 2019-12-10 10:49:21

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/7928228/pkg-config-fails-to-find-packages-when-run-from-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!