Ubuntu 11.10
g++ 4.6
Eclipse Platform Version: 3.7.0 Build id: I20110613-1736
Eclipse CDT 6.0.2.20102161416
Really simple OpenCV code:
//============================================================================
// Name : cvHello.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <iomanip>
#include <iterator>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace std;
using namespace cv;
int main(int argc, char* argv[]) {
typedef std::istream_iterator<int> in;
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
IplImage* img =0;
int height,width,step,channels;
uchar *data;
int i,j,k;
if(argc<2){
std::cout << "Usage: main <image-file-name>" << endl;
exit(0);
}
// load an image
img = cvLoadImage(argv[1],4);
if(!img){
std::cout << "Could not load image file: " << endl;
exit(0);
}
// get the image data
height = img->height;
width = img->width;
step = img->widthStep;
channels = img->nChannels;
data = (uchar *)img->imageData;
std::cout << "Processing a "<< height << "x" << width << " image with " << channels << "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;
}
Console output on issuing Project ==> Build All:
**** Build of configuration Debug for project cvHello ****
make all
Building file: ../src/cvHello.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/cvHello.d" -MT"src/cvHello.d" -o"src/cvHello.o" "../src/cvHello.cpp"
Finished building: ../src/cvHello.cpp
Building target: cvHello
Invoking: GCC C++ Linker
g++ -L/usr/local/lib -o"cvHello" ./src/cvHello.o -lopencv-core -lopencv-highgui
/usr/bin/ld: cannot find -lopencv-core
/usr/bin/ld: cannot find -lopencv-highgui
collect2: ld returned 1 exit status
make: *** [cvHello] Error 1
This line:
g++ -L/usr/local/lib -o"cvHello" ./src/cvHello.o -lopencv-core -lopencv-highgui
Fails.
If I rewrite it on the command-line, as such:
g++ -o"cvHello" ./src/cvHello.o -L/usr/local/lib -lopencv_core -lopencv_highgui
it succeeds and the code runs as expected. The only thing that changed was the placement of the -L{LIBRARY_SEARCH_PATH} arguement.
So the question becomes:
How do I control the order of the linker arguements?