首页 > 解决方案 > 无需重新编译即可重新生成 pkg-config 文件“opencv.pc”

问题描述

我在我创建的子目录中使用以下命令在 Raspbian 上编译了 OpenCV 库(版本 4):

cmake -D CMAKE_INSTALL_PREFIX=./ -D CMAKE_BUILD_TYPE=Debug ../
make -j4
make install

我正在使用 pkg-config 文件opencv.pc来编译一个带有Makefile.

我不得不将库文件夹移动到另一个目录,以便文件opencv.pc指向错误的路径。但是动态库应该仍然有效(不是吗?)。

那么如何在opencv.pc不重新编译 Raspbian 上的所有库的情况下重新生成文件,这需要大量时间?

编辑 1 尝试重新运行cmake -D CMAKE_INSTALL_PREFIX=./ -D CMAKE_BUILD_TYPE=Debug ../ 会导致以下错误:

CMake Error: The current CMakeCache.txt directory /home/pi/opencv-2.4.13/build/CMakeCache.txt is different than the directory /home/pi/OldDirectory/opencv-2.4.13/build/ where CmakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure reedit CMakeCache.txt 
CMake Error The source "NewSourcePath" does not match the source "NewSourcePath" used to generate cache. Re-run cmake with a different source directory.

标签: opencvmakefilecmakecompilationpkg-config

解决方案


我不得不将库文件夹移动到另一个目录,以便文件 opencv.pc 指向错误的路径。但是动态库应该仍然有效(不是吗?)。

您的.pc文件应使用相对于其自身位置的路径。这样,它就可以安全地搬迁。例如,

prefix=${pcfiledir}/../..
exec_prefix=${prefix}
libdir=${prefix}/include
includedir=${prefix}/lib64

Name: Proton
Description: Qpid Proton C library
Version: 0.36.0
URL: http://qpid.apache.org/proton/
Libs: -L${libdir} -lqpid-proton
Cflags: -I${includedir}

诀窍是${pcfiledir}变量。因此,编写良好的.pc文件将“正常工作”。如果文件使用绝对路径,您可以使用查找和替换方法,将指向先前库位置的前缀替换为您现在拥有库的新前缀。

资料来源:https ://indico.cern.ch/event/848215/contributions/3591953/attachments/1923018/3181752/HSFPackagingRelocation.pdf


推荐阅读