IzunumaPi
Posts: 14
Joined: Wed Jun 20, 2018 2:44 am

I cannot compile c++ program.

Thu Sep 06, 2018 1:00 am

I can not compile the following c ++ files. Please tell me the cause.


#include "stdio.h"
#include "highgui.h"
#include "cv.h"

int main( int argc, char** argv){

IplImage* img = cvLoadImage( argv[1] );

cvNamedWindow( "scrot.png", CV_WINDOW_AUTOSIZE );

cvShowImage( "scrot.png", img );

cvReleaseImage( &img );

cvDestroyWindow( "scrot.png" );


}

n67
Posts: 938
Joined: Mon Oct 30, 2017 4:55 pm

Re: I cannot compile c++ program.

Thu Sep 06, 2018 2:00 am

What error message do you get? That's the key to solving your problem.

Peering into my crystal ball, I'm guessing that the functions you are calling are in some library, and
you are not linking that library in.
"L'enfer, c'est les autres"

G fytc hsqr rum umpbq rm qyw rm rfc kmbq md rfgq dmpsk:

Epmu Sn!

J lnacjrw njbruh-carppnanm vxm rb mnuncrwp vh yxbcb!

IzunumaPi
Posts: 14
Joined: Wed Jun 20, 2018 2:44 am

Re: I cannot compile c++ program.

Thu Sep 06, 2018 2:13 am

reg++ -Wall -o "rei2-1" "rei2-1.cpp"(derectory: /home/pi/Desktop/C)
/tmp/ccWxBQc9.o: function `main':
rei2-1.cpp:(.text+0x28): It is an undefined reference to `cvLoadImage'
rei2-1.cpp:(.text+0x3c): It is an undefined reference to`cvNamedWindow'
rei2-1.cpp:(.text+0x4c): It is an undefined reference to`cvShowImage'
rei2-1.cpp:(.text+0x58): It is an undefined reference to`cvReleaseImage'
rei2-1.cpp:(.text+0x60): It is an undefined reference to`cvDestroyWindow'
collect2: error: ld returned 1 exit status
Compile failed

User avatar
scruss
Posts: 2481
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: I cannot compile c++ program.

Thu Sep 06, 2018 3:07 am

You'll need to install the OpenCV libraries - at least libopencv-highgui-dev - and add the library link on the command line
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

IzunumaPi
Posts: 14
Joined: Wed Jun 20, 2018 2:44 am

Re: I cannot compile c++ program.

Mon Sep 10, 2018 4:21 am

How can I add the library link on the command line?

User avatar
B.Goode
Posts: 8575
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: I cannot compile c++ program.

Mon Sep 10, 2018 11:05 am

IzunumaPi wrote:
Mon Sep 10, 2018 4:21 am
How can I add the library link on the command line?
Assuming that reg++ behaves in the same way as g++, the explanation from the man page says this:
-llibrary
-l library
Search the library named library when linking. (The second alternative with the library as a separate argument is only for POSIX compliance and is not recommended.)

Return to “Beginners”