0

I'm working with ns3 and I have built my own module and I need to use OpenCv inside it. So I edited the wscript to look like this:

def build(bld):
 bld.env.append_value("LIB", ["opencv_core", "opencv_ml"])
 //other stuff..

Then in the main module.cpp I import opencv like this:

#include <opencv4/opencv2/core.hpp>
#include <opencv4/opencv2/ml.hpp>

and later in the code I try to build a knn and train it:

void module::TrainKnn()
{
 cv::Ptr<cv::ml::KNearest> knn = cv::ml::Knearest::create();
 cv::Mat train_data;
 //other stuff
}

Now the problem arise when I try to compile with ./waf:

"undefined reference to 'cv::Mat::Mat()'"

This means that somehow the link for cv::Mat which is inside OpenCv_Core did not work, but it works for cv::ml::KNearest which is inside Opencv_ml.

If I try to compile a simple program outside ns3 with the same function TrainKnn I need to run g++ HelloWorld.cpp -o HelloWorld -L/home/davide/opencv-4.5.4/build/lib -lopencv_core -lopencv_ml and the program compile and works fine. So I tried to edit the wscript by adding:

def configure(conf):
 conf.env.append_value("LINKFLAGS", ["-L/home/davide/opencv-4.5.4/build/lib -lopencv_core -lopencv_ml"])
 conf.env.append_value("LIB", ["opencv_core", "opencv_ml"]

But the problem persist. Any help would be really appreciated.

Davide Quaglio
  • 751
  • 2
  • 11
  • 31
  • Have you tried passing loader flags to waf like [this](https://stackoverflow.com/a/68489503/13040392)? Directly modifying the waf scripts is a bit fragile. – Sagar Nov 29 '21 at 04:48
  • Do I have to write something like: `LDFLAGS=-L/home/davide/opencv-4.5.4/build/lib -lopencv_core -lopencv_ml` ? Do I need to keep the wscript modified? Do you have perhaps a link on how to use .waf parameters? – Davide Quaglio Nov 30 '21 at 10:11
  • Can you [edit] your answer to include the *exact* error message you obtain when building with `./waf`? – Sagar Nov 30 '21 at 18:30

0 Answers0