Python C++链接器输入时自动提取目录下的不同版本lib文件名

  • Post author:
  • Post category:python




需求

在C++第三方库的安装配置时,在链接器输入时需要区分debug版本的lib和release版本的lib,但是某些大型库(比如说OpenCV)里面的lib是很多的,一个个复制文件名粘贴太麻烦了,而且两种版本就差了一个d字母,很容易看花眼。所以写了一个小脚本,自动提取lib目录下debug版本和release版本的lib文件名,分别写入到两个txt里,然后配置的时候直接复制整个txt里的文件名到链接器输入就好了。




代码

import os


def Extract_lib(path):
    release = open("release_lib.txt", 'w')
    debug = open("debug_lib.txt", 'w')
    for file in os.listdir(path):
        if file[-5:] == 'd.lib':
            debug.write(file)
            debug.write('\n')
        elif file[-4:] == '.lib':
            release.write(file)
            release.write('\n')
    debug.close()
    release.close()


if __name__ == '__main__':
    path = r"D:\Program Files (x86)\OPenCV\x64\vc16\lib"
    Extract_lib(path)



效果

以OpenCV 4.5.5 的为例,输入其lib目录:

debug_lib.txt 内容

opencv_aruco455d.lib
opencv_barcode455d.lib
opencv_bgsegm455d.lib
opencv_bioinspired455d.lib
opencv_calib3d455d.lib
opencv_ccalib455d.lib
opencv_core455d.lib
opencv_cudaarithm455d.lib
opencv_cudabgsegm455d.lib
opencv_cudacodec455d.lib
opencv_cudafeatures2d455d.lib
opencv_cudafilters455d.lib
opencv_cudaimgproc455d.lib
opencv_cudalegacy455d.lib
opencv_cudaobjdetect455d.lib
opencv_cudaoptflow455d.lib
opencv_cudastereo455d.lib
opencv_cudawarping455d.lib
opencv_cudev455d.lib
opencv_datasets455d.lib
opencv_dnn455d.lib
opencv_dnn_objdetect455d.lib
opencv_dnn_superres455d.lib
opencv_dpm455d.lib
opencv_face455d.lib
opencv_features2d455d.lib
opencv_flann455d.lib
opencv_fuzzy455d.lib
opencv_gapi455d.lib
opencv_hfs455d.lib
opencv_highgui455d.lib
opencv_imgcodecs455d.lib
opencv_imgproc455d.lib
opencv_img_hash455d.lib
opencv_intensity_transform455d.lib
opencv_line_descriptor455d.lib
opencv_mcc455d.lib
opencv_ml455d.lib
opencv_objdetect455d.lib
opencv_optflow455d.lib
opencv_phase_unwrapping455d.lib
opencv_photo455d.lib
opencv_plot455d.lib
opencv_quality455d.lib
opencv_rapid455d.lib
opencv_reg455d.lib
opencv_rgbd455d.lib
opencv_saliency455d.lib
opencv_shape455d.lib
opencv_stereo455d.lib
opencv_stitching455d.lib
opencv_structured_light455d.lib
opencv_superres455d.lib
opencv_surface_matching455d.lib
opencv_text455d.lib
opencv_tracking455d.lib
opencv_video455d.lib
opencv_videoio455d.lib
opencv_videostab455d.lib
opencv_wechat_qrcode455d.lib
opencv_world455d.lib
opencv_xfeatures2d455d.lib
opencv_ximgproc455d.lib
opencv_xobjdetect455d.lib
opencv_xphoto455d.lib

release_lib.txt 内容

opencv_aruco455.lib
opencv_barcode455.lib
opencv_bgsegm455.lib
opencv_bioinspired455.lib
opencv_calib3d455.lib
opencv_ccalib455.lib
opencv_core455.lib
opencv_cudaarithm455.lib
opencv_cudabgsegm455.lib
opencv_cudacodec455.lib
opencv_cudafeatures2d455.lib
opencv_cudafilters455.lib
opencv_cudaimgproc455.lib
opencv_cudalegacy455.lib
opencv_cudaobjdetect455.lib
opencv_cudaoptflow455.lib
opencv_cudastereo455.lib
opencv_cudawarping455.lib
opencv_cudev455.lib
opencv_datasets455.lib
opencv_dnn455.lib
opencv_dnn_objdetect455.lib
opencv_dnn_superres455.lib
opencv_dpm455.lib
opencv_face455.lib
opencv_features2d455.lib
opencv_flann455.lib
opencv_fuzzy455.lib
opencv_gapi455.lib
opencv_hfs455.lib
opencv_highgui455.lib
opencv_imgcodecs455.lib
opencv_imgproc455.lib
opencv_img_hash455.lib
opencv_intensity_transform455.lib
opencv_line_descriptor455.lib
opencv_mcc455.lib
opencv_ml455.lib
opencv_objdetect455.lib
opencv_optflow455.lib
opencv_phase_unwrapping455.lib
opencv_photo455.lib
opencv_plot455.lib
opencv_quality455.lib
opencv_rapid455.lib
opencv_reg455.lib
opencv_rgbd455.lib
opencv_saliency455.lib
opencv_shape455.lib
opencv_stereo455.lib
opencv_stitching455.lib
opencv_structured_light455.lib
opencv_superres455.lib
opencv_surface_matching455.lib
opencv_text455.lib
opencv_tracking455.lib
opencv_video455.lib
opencv_videoio455.lib
opencv_videostab455.lib
opencv_wechat_qrcode455.lib
opencv_world455.lib
opencv_xfeatures2d455.lib
opencv_ximgproc455.lib
opencv_xobjdetect455.lib
opencv_xphoto455.lib




版权声明:本文为m0_50910915原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。