Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6895549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:55:23+00:00 2026-05-27T06:55:23+00:00

I installed opencv from Macports and it is in /opt/local/include I tried to compile

  • 0

I installed opencv from Macports and it is in
/opt/local/include

I tried to compile basic OPENCV code from Terminal by giving the following commands, but it doesn’t getting compiled:

g++ example.cpp -o example -I /usr/local/include/opencv/ -L /usr/local/lib/ -lopencv_highgui -lopencv_calib3d -lopencv_legacy
g++ example.cpp -o example -I /opt/local/include/opencv/ -L /opt/local/lib/ -lopencv_highgui -lopencv_calib3d -lopencv_legacy

Can anyone tell me the right Terminal command to compile given below opencv program for Mac OS X 10,7?

I was trying to compile the simple example given on this link:
http://www.cs.iit.edu/~agam/cs512/lect-notes/opencv-intro/

Edit:

Here is the code I am trying to compile:

////////////////////////////////////////////////////////////////////////
//
// hello-world.cpp
//
// This is a simple, introductory OpenCV program. The program reads an
// image from a file, inverts it, and displays the result. 
//
////////////////////////////////////////////////////////////////////////
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>


int main(int argc, char *argv[])
{
  IplImage* img = 0; 
  int height,width,step,channels;
  uchar *data;
  int i,j,k;

  if(argc<2){
    printf("Usage: main <image-file-name>\n\7");
    exit(0);
  }

  // load an image  
  img=cvLoadImage(argv[1]);
  if(!img){
    printf("Could not load image file: %s\n",argv[1]);
    exit(0);
  }

  // get the image data
  height    = img->height;
  width     = img->width;
  step      = img->widthStep;
  channels  = img->nChannels;
  data      = (uchar *)img->imageData;
  printf("Processing a %dx%d image with %d channels\n",height,width,channels); 

  // create a window
  cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); 
  cvMoveWindow("mainWin", 100, 100);

  // invert the image
  for(i=0;i<height;i++) for(j=0;j<width;j++) for(k=0;k<channels;k++)
    data[i*step+j*channels+k]=255-data[i*step+j*channels+k];

  // show the image
  cvShowImage("mainWin", img );

  // wait for a key
  cvWaitKey(0);

  // release the image
  cvReleaseImage(&img );
  return 0;
}

And here is the output:

