I used to have OpenCV3 from the Arch Linux pckage manager(pacman) and it worked fine but when I removed it and install OpenCV 3.4.1 and OpenCV-Contrib from source code nothing worked even the old project when I tryied to recompile them, here is the CMakeLists.txt file:

cmake_minimum_required(VERSION 2.8)
cmake_policy(SET CMP0012 NEW)
find_package(OpenCV 3.4.0 REQUIRED)
message("OpenCV Version ${OpenCV_Version}")
set(SRC main.cpp)
add_executable(${PROJECT_NAME} ${SRC})
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})

Here is the main.cpp file (for demonstrating, all prjects don't work anymore after recompiling them)

#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/face.hpp"
#include "opencv2/imgproc.hpp"

#include <stdio.h> 
#include <fstream>
#include <sstream>

using namespace cv;
using namespace cv::face;
using namespace std;

//Normalize image

static Mat norm_0_255(Mat _src){
     Mat src (_src);
     //The returned normalized image
    Mat dst;
    switch (src.channels()){
         case 1:
             normalize(src, dst, 0, 255, NORM_MINMAX, CV_8UC1);
         case 3:
             normalize(src, dst, 0, 255, NORM_MINMAX, CV_8UC3);
     return dst;

 //Read CSV which containts the paths to images
 static void read_csv(const string& filename, vector<Mat>& images,         vector<int>& labels, char separator = ';'){
     ifstream file(filename.c_str(), ifstream::in);
         string error_message = "No valid inout file was given\n";
         CV_Error(Error::StsBadArg, error_message);
     string line, path, classlabel;
     while(getline(file, line)){
         stringstream liness(line);
         getline(liness, path, separator);
         getline(liness, classlabel);
         if(!path.empty() && !path.empty()){
             images.push_back(imread(path, 0));

 int main(int argc,const char* argv[]){
     return 0;

Errors after recompiling the project

cmake ..

OpenCV Errors after recompiling the project

The remainder errors are the same. Note:This code is from samples , and ofcourse this is part of it, other projects wouldn't work too although they are worked before I reinstalled it.


I have solved it by recompiling OpenCV and recompiling LPACKE for Compiling OpenCV I've used their docs and this blog post

*Note for block post I haven't used the last two commands

sudo sh -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf'

sudo ldconfig

I used this blog as a guid, I didn't need all the stuff in it *Also I suggest that you should first learn about compiling from source(cmake and make) and also the structure of Linux system(you can find alot online), because the problem was that OpenCV can't found dependcies as someone said to me on G+ post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.