我如何通过terminal命令在mac上编译它

时间:2016-05-03 04:07:51

标签: c++ macos opencv compilation

我使用xcode编译我的opencv项目,我有一些设置如下:

    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

我想知道终端命令应该写什么,而不是设置xcode。

2 个答案:

答案 0 :(得分:3)

如果您使用 Intent share = new Intent(Intent.ACTION_SEND); share.setType("image/*"); // share.setPackage("com.hike"); share.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject"); share.putExtra(Intent.EXTRA_TEXT, "Hello " + webView.getUrl()); /* * if (text!=null){ share.putExtra(Intent.EXTRA_TEXT,text); } if * (path!=null){ share.putExtra(Intent.EXTRA_STREAM, * Uri.fromFile(new File(path))); } */ share.putExtra(Intent.EXTRA_STREAM, BitmapURLFromAssets.getBitmapFromAssets(MainActivity.this, "logo.png")); try { startActivity(Intent.createChooser(share, "")); } catch (android.content.ActivityNotFoundException ex) { FireToast.makeToast(MainActivity.this, "hike have not been installed."); } 安装了OpenCV并且还安装了homebrewpkgconfig,则该软件包可以告诉您自己需要的设置 - 远比你可以猜到它们。

简单的方法是让homebrew列出它知道的所有包:

pkgconfig

所以,现在您知道包名称简单明了pkg-config --list-all | grep -i opencv opencv OpenCV - Open Source Computer Vision Library ,您可以找到所需的标志:

opencv

这意味着您的编辑和链接变得简单:

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

如果您在Makefile中执行此操作,则需要将g++ $(pkg-config --cflags --libs opencv) program.cpp -o program 符号加倍。

如果您的系统安装不正确,您可能需要自己查找$文件。所以你会这样做:

pkgconfig

然后你可以像这样访问该文件:

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

答案 1 :(得分:1)

您可以使用:

g++ -I ${HEADER_SEARCH_PATHS} -L ${LIBRARY_SEARCH_PATHS} ${OTHER_LDFLAGS} ${SOURCE_FILES}