実現したいこと
ベクトルや回転行列のコンストラクタ定義
前提
C++でプログラムを書きました。
cygwin64で実行したところ、以下の文章がでてきました。
どこを修正すればよいのでしょうか。
検索しても私には解決できませんでした。
発生している問題・エラーメッセージ
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /tmp/cc39sBk1.o:vector.cpp:(.text+0xc88): undefined reference to `Matrix4d::Matrix4d()' /usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /tmp/cc39sBk1.o:vector.cpp:(.text+0xd38): undefined reference to `Matrix4d::set(double (*) [4])' /usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /tmp/cc39sBk1.o:vector.cpp:(.text+0xd6a): undefined reference to `Matrix4d::Matrix4d()' /usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /tmp/cc39sBk1.o:vector.cpp:(.text+0xe1a): undefined reference to `Matrix4d::set(double (*) [4])' /usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /tmp/cc39sBk1.o:vector.cpp:(.text+0xe4c): undefined reference to `Matrix4d::Matrix4d()' /usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /tmp/cc39sBk1.o:vector.cpp:(.text+0xefc): undefined reference to `Matrix4d::set(double (*) [4])' /usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /tmp/cc39sBk1.o:vector.cpp:(.text+0xf29): undefined reference to `Matrix4d::Matrix4d()' /usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /tmp/cc39sBk1.o:vector.cpp:(.text+0xf74): undefined reference to `Matrix4d::set(double (*) [4])' /usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /tmp/cc39sBk1.o:vector.cpp:(.text+0xfa6): undefined reference to `Matrix4d::Matrix4d()' /usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /tmp/cc39sBk1.o:vector.cpp:(.text+0xff5): undefined reference to `Matrix4d::set(double (*) [4])' /usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /usr/lib/../lib/libcygwin.a(libcmain.o): in function `main': /usr/src/debug/cygwin-3.4.6-1/winsup/cygwin/lib/libcmain.c:37: undefined reference to `WinMain' collect2: error: ld returned 1 exit status
該当のソースコード
C++
1#include <iostream> 2using namespace std; 3#include <stdio.h> 4#include <math.h> 5#include "vector.h" 6 7 8//=========================================================== Vector2d 9//----------------------------------------------- constructors 10Vector2d::Vector2d( void ) {} 11 12Vector2d::Vector2d( double xx, double yy ) { 13 x( xx ); y( yy ); 14} 15 16//-------------------------------------------------- accessors 17double Vector2d::x( void ) { return _x; } 18double Vector2d::y( void ) { return _y; } 19double Vector2d::x( double xx ) { _x = xx; return xx; } 20double Vector2d::y( double yy ) { _y = yy; return yy; } 21 22//------------------------------------- other member functions 23void Vector2d::print( void ) 24{ 25 cout << "(" << x() << "," << y() << ")"; 26} 27 28char *Vector2d::princ( void ) 29{ 30 static char s[128]; 31 sprintf(s, "(%.1lf, %.1lf)", x(), y()); 32 return( s ); 33} 34 35//----------------------------------------- operator functions 36Vector2d operator+( Vector2d v1, Vector2d v2 ) 37{ 38 Vector2d v3( v1.x()+v2.x(), v1.y()+v2.y() ); 39 return( v3 ); 40} 41 42Vector2d operator-( Vector2d v1, Vector2d v2 ) 43{ 44 Vector2d v3( v1.x()-v2.x(), v1.y()-v2.y() ); 45 return( v3 ); 46} 47 48Vector2d operator*( Vector2d v, double a ) 49{ 50 Vector2d v3( v.x() * a, v.y() * a ); 51 return( v3 ); 52} 53 54Vector2d operator*( double a, Vector2d v) 55{ 56 return( v*a ); 57} 58 59double operator,( Vector2d v1, Vector2d v2 ) 60{ 61 return( v1.x()*v2.x() + v1.y()*v2.y() ); 62} 63 64ostream& operator<<( ostream &os, Vector2d v ) 65{ 66 return( os << "(" << v.x() << "," << v.y() << ")" ); 67} 68 69 70//=========================================================== Vector3d 71//----------------------------------------------- constructors 72Vector3d::Vector3d( void ) {} 73 74Vector3d::Vector3d( double xx, double yy, double zz ) { 75 x( xx ); y( yy ); z( zz ); 76} 77 78void Vector3d::print( void ) 79{ 80 cout << "(" << x() << "," << y() << "," << z() << ")"; 81} 82 83//-------------------------------------------------- accessors 84double Vector3d::x( void ) { return _x; } 85double Vector3d::y( void ) { return _y; } 86double Vector3d::z( void ) { return _z; } 87double Vector3d::x( double xx ) { _x = xx; return xx; } 88double Vector3d::y( double yy ) { _y = yy; return yy; } 89double Vector3d::z( double zz ) { _z = zz; return zz; } 90 91//----------------------------------------- operator functions 92Vector3d operator+( Vector3d v1, Vector3d v2 ) 93{ 94 Vector3d v3( v1.x()+v2.x(), v1.y()+v2.y(), v1.z()+v2.z() ); 95 return( v3 ); 96} 97 98Vector3d operator-( Vector3d v1, Vector3d v2 ) 99{ 100 Vector3d v3( v1.x()-v2.x(), v1.y()-v2.y(), v1.z()-v2.z() ); 101 return( v3 ); 102} 103 104Vector3d operator*( Vector3d v, double a ) 105{ 106 Vector3d v3( v.x() * a, v.y() * a, v.z() * a ); 107 return( v3 ); 108} 109 110Vector3d operator*( double a, Vector3d v) 111{ 112 return( v*a ); 113} 114 115double operator,( Vector3d v1, Vector3d v2 ) 116{ 117 return( v1.x()*v2.x() + v1.y()*v2.y() + v1.z()*v2.z() ); 118} 119 120Vector3d operator*( Vector3d v1, Vector3d v2 ) 121{ 122 Vector3d v3; 123 124 v3.x( v1.y()*v2.z() - v1.z()*v2.y() ); 125 v3.y( v1.z()*v2.x() - v1.x()*v2.z() ); 126 v3.z( v1.x()*v2.y() - v1.y()*v2.x() ); 127 return( v3 ); 128} 129 130ostream& operator<<( ostream &os, Vector3d v ) 131{ 132 return( os << "(" << v.x() << "," << v.y() << "," << v.z() << ")" ); 133} 134 135 136 137//Rotation_z::Rotation_z(void){} 138Rotation_z::Rotation_z(double theta){ 139 double mm[4][4] = { cos(theta), -sin(theta), 0, 0, 140 sin(theta), cos(theta), 0, 0, 141 0, 0, 1, 0, 142 0, 0, 0, 1 }; 143 set(mm); 144} 145//-------------------------------------constructors 146Rotation_x::Rotation_x(double theta){ 147 double mm[4][4] = { 1, 0, 0, 0, 148 0, cos(theta), -sin(theta), 0, 149 0, sin(theta), cos(theta), 0, 150 0, 0, 0, 1 }; 151 set(mm); 152} 153 154Rotation_y::Rotation_y(double theta){ 155 double mm[4][4] = { cos(theta), 0, sin(theta), 0, 156 0, 1, 0, 0, 157 -sin(theta), 0, cos(theta), 0, 158 0, 0, 0, 1 }; 159 set(mm); 160} 161 162Orthogonal::Orthogonal(void){ 163 double mm[4][4] = { 0, 0, 0, 0, 164 0, 1, 0, 0, 165 0, 0, 1, 0, 166 0, 0, 0, 1 }; 167 set(mm); 168} 169 170Perspective::Perspective(double d){ 171 double mm[4][4] = { 0, 0, 0, 0, 172 0, d, 0, 0, 173 0, 0, d, 0, 174 -1, 0, 0, d }; 175 set(mm); 176} 177
C++
1コード 2#ifndef VECTOR_H 3#define VECTOR_H 4 5#include <iostream> 6#include <stdio.h> 7using namespace std; 8 9~中略~ 10 11//=============================================== Vector4d 12class Vector4d { 13private: 14 double _v[4]; 15public: 16 //---------------------------------------- constructors 17 Vector4d(void); 18 Vector4d(double xx, double yy, double zz, double ww); 19 Vector4d(double vv[4]); 20 //---------------------------------------- accessors 21 double x(void); 22 double y(void); 23 double z(void); 24 double *v(void) {return &_v[0];} 25 double w(void); 26 double x(double xx); 27 double y(double yy); 28 double z(double zz); 29 double w(double ww); 30 void set(double a[4]); 31 //---------------------------------------- other member functions 32 void print(void); 33}; 34 35//------------------------------------------ operator functions 36ostream& operator<<(ostream &os, Vector4d v); // stream output 37 38//================================================= Matrix4d 39class Matrix4d { 40private: 41 double _m[4][4]; 42public: 43 //----------------------------------------- constructors 44 Matrix4d(void); 45 Matrix4d(double m00, double m01, double m02, double m03, 46 double m10, double m11, double m12, double m13, 47 double m20, double m21, double m22, double m23, 48 double m30, double m31, double m32, double m33); 49 Matrix4d(double mm[4][4]); 50 //----------------------------------------- accessors 51 double *m(void) { return &_m[0][0]; } 52 //----------------------------------------- other member functions 53 void set(double mm[4][4]); 54 Vector4d operator*(Vector4d v); 55 Matrix4d operator*(Matrix4d mm); 56 void print(void); 57}; 58 59//================================================= Rotation_z 60class Rotation_z : public Matrix4d { 61public: 62 //----------------------------------------- constructors 63 Rotation_z(double theta); 64}; 65 66//================================================= Rotation_x 67class Rotation_x : public Matrix4d { 68public: 69 //----------------------------------------- constructors 70 Rotation_x(double theta); 71}; 72 73//================================================= Rotation_y 74class Rotation_y : public Matrix4d { 75public: 76 //----------------------------------------- constructors 77 Rotation_y(double theta); 78}; 79 80//================================================= Orthogonal 81class Orthogonal : public Matrix4d { 82public: 83 //----------------------------------------- constructors 84 Orthogonal(void); 85}; 86 87//================================================ Perspective 88class Perspective : public Matrix4d { 89public: 90 //----------------------------------------- constructors 91 Perspective(double distance); 92}; 93 94#endif /* VECTOR_H */ 95 96
試したこと
#include <math.h>を書いたらこうなりました。
補足情報(FW/ツールのバージョンなど)
visual studio
cygwin64
どういうコマンドラインでコンパイルしていますか。

回答1件
あなたの回答
tips
プレビュー