如何在 C++ 代码中使用 SVM Light? (可能不从 C++ 代码调用可执行文件)

How is it possible use SVM Light inside the C++ code? (Possibly without invoking the executable from C++ code)

我必须在我的 C++ 代码中使用 SVM Light 工具。我像在 http://svmlight.joachims.org/ 中那样编译并链接了 SVM Light 到我的代码,但现在我如何调用

./svm_learn -v 0 -x 1  example1/train.dat example1/model

例如从我的 C++ 代码而不是从命令行? 即在原代码中加上

./svm_learn -v 0 -x 1  example1/train.dat example1/model

我得到了支持向量机模型。我现在如何从我的 C++ 代码中获得相同的模型?最好从我的 C++ 代码中调用函数而不是从命令行调用可执行文件? (可能是我被迫使用系统或类似函数从我的 C++ 代码中调用 C 对象代码(可执行文件)....是这样的吗?)

(我在 Linux 上使用 C++11 编译器) 提前致谢

此 link http://svmlight.joachims.org/ 在页面底部附近的“扩展和添加”下有一个 DLL 接口。我将从那里开始。

更好的是,在版本历史下,在 V6.01 - V6.02 下第二句说 "Updated makefile to add the ability for compiling SVM-light into a shared-object library that gives external code easy access to learning and classification functions." 这个库接口应该被记录下来。

我从自己身上找到了可能的解决方案。我 post 在这里为任何人感兴趣。我修改了svm_learn_main.c,我在这里留下了一个空的main。我添加了一个新文件 svm_mylearn.c 和 svm_mylearn.h 。我在svm_mylearn.c中复制了原来的svm_learn_main.c。我在此处的外部声明中添加了 header svm_mylearn.h。我在 svm_mylearn.h 中移动了函数的签名。我用与 main 相同的代码更改了 svm_my_exec(int,char* []) 中 main 函数的名称。我修改了 makefile,因此为 svm_mylearn.c 创建了 object 代码(.o) 稍后命名我的 .cpp 文件 Test.cpp 我必须做的:

make all
g++ -c Test.cpp
g++ Test.o svm_learn.o svm_common.o svm_hideo.o svm_mylearn.o    (linking)
./a.out

此外,我忘记了在 Test.cpp 中我必须添加这样的外部声明:

extern "C" 
{
# include "svm_common.h"
# include "svm_learn.h"
# include "svm_mylearn.h"
} 

并以这种方式调用 svm_my_exec 函数(例如):

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 );