树莓派3安装OpenCV 3.3.0报错求助
Hey there! I know how frustrating it is to hit roadblocks when you're new to Raspberry Pi and trying to set up OpenCV. Let's break down what's going wrong and fix this step by step.
Why You're Seeing "No makefile has been found"
The root issue here is that your cmake command didn't complete successfully—either because you missed dependencies, used incorrect parameters, or had a broken OpenCV source file. Copying someone else's Makefile won't work because every system's paths, installed libraries, and configurations are unique. Let's start fresh.
Step 1: Clean Up Your Current Build Directory
First, let's wipe the messy build folder to start over:
- Navigate to your OpenCV build directory (the folder where you ran
cmakeearlier). For example:cd ~/opencv-3.3.0/build - Delete all existing files to reset:
rm -rf *
Step 2: Install All Required Dependencies
OpenCV needs a ton of libraries to compile properly. Run these commands to make sure you have everything installed:
sudo apt-get update && sudo apt-get upgrade -y sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev -y sudo apt-get install libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev -y sudo apt-get install libv4l-dev libxvidcore-dev libx264-dev -y sudo apt-get install libatlas-base-dev gfortran -y sudo apt-get install python-dev python-numpy python-pip -y
Wait for all packages to install—this might take a few minutes.
Step 3: Run CMake Correctly
Now let's run cmake with the right parameters tailored for Raspberry Pi. Make sure you're still in the build directory, then execute this command (adjust paths if your OpenCV source or opencv_contrib folders are in different locations):
cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D INSTALL_C_EXAMPLES=ON \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.3.0/modules \ -D BUILD_EXAMPLES=ON \ -D WITH_LIBV4L=ON \ -D WITH_OPENGL=ON ..
- Note: If you didn't download
opencv_contrib, remove the line starting with-D OPENCV_EXTRA_MODULES_PATH=.... - The
..at the end is critical—it tells CMake to look for the OpenCV source code in the parent directory.
As CMake runs, watch the output closely. If you see any red error messages (like "package not found"), go back and install that missing package. If you see "Configuring done" and "Generating done" at the end, congratulations—CMake has successfully created your Makefile!
Step 4: Fix CMake Version Issues (If Needed)
If CMake still fails to generate the Makefile, check your CMake version:
cmake --version
If it's older than 3.5, upgrade it with these commands:
sudo apt-get remove cmake -y sudo apt-get install cmake3 -y
Then use cmake3 instead of cmake in the command above.
Step 5: Compile OpenCV
Once the Makefile is generated correctly, start compiling with:
make -j4
The -j4 uses all 4 cores of your Raspberry Pi 3 to speed up compilation (this will take 2-3 hours, so grab a snack and make sure your Pi has good cooling!).
If compilation finishes without errors, install OpenCV with:
sudo make install sudo ldconfig
A Quick Reminder for Newbies
Never copy a Makefile from another system—compilation settings are highly dependent on your specific environment. Always let CMake generate it for you after ensuring all dependencies are in place.
内容的提问来源于stack exchange,提问作者Kawsur Abeddin

