c++ - 来自 QT 的 Octave : undefined reference

标签 c++ qt linker embedded octave

我想从 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 键并单击 Arrayfeval 时 - 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/

相关文章:

c++ - 标题困惑。编译器不识别数据类型

c++ - QT query.exec() 始终返回 false

c++ - QT/SQLITE-数据库上的奇怪符号?

C++ 共享库 : Pure virtual function does not cause link error

c++ - 使用#ifndef 时具体定义了什么

linux - 在 makefile 中设置共享库的路径以进行编译

安卓 native OGLES2 : esLoadProgram not declared

c++ - cudaMallocManaged 用于主机启动的变量

qt - 鼠标交互的设计模式

c++ - 如何使用 C++ 在 opencv 中训练我自己的 svm?