pkg-config妙用
阿新 • • 發佈:2018-11-17
1.makefile 中選項
cflags 指定標頭檔案路徑 eg: CFLAGS=-I/usr/include
LDFLAGS: 庫檔案位置 eg: LDFLAGS=-L/usr/lib -L/path/to/your/lib
LIBS:告訴連結器要連結哪些庫檔案,如LIBS = -lpthread -liconv
gcc 選項: -I -L
2.pkg-config
LInux命令,獲得某個庫/模組的所有編譯相關的資訊
pkg-config opencv –libs –cflags 檢視opencv標頭檔案和庫檔案
輸出:
-I/usr/local/include/opencv4/opencv -I/usr/local/include/opencv4 -L/usr/local/lib -lopencv_gapi -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dpm -lopencv_face -lopencv_photo -lopencv_fuzzy -lopencv_hdf -lopencv_hfs -lopencv_img_hash -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_sfm -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_surface_matching -lopencv_tracking -lopencv_video -lopencv_datasets -lopencv_plot -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_flann -lopencv_xobjdetect -lopencv_imgcodecs -lopencv_objdetect -lopencv_xphoto -lopencv_imgproc -lopencv_core
好處:所有用opencv的其他程式,在編譯時,只需要寫“pkg-config opencv –libs –cflags”,而不需要自己去找opencv的標頭檔案在哪裡,要連結的庫在哪裡!省時省力!
如果你寫了一個庫,不管是靜態的還是動態的,要提供給第三方使用,那除了給人家庫/標頭檔案,最好也寫一個pc檔案,這樣別人使用就方便很多,不用自己再手動寫依賴了你哪些庫,只需要敲一個”pkg-config [YOUR_LIB] –libs –cflags”。
pkg資訊在PKG_CONFIG_PATH環境變數下,裡面有各個pc檔案,如opencv的.
使用pkg-config 編譯自己程式寫法為:gcc main.c `pkg-config --cflags --libs opencv` -o main