###前提・実現したいこと
C++で配列を扱おうと思い、octaveをインストールしました。そしてcppのコードにoctaveに
含まれているものをincludeして簡単な配列を表示しようとしています。
###発生している問題・エラーメッセージ
コンパイルする際に下記のようなエラーが生じてしまいました。
$ g++ main.cpp Undefined symbols for architecture x86_64: "Array<double>::fill(double const&)", referenced from: Array<double>::Array(dim_vector const&, double const&) in main-7e0d24.o "dim_vector::safe_numel() const", referenced from: Array<double>::Array(dim_vector const&) in main-7e0d24.o Array<double>::Array(dim_vector const&, double const&) in main-7e0d24.o "ColumnVector::transpose() const", referenced from: _main in main-7e0d24.o "Array<double>::resize_fill_value() const", referenced from: vtable for Matrix in main-7e0d24.o vtable for NDArray in main-7e0d24.o vtable for MArray<double> in main-7e0d24.o vtable for Array<double> in main-7e0d24.o vtable for ColumnVector in main-7e0d24.o "operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, Matrix const&)", referenced from: _main in main-7e0d24.o "operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, RowVector const&)", referenced from: _main in main-7e0d24.o "operator*(Matrix const&, ColumnVector const&)", referenced from: _main in main-7e0d24.o "MArray<double> operator+<double>(MArray<double> const&, MArray<double> const&)", referenced from: operator+(ColumnVector const&, ColumnVector const&) in main-7e0d24.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
###該当のソースコード
cpp
1#include <octave/config.h> 2#include <octave/Matrix.h> 3#include <iostream> 4using namespace std; 5int main(int argc, char**argv) 6{ 7 Matrix A(2,3), B(2,2,1.0); 8 ColumnVector x(3), y(2), z(2); 9 for(int r(0); r<2; ++r) 10 for(int c(0); c<3; ++c) 11 A(r,c) = r+c; 12 for(int r(0); r<3; ++r) x(r)=(r+1.0)*2.0; 13 for(int r(0); r<2; ++r) y(r)=(r+1.0)*r; 14 z = B*(A*x+y); 15 cout<<"A="<<endl; 16 cout<<A; 17 cout<<"B="<<endl; 18 cout<<B; 19 cout<<"x= "<<x.transpose()<<endl; 20 cout<<"y="<<y.transpose()<<endl; 21 cout<<"z="<<z.transpose()<<endl; 22 return 0; 23}
###試したこと
includeとlibはしっかりと読み込めるように、コンパイルされている場所にエイリアスを作成しました。ですが、この問題の解決にはつながらなかったようです。
Opencv以外には他のライブラリを利用したことがないようなcppの初心者ですので、わかりやすく教えていただけると幸いです。コードはこちらのサイトに記載されていたものを参考にさせてもらいました。http://d.hatena.ne.jp/aki-yam/20080721/1218193668
よろしくお願いします。
###補足情報(言語/FW/ツール等のバージョンなど)
octave 4.0.3
###追記
回答していただいた内容を活かして修正したコンパイルのログです。
ヘッダとライブラリを含めてコンパイルはできたと思うのですが、どうにもエラーがなくなりません。
gcc -g -Wall main.cpp -I/usr/local/include/octave-4.2.0/octave -I/usr/local/Cellar/octave/4.2.0/binoctave-'octave-config -v' -L/usr/local/lib/octave/4.2.0 -O0 In file included from main.cpp:2: /usr/local/include/octave-4.2.0/octave/config.h:28:2: warning: "config.h has been deprecated; there is no need to include it directly" [-W#warnings] #warning "config.h has been deprecated; there is no need to include it directly" ^ In file included from main.cpp:3: In file included from /usr/local/include/octave-4.2.0/octave/Matrix.h:32: In file included from /usr/local/include/octave-4.2.0/octave/mx-base.h:30: In file included from /usr/local/include/octave-4.2.0/octave/MatrixType.h:29: In file included from /usr/local/include/octave-4.2.0/octave/MSparse.h:31: In file included from /usr/local/include/octave-4.2.0/octave/Sparse.h:37: In file included from /usr/local/include/octave-4.2.0/octave/Array.h:37: /usr/local/include/octave-4.2.0/octave/dim-vector.h:205:21: warning: variadic templates are a C++11 extension [-Wc++11-extensions] template <typename... Ints> ^ /usr/local/include/octave-4.2.0/octave/dim-vector.h:209:10: error: no member named 'initializer_list' in namespace 'std' std::initializer_list<octave_idx_type> all_lengths = {r, c, lengths...}; ~~~~~^ /usr/local/include/octave-4.2.0/octave/dim-vector.h:209:27: error: unexpected type name 'octave_idx_type': expected expression std::initializer_list<octave_idx_type> all_lengths = {r, c, lengths...}; ^ /usr/local/include/octave-4.2.0/octave/dim-vector.h:209:44: error: use of undeclared identifier 'all_lengths' std::initializer_list<octave_idx_type> all_lengths = {r, c, lengths...}; ^ /usr/local/include/octave-4.2.0/octave/dim-vector.h:209:58: error: expected expression std::initializer_list<octave_idx_type> all_lengths = {r, c, lengths...}; ^ /usr/local/include/octave-4.2.0/octave/dim-vector.h:210:33: warning: range-based for loop is a C++11 extension [-Wc++11-extensions] for (const octave_idx_type l: all_lengths) ^ /usr/local/include/octave-4.2.0/octave/dim-vector.h:210:35: error: use of undeclared identifier 'all_lengths' for (const octave_idx_type l: all_lengths) ^ /usr/local/include/octave-4.2.0/octave/dim-vector.h:212:12: error: use of undeclared identifier 'all_lengths' rep -= all_lengths.size (); ^ In file included from main.cpp:3: In file included from /usr/local/include/octave-4.2.0/octave/Matrix.h:32: In file included from /usr/local/include/octave-4.2.0/octave/mx-base.h:30: In file included from /usr/local/include/octave-4.2.0/octave/MatrixType.h:29: In file included from /usr/local/include/octave-4.2.0/octave/MSparse.h:31: In file included from /usr/local/include/octave-4.2.0/octave/Sparse.h:37: /usr/local/include/octave-4.2.0/octave/Array.h:282:30: warning: variadic templates are a C++11 extension [-Wc++11-extensions] template<template <typename...> class Container> ^ /usr/local/include/octave-4.2.0/octave/Array.h:861:28: warning: variadic templates are a C++11 extension [-Wc++11-extensions] template<template <typename...> class Container> ^ /usr/local/include/octave-4.2.0/octave/Array.h:876:19: warning: range-based for loop is a C++11 extension [-Wc++11-extensions] for (const T& x : a) ^ In file included from main.cpp:3: In file included from /usr/local/include/octave-4.2.0/octave/Matrix.h:32: In file included from /usr/local/include/octave-4.2.0/octave/mx-base.h:35: In file included from /usr/local/include/octave-4.2.0/octave/chMatrix.h:32: In file included from /usr/local/include/octave-4.2.0/octave/chNDArray.h:35: /usr/local/include/octave-4.2.0/octave/str-vec.h:59:30: warning: variadic templates are a C++11 extension [-Wc++11-extensions] template<template <typename...> class String_Container, typename... Other> ^ /usr/local/include/octave-4.2.0/octave/str-vec.h:59:67: warning: variadic templates are a C++11 extension [-Wc++11-extensions] template<template <typename...> class String_Container, typename... Other> ^ /usr/local/include/octave-4.2.0/octave/str-vec.h:130:28: warning: variadic templates are a C++11 extension [-Wc++11-extensions] template<template <typename...> class String_Container, typename... Other> ^ /usr/local/include/octave-4.2.0/octave/str-vec.h:130:65: warning: variadic templates are a C++11 extension [-Wc++11-extensions] template<template <typename...> class String_Container, typename... Other> ^ /usr/local/include/octave-4.2.0/octave/str-vec.h:138:29: warning: range-based for loop is a C++11 extension [-Wc++11-extensions] for (const std::string& s : lst) ^ In file included from main.cpp:3: In file included from /usr/local/include/octave-4.2.0/octave/Matrix.h:34: In file included from /usr/local/include/octave-4.2.0/octave/mx-ext.h:54: /usr/local/include/octave-4.2.0/octave/svd.h:43:12: warning: scoped enumerations are a C++11 extension [-Wc++11-extensions] enum class Type ^ /usr/local/include/octave-4.2.0/octave/svd.h:50:12: warning: scoped enumerations are a C++11 extension [-Wc++11-extensions] enum class Driver ^ 13 warnings and 6 errors generated.
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/11/17 13:09
2016/11/17 14:26
2016/11/18 05:46 編集
2016/11/18 07:17
2016/11/18 15:33