I have to use the tool SVM Light in my C++ code. I compiled and linked the SVM Light to my code like in http://svmlight.joachims.org/ but now how can I call
./svm_learn -v 0 -x 1 example1/train.dat example1/model
for example from my C++ code instead that from command line? Namely in the original code with
./svm_learn -v 0 -x 1 example1/train.dat example1/model
i get the svm model. How can I get now the same model from my C++ code?Preferably calling a function from my C++ code rather than calling the executable from command line? (May be that I'm enforced to use system or similar functions to invoke the C object code (the executable) from my c++ code.... Is like this?)
(I'm using C++11 compiler, on Linux) Thanks in advance
I found a possible solution from myself. I post here for anyone was interested. I modified svm_learn_main.c, I left here a empty main alone. I added a new file svm_mylearn.c and svm_mylearn.h . I copied the original svm_learn_main.c in svm_mylearn.c. I added here in the extern declaration the header svm_mylearn.h. I moved the signature of functions in svm_mylearn.h . I changed the name of the main function in svm_my_exec(int,char* []) with the same code of the main. I modified the makefile so create the object code (the .o) for svm_mylearn.c Later naming my .cpp file Test.cpp i have to do:
make all
g++ -c Test.cpp
g++ Test.o svm_learn.o svm_common.o svm_hideo.o svm_mylearn.o (linking)
./a.out
Furthemore, I was forgetting that in Test.cpp I have to add a extern declaration like this:
extern "C"
{
# include "svm_common.h"
# include "svm_learn.h"
# include "svm_mylearn.h"
}
and call the svm_my_exec function in this way(for example) :
const char *comando[]={"./svm_learn" ,"-v", "1", "-x", "1", "-o",
"2.0", "-k" ,"100", "example1/train.dat", "example1/model"};
svm_my_exec(sizeof(comando)/sizeof(char *),comando );