singhg@~/Programming/opencvTest $ g++ example.c -o example 'pkg-config --cflags --libs opencv'
i686-apple-darwin11-llvm-g++-4.2: pkg-config --cflags --libs opencv: No such file or directory
example.c:14:16: error: cv.h: No such file or directory
example.c:15:21: error: highgui.h: No such file or directory
example.c: In function ‘int main(int, char**)’:
example.c:21: error: ‘IplImage’ was not declared in this scope
example.c:21: error: ‘img’ was not declared in this scope
example.c:23: error: ‘uchar’ was not declared in this scope
example.c:23: error: ‘data’ was not declared in this scope
example.c:32: error: ‘cvLoadImage’ was not declared in this scope
example.c:43: error: expected primary-expression before ‘)’ token
example.c:43: error: expected `;' before ‘img’
example.c:47: error: ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope
example.c:47: error: ‘cvNamedWindow’ was not declared in this scope
example.c:48: error: ‘cvMoveWindow’ was not declared in this scope
example.c:55: error: ‘cvShowImage’ was not declared in this scope
example.c:58: error: ‘cvWaitKey’ was not declared in this scope
example.c:61: error: ‘cvReleaseImage’ was not declared in this scope

Edit[6Dec]:

singhg@~/Programming/opencvTest $ g++ example.cpp -o example `pkg-config --cflags --libs opencv`
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found
i686-apple-darwin11-llvm-g++-4.2: example.cpp: No such file or directory
i686-apple-darwin11-llvm-g++-4.2: no input files
singhg@~/Programming/opencvTest $ 

in my /opt/local/lib I have:

singhg@/opt/local/lib $ ls *cv*
libopencv_calib3d.2.3.1.dylib       libopencv_highgui.dylib
libopencv_calib3d.2.3.dylib     libopencv_imgproc.2.3.1.dylib
libopencv_calib3d.dylib         libopencv_imgproc.2.3.dylib
libopencv_contrib.2.3.1.dylib       libopencv_imgproc.dylib
libopencv_contrib.2.3.dylib     libopencv_legacy.2.3.1.dylib
libopencv_contrib.dylib         libopencv_legacy.2.3.dylib
libopencv_core.2.3.1.dylib      libopencv_legacy.dylib
libopencv_core.2.3.dylib        libopencv_ml.2.3.1.dylib
libopencv_core.dylib            libopencv_ml.2.3.dylib
libopencv_features2d.2.3.1.dylib    libopencv_ml.dylib
libopencv_features2d.2.3.dylib      libopencv_objdetect.2.3.1.dylib
libopencv_features2d.dylib      libopencv_objdetect.2.3.dylib
libopencv_flann.2.3.1.dylib     libopencv_objdetect.dylib
libopencv_flann.2.3.dylib       libopencv_ts.2.3.1.dylib
libopencv_flann.dylib           libopencv_ts.2.3.dylib
libopencv_gpu.2.3.1.dylib       libopencv_ts.dylib
libopencv_gpu.2.3.dylib         libopencv_video.2.3.1.dylib
libopencv_gpu.dylib         libopencv_video.2.3.dylib
libopencv_highgui.2.3.1.dylib       libopencv_video.dylib
libopencv_highgui.2.3.dylib
singhg@/opt/local/lib $ 

Now I used this command:

   singhg@~/Programming/opencvTest $ g++ hello-world.cpp -o hello-world -I /opt/local/include/opencv/ -L /opt/local/lib  -lopencv_highgui -lopencv_core
In file included from hello-world.cpp:12:
/opt/local/include/opencv/cv.h:63:33: error: opencv2/core/core_c.h: No such file or directory
/opt/local/include/opencv/cv.h:64:33: error: opencv2/core/core.hpp: No such file or directory
/opt/local/include/opencv/cv.h:65:39: error: opencv2/imgproc/imgproc_c.h: No such file or directory
/opt/local/include/opencv/cv.h:66:39: error: opencv2/imgproc/imgproc.hpp: No such file or directory
/opt/local/include/opencv/cv.h:67:38: error: opencv2/video/tracking.hpp: No such file or directory
/opt/local/include/opencv/cv.h:68:45: error: opencv2/features2d/features2d.hpp: No such file or directory
/opt/local/include/opencv/cv.h:69:35: error: opencv2/flann/flann.hpp: No such file or directory
/opt/local/include/opencv/cv.h:70:39: error: opencv2/calib3d/calib3d.hpp: No such file or directory
/opt/local/include/opencv/cv.h:71:43: error: opencv2/objdetect/objdetect.hpp: No such file or directory
/opt/local/include/opencv/cv.h:72:37: error: opencv2/legacy/compat.hpp: No such file or directory
/opt/local/include/opencv/cv.h:79:37: error: opencv2/core/internal.hpp: No such file or directory
In file included from hello-world.cpp:13:
/opt/local/include/opencv/highgui.h:47:39: error: opencv2/highgui/highgui_c.h: No such file or directory
/opt/local/include/opencv/highgui.h:48:39: error: opencv2/highgui/highgui.hpp: No such file or directory
hello-world.cpp: In function ‘int main(int, char**)’:
hello-world.cpp:18: error: ‘IplImage’ was not declared in this scope
hello-world.cpp:18: error: ‘img’ was not declared in this scope
hello-world.cpp:20: error: ‘uchar’ was not declared in this scope
hello-world.cpp:20: error: ‘data’ was not declared in this scope
hello-world.cpp:29: error: ‘cvLoadImage’ was not declared in this scope
hello-world.cpp:40: error: expected primary-expression before ‘)’ token
hello-world.cpp:40: error: expected `;' before ‘img’
hello-world.cpp:44: error: ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope
hello-world.cpp:44: error: ‘cvNamedWindow’ was not declared in this scope
hello-world.cpp:45: error: ‘cvMoveWindow’ was not declared in this scope
hello-world.cpp:52: error: ‘cvShowImage’ was not declared in this scope
hello-world.cpp:55: error: ‘cvWaitKey’ was not declared in this scope
hello-world.cpp:58: error: ‘cvReleaseImage’ was not declared in this scope
singhg@~/Programming/opencvTest $ 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:55:24+00:00Added an answer on May 27, 2026 at 6:55 am

    Or use pkg-config to assist you filling in the paths and libraries:

    g++ example.cpp -o example `pkg-config --cflags --libs opencv`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have installed OpenCV. I have been able to compile some code but sometimes
I've installed Code::Blocks with MinGW and OpenCV 2.4.3. I want to compile this simple
I installed the following component by MacPorts: p5-image-info @1.16 (perl, graphics) Extract meta information
I installed opencv in my mac using mac ports by the following command sudo
g++ cv.cpp -o cv -I /usr/local/include/opencv -L /usr/local/lib -lm -lcv -lhighgui -lcvaux Error: /usr/bin/ld:
I compiled and installed OpenCV (last version from the SVN) on Mac Os X
I have installed OpenCV C libraries from package management into my Kubuntu 9.10. I
I have a problem using openCV 2.3.1 installed from mac ports. For installation and
Having successfully installed opencv 2.0 with python bindings I'm starting to run into trouble
Installed rubyinstaller-1.8.7-p358.exe, then tried to install jammit , but the config.gem command isn't being

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.