程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python C++鏈接器輸入時自動提取目錄下的不同版本lib文件名

編輯: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


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved