我想从 Qt GUI 应用程序运行 Octave 脚本。
这是.pro
文件:
...
win32 {
INCLUDEPATH += c:/Octave/Octave-4.2.1/include/octave-4.2.1/octave
LIBS += c:/Octave/Octave-4.2.1/lib/octave/4.2.1/liboctave.dll.a \
c:/Octave/Octave-4.2.1/lib/octave/4.2.1/liboctinterp.dll.a
DEPENDPATH += c:/Octave/Octave-4.2.1/bin
}
...
这里是 .cpp
文件(示例取自 docs ):
#include <iostream>
#include <octave/oct.h>
#include <octave/octave.h>
#include <octave/parse.h>
#include <octave/interpreter.h>
int
main (void)
{
string_vector argv (2);
argv(0) = "embedded";
argv(1) = "-q";
octave_main (2, argv.c_str_vec (), 1);
octave_idx_type n = 2;
octave_value_list in;
for (octave_idx_type i = 0; i < n; i++)
in(i) = octave_value (5 * (i + 2));
octave_value_list out = feval ("gcd", in, 1);
if (out.length () > 0)
std::cout << "GCD of ["
<< in(0).int_value ()
<< ", "
<< in(1).int_value ()
<< "] is " << out(0).int_value ()
<< std::endl;
else
std::cout << "invalid\n";
clean_up_and_exit (0);
}
当我尝试从 Qt Creator 编译 C++ 代码时,出现以下错误:
undefined reference to feval(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, octave_value_list const&, int)
编译器还出现以下错误:
undefined reference to Array<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::nil_rep()
undefined reference to Array<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::resize_fill_value() const
undefined reference to Array<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::resize_fill_value() const
但是当我按住 Ctrl 键并单击 Array
或 feval
时 - Qt Creator 将打开相应的文件。
我还可以使用 Octave GUI 中的以下命令编译示例 C++ 文件:
mkoctfile --link-stand-alone embedded.cc -o embedded
我应该添加什么库/路径?
提前非常感谢您。
最佳答案
如果您在上面的示例中以详细方式运行 mkoctfile(我将其复制到 main.cc 中),您将看到所需的所有标志:
mkoctfile -v --link-stand-alone main.cc
g++ -std=gnu++11 -c -fPIC -I/usr/local/include/octave-4.2.0/octave/.. -I/usr/local/include/octave-4.2.0/octave -I/usr/local/include -pthread -fopenmp -g -O2 main.cc -o main.o
g++ -std=gnu++11 -I/usr/local/include/octave-4.2.0/octave/.. -I/usr/local/include/octave-4.2.0/octave -I/usr/local/include -pthread -fopenmp -g -O2 -rdynamic -fPIC main.o -L/usr/local/lib/octave/4.2.0 -L/usr/local/lib -loctinterp -loctave
现在您必须将这些添加到您的 QtCreator 中。 (我猜 -std=gnu++11 丢失了)
关于c++ - 来自 QT 的 Octave : undefined reference,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44160846/