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.