[英]Octave from QT: undefined reference
我想從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
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丟失了)
從錯誤看來gcd
函數不存在,或者找不到它的引用。 我不知道gcd
函數是八度音階的一部分還是您自定義定義的,但是肯定缺少對它的引用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.