0

I have an error of using CvMatToImageView() function in main.cpp

#include "morph.hpp"
...
cv::Mat frame;
ImageView grayscale_image;
...
CvMatToImageView(frame, grayscale_image);
...

error

/home/.../main.cpp:2714: error: undefined reference to `CvMatToImageView(cv::Mat const&, ImageView&)'

morph.hpp file has declaration of CvMatToImageView() function

...
void CvMatToImageView(const cv::Mat& frame, ImageView& image);
...

morph.cpp file has definition of this function

#include "morph.hpp"
void CvMatToImageView(const cv::Mat& frame, ImageView& image)
{ ... }

If you define the function in main.cpp then it will work. What's wrong? Please help. Thanks

  • Show how you are compiling. I suspect that `morph.cpp` is not being compiled or its object file is not linked. If this is VSCode remember that by default it builds only the active file. The documentation explains this and tells you how to edit your tasks.json to build all files in a folder. – drescherjm Jul 07 '22 at 13:03
  • You forgot to link with the definition. How you do that depends on what tools you're using. – molbdnilo Jul 07 '22 at 13:04
  • This is a linker error. Somehow you haven't included `morph.o` (or whatever the output of compiling morph.cpp is named) in your linker command. – Spencer Jul 07 '22 at 13:04
  • @drescherjm I use QtCreater 6.0.2 Based on Qt 6.2.2 (GCC 10.3.1 20210422 (Red Hat 10.3.1-1), 64 bit) on Ubuntu 20.04.1. I build the project with CMake. And there is another compilation error: " :-1: error: CMakeFiles/startUp.dir/Sources/main.cpp.o: in function `Slave::StapleTracker()': " StapleTracker() function calls CvMatToImageView() function. @molbdnilo I included header to source file. Isn't that enough? – Sudakov Andrey Jul 07 '22 at 13:29
  • Please add your `CMakeLists.txt` since that is likely where you have the bug. I assume you forgot to add `morph.cpp` to your sources variable that is used in your `add_executable()` for your executable target. – drescherjm Jul 07 '22 at 13:52
  • @SudakovAndrey *isn't that enough?* No it isn't. – john Jul 07 '22 at 13:53
  • @drescherjm I forgot to set ON "morph" flag in CMakeList.txt of my project so the compiler couldn't define the function. Thank you all for most faster feedback. It was my first question on this public : D – Sudakov Andrey Jul 07 '22 at 14:04

1 Answers1

0

I forgot to set ON "morph" flag in CMakeList.txt of my project so the compiler couldn't define the function.