cmake 编译及OpenCV编译notes

17 篇文章 0 订阅
15 篇文章 1 订阅

一、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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值