cmake 编译及OpenCV编译notes

一、cmake入门

二、c++11 feature

from:https://stackoverflow.com/questions/19774778/when-is-it-necessary-to-use-use-the-flag-stdlib-libstdc

On Linux: In general, all commonly available linux distributions will use libstdc++ by default. If you want to compile c++11 code here, use one of:

  • g++ -std=c++11 input.cxx -o a.out
  • g++ -std=gnu++11 input.cxx -o a.out

On OS X before Mavericks: libstdc++ was the default. You could use libc++ (which included c++11 library support) by passing -stdlib=libc++. If you want to compile c++11 code here, use one of:

  • g++ -std=c++11 -stdlib=libc++ input.cxx -o a.out
  • g++ -std=gnu++11 -stdlib=libc++ input.cxx -o a.out
  • clang++ -std=c++11 -stdlib=libc++ input.cxx -o a.out
  • clang++ -std=gnu++11 -stdlib=libc++ input.cxx -o a.out

On OS X since Mavericks: libc++ is the default. You can use libstdc++ (which does not include c++11 library support) by passing -stdlib=libstdc++

  • clang++ -std=c++11 input.cxx -o a.out
  • clang++ -std=gnu++11 input.cxx -o a.out

三、tree dir命令可以显示文件夹文件结构

 │   ├── README.md
    │   ├── scripts
    │   │   ├── build_opencv.sh
    │   │   ├── cpplint.sh
    │   │   └── install_opencv.sh
    │   └── src
    │       ├── gradient_filter.cc
    │       ├── lens_blur_filter.cc
    │       ├── main.cc
    │       └── quadtree.cc
    └── opencv-3.3.0.tar.gz

四、运行脚本时,出现[[: not found,是因为从Ubuntu 6.10开始,默认使用dash(theDebian Almquist Shell)而不是bash(the GNUBourne-Again Shell),需作如下处理:

#先看看是用的哪个 shell
ls -al /bin/sh

#如果是 Dash 可用以下方法切回 Bash(选择 NO)
方法一
sudo dpkg-reconfigure dash

方法二
sudo ln -fs /bin/bash /bin/sh

五、“cmake_symlink_library: System Error: Read-only file system“错误,

一般为代码存放在Win/Linux共享文件夹导致,将代码copy到Linux本地例如用户目录编译可解决此问题。

六、error: ‘FilterEngine’ is not a member of ‘cv’

There's no class FilterEngine in 3.0.0 anymore,change to version 2.4.11 , problem solved

七、在ubuntu上编译OS上的代码时,可将clang/clang++改为gcc/g++

八、opencv编译脚本

#!/bin/sh
#
#  install_opencv.sh
#
#  MIT License
#

readonly CLANG_CC=$(which gcc)
readonly CLANG_CXX=$(which g++)
if [[ ! -f $CLANG_CC ]]; then
  echo "gcc was not found: $CLANG_CC"
  exit 1
fi
if [[ ! -f $CLANG_CXX ]]; then
  echo "g++ was not found: $CLANG_CXX"
  exit 1
fi

readonly SRCROOT=$(cd "$(dirname "$0")/../"; pwd)
readonly OPENCV_DIR="$SRCROOT/opencv"
readonly OPENCV_BUILD_DIR="$OPENCV_DIR/build"

echo "-- Building"
mkdir -p "$OPENCV_BUILD_DIR"
pushd "$OPENCV_BUILD_DIR"
  cmake -G "Unix Makefiles" \
      -DCMAKE_BUILD_TYPE="RELEASE" \
      -DCMAKE_C_COMPILER="$CLANG_CC" \
      -DCMAKE_CXX_COMPILER="$CLANG_CXX" \
      -DCMAKE_CXX_FLAGS="-std=c++11" \
      -DCMAKE_OSX_ARCHITECTURES="x86_64" \
      "$OPENCV_DIR"
  make -j8
  echo "-- Installing"
  make install
popd

echo "-- Done"

十、编译opencv出现错误“CMake Error: cmake_symlink_library: System Error: Protocol error

 I run the make command on a virtual machine. When running the command on a folder that is shared by the guest and the host OS, the system reports the above error. When running on a folder that is accessible only on the guest OS, everything works fine.

十一、编译安装单个module,例如imgproc

sudo make opencv_imgproc

sudo make install

你可能感兴趣的:(android,c++,滤镜)