重新生成 pkg 配置文件 'opencv.pc' 而不重新编译



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

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

并且我正在使用 pkg 配置文件opencv.pc来编译一个带有Makefile的项目。

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

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

编辑 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.

我不得不将库文件夹移动到另一个目录,以便文件 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

最新更新