9

i am using raspbian,opencv-2.4.8 and geany this is my simple/first code

#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
using namespace std;
using namespace cv;
int main ()
{
    Mat image=imread("/home/pi/Desktop/pic3.png");
    if (! image.data)
    {
        cout<<"error"<<endl;
    }
    else
    {
        namedWindow("display",WINDOW_AUTOSIZE)
        imshow("display",image);
        waitKey(0);
        return 0;
    }
}    

these are compile and build commands in geany->project->properties->build

g++ $(pkg-config --cflags opencv-2.4.8) -c "f'
g++ $(pkg-config --clfags --libs opencv-2.4.8) -o "e" "f'

and it compiles and build perfectly but when i execute it this is my output

Illegal instruction


(program exited with code :132)

i have searched this exit code on internet but couldn't find a single thread or issue about it

frlan
  • 6,950
  • 3
  • 31
  • 72
ibnetariq
  • 718
  • 1
  • 4
  • 20

1 Answers1

20

132 = 128 + 4

man exit:

>128   A command was interrupted by a signal.

man -s 7 signal

SIGILL        4       Core    Illegal Instruction

Later

The -I/usr/local/include -I/usrlocal/include/opencv makes sense for the compile-only (-c) call (but not for the second g++ call which links the executable). But libraries aren't specified by their full paths. What you normally do, is to specify one -L/usr/local/lib (or similar) for each directory, and -lopencv_calib3d (or similar) for each library in those directories (omitting lib and .so.)

laune
  • 31,114
  • 3
  • 29
  • 42
  • i am totally new to raspbian and i cant figure out why this error is generated even if i am using sample code of opencv same error appears any suggestion how to find/debug this error – ibnetariq Jun 08 '14 at 10:38
  • i added sudo to my execute command now illegal instruction is gone but still gives program exited with code 132 – ibnetariq Jun 08 '14 at 11:15
  • The commands you give for building look very strange to me. For instance: `"f'`. The `-c` switch requests "compile only", so there should be an .o file, but this isn't used in the next command. So, I guess `"e"` (why the quotes?) is the executable, `e`, compiled and linked by the second command. - It is required to know what the `$(pkg-config...)` returns; library names should go to the end of the compile/link commands. – laune Jun 08 '14 at 16:33
  • its for geany "f' compiles the file which is opened and "e" creats .o file with same name – ibnetariq Jun 09 '14 at 17:43
  • pkg-config returns '-I/usr/local/include -I/usrlocal/include/opencv /usr/local/lib/libopencv_calib3d.so' and so on all .so files @laune – ibnetariq Jun 09 '14 at 17:51
  • Added some comments on compiling and linking. – laune Jun 09 '14 at 19:36
  • i tried your suggestion but same result Illegal Instruction @laune – ibnetariq Jun 10 '14 at 08:50
  • i don't think my problem is compile or build it, executable file is generated and when i execute it using ./test then i get this error – ibnetariq Jun 10 '14 at 08:54
  • Compiling and/or building can be the problem - e.g., when you have managed to install compiler or a library that contains instructions not supported by that CPU. It's possible to make gcc display its details. - Does openCV support Raspberry? – laune Jun 10 '14 at 09:52
  • yes, people are working on opencv + raspberry pi [http://robertcastle.com/2014/02/installing-opencv-on-a-raspberry-pi/] . [http://mitchtech.net/category/tutorials/raspberry-pi/] @laune – ibnetariq Jun 10 '14 at 10:11
  • Well, leavin openCV aside, can you compile and execute a "hello world" C++ program? – laune Jun 10 '14 at 11:27
  • yup it runs perfect @laune – ibnetariq Jun 10 '14 at 12:34
  • The logical conclusion is that something's wrong with the library. The links you've given above aren't working any more. – laune Jun 10 '14 at 15:50
  • my bad there was an extra "]" at the end of both links they are working and i will try a fresh reinstall lets see.... – ibnetariq Jun 10 '14 at 17:16