Ask Your Question

"Illegal instruction" when running any compiled opencv demo binary & sse3 flag

asked 2013-08-01 05:55:26 -0600

Sr. Betelu gravatar image

Hi all,

I just want to notice an issue that happened to me today. I untarred the 2.4.5 version of of OpenCV in a machine running Ubuntu 12.04. Then I went inside the dir, create de build directory and run cmake

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/home/usuario/inst_opencv_245 ..

Everything seemed to go ok so I did "make install" and the whole bunch started to compile. It ended up without any problem (I did this installation before on other machines) but as soon as I tried to execute any binary, such as opencv_test_core nothing started but an "Illegal instruction" message.

I googled this issue around for a little bit and I saw sth related to sse, processors and things like that. So I did "cat /proc/cpuinfo" and this was the output:

processor : 0 vendor_id : AuthenticAMD cpu family : 15 model : 12 model name : AMD Athlon(tm) 64 Processor 3000+ stepping : 0 cpu MHz : 1000.000 cache size : 512 KB fdiv_bug : no hlt_bug : no f00f_bug : no coma_bug : no fpu : yes fpu_exception : yes cpuid level : 1 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext lm 3dnowext 3dnow up bogomips : 2000.07 clflush size : 64 cache_alignment : 64 address sizes : 40 bits physical, 48 bits virtual power management: ts fid vid ttp

For my surprise, running the above cmake command showed that an sse3 flag was enabled for both c and c++ gcc compilers. So what I did was to comment the lines 140 and 144 of the file OpenCVCompilerOptions.cmake under the cmake directory.

# GCC depresses SSEx instructions when -mavx is used. Instead, it generates if(NOT OPENCV_EXTRA_CXX_FLAGS MATCHES "-mavx") if(ENABLE_SSE3) # add_extra_compiler_option(-msse3) endif() if(ENABLE_SSSE3) # add_extra_compiler_option(-mssse3) endif() if(ENABLE_SSE41) add_extra_compiler_option(-msse4.1) endif()

Then I did cmake again and after compiling and installing it again everything worked perfectly.

I dunno if this is a bug or what. It is just in case anyone had this problem.


P.S.: this is my first post, sorry for the format.

edit retag flag offensive close merge delete


Thanks! I've been struggling for days with this. I guess my 15-year old IBM T30 shouldn't behave like 'modern' machines. At first I blamed simplecv, then opencv. Now I can close a query on the simplecv site. Appreciated greatly.

andycrofts gravatar imageandycrofts ( 2013-08-20 18:26:21 -0600 )edit

Thanks, I was with the some problem and yours was very helpful. Actually, I didn't took care about those flags when I was compiling OpenCV. Thanks again

Adrian034 gravatar imageAdrian034 ( 2016-02-18 09:28:07 -0600 )edit

1 answer

Sort by » oldest newest most voted

answered 2013-08-01 06:47:17 -0600

SSE support in OpenCV is controlled by ENABLE_SSE, ENABLE_SSE2, etc flags for cmake. You need just run cmake with -DENABLE_SSE3=OFF to cmake command line and it fix you issue. You can find list of SSEx and AVX flags in CmakeLists.txt in OpenCV source root directory.

edit flag offensive delete link more

Question Tools


Asked: 2013-08-01 05:55:26 -0600

Seen: 3,656 times

Last updated: Aug 01 '13