0

I migrated from python to c++ recently;I am trying to do opencv4 but when I try to compile with cl it gives me an error saying several external symbols are missing. I don't want to try to install visual studio because of low finance and unbreakable love for vs code. Any help will be appreciated. Sample code is here. Sorry about some silly syntax errors, that is because I am typing by my phone.

#include <iostream>
#include <openvc2/opencv.hpp>
#include <openvc2/highgui.hpp>

using namespace cv;

int main(){
   Mat img = imread("file.jpg");
   imshow("win",img);
   WaitKey(0);
   destroyAllWindows();
   return 0;
Lewaro
  • 1
  • 1
  • Are you supplying the required libraries on the command line? What is the command line you're using? What are the actual errors? – Retired Ninja Nov 08 '22 at 17:19
  • *I don't want to try to install visual studio because of low finance* [visual studio is free](https://visualstudio.microsoft.com/vs/community/) – NathanOliver Nov 08 '22 at 17:20
  • 1
    Building a C++ program is done in three steps: 1) Edit the source; 2) Compile the source into an object file (this is the step where header files are included); And 3) Link object files together with libraries to create the executable program file. The problem you're having in in step 3, where you probably don't link with the OpenCV libraries. – Some programmer dude Nov 08 '22 at 17:21
  • 1
    Note that sometimes steps 2 and 3 can be performed together transparently by the compiler, hiding the fact that there is a step 3 from you. – user4581301 Nov 08 '22 at 17:23
  • Regarding not wanting to install Visual Studio, how did you install the Visual Studio compiler `cl` without downloading Visual Studio? It's not possible to get the compiler `cl` without Visual Studio. Even if you can skip the installation of the actual IDE, it still part of the same package. – Some programmer dude Nov 08 '22 at 17:23
  • @NathanOliver free-ish. The community edition has some restrictions (e.g. I wouldn't be able to use it at work) – Alan Birtles Nov 08 '22 at 17:26
  • In VSCode note that neither code-runner nor the default tasks.json will support an external library by default. You will have to edit the compiler args or switch to use CMakeTools and use a CMakeLists.txt – drescherjm Nov 08 '22 at 18:29

0 Answers0