Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
608 views
in Technique[技术] by (71.8m points)

c++ - How do I compile this on mac by terminal command

I am using xcode to compile my opencv project, and I have some settings as below:

    HEADER_SEARCH_PATHS = /usr/local/include

    LIBRARY_SEARCH_PATHS = /usr/local/lib

    OTHER_LDFLAGS = -lopencv_calib3d -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videoio -lopencv_videostab

I want to know what shall I write by terminal command rather than setting of xcode.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you installed OpenCV with homebrew and you also installed the pkgconfig package with homebrew, the package can tell you the settings you need itself - far more accurately than you can guess them.

The easy way is to ask pkgconfig to list all the packages it knows about:

pkg-config --list-all | grep -i opencv

opencv                 OpenCV - Open Source Computer Vision Library

So, now you know the package name is plain and simple opencv, and you can find the flags you need like this:

pkg-config --cflags --libs opencv
-I/usr/local/Cellar/opencv/2.4.12_2/include/opencv 
-I/usr/local/Cellar/opencv/2.4.12_2/include 
-L/usr/local/Cellar/opencv/2.4.12_2/lib 
-lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab

Which means your compilation and linking becomes simply:

g++ $(pkg-config --cflags --libs opencv) program.cpp -o program

If you do that in a Makefile, you will need to double up the $ signs.

If your system is not so well installed, you may need to find the pkgconfig file yourself. So you would do:

find /usr/local -name "opencv*pc"
/usr/local/Cellar/opencv/2.4.12_2/lib/pkgconfig/opencv.pc

Then you can access that file specifically like this:

pkg-config --cflags --libs /usr/local/Cellar/opencv/2.4.12_2/lib/pkgconfig/opencv.pc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...