代码如下:
#include <stdio.h>
#include <math.h>
#include <vector>
float comp_cur(float A_x, float A_y, float B_x, float B_y, float C_x, float C_y);
void comp_arr(std::vector<float> vals, std::vector<float> out, int scale, float dim);
main(){
std::vector <float> curves;
std::vector <float> inputs;
inputs.push_back(2.0);
inputs.push_back(3.0);
inputs.push_back(6.0);
inputs.push_back(1.0);
inputs.push_back(7.0);
comp_arr(inputs,curves,1.0,1.0);
}
float comp_cur(float A_x, float A_y, float B_x, float B_y, float C_x, float C_y){
B_x = B_x-A_x;
B_y = B_y-A_y;
C_x = C_x-A_x;
C_y = C_y-A_y;
A_x = 0;
A_y = 0;
float numerator_A = C_y*B_x - B_y*C_x;
float denominator_A = C_x*C_x*B_x - C_x*B_x*B_x;
float A = numerator_A / denominator_A;
float B = (B_y - A*B_x*B_x) / B_x;
float curviture = 2*A / powf( (1 + (2*A*B_x + B)*(2*A*B_x + B)), 1.5);
return (curviture);
}
void comp_arr(std::vector<float> vals, std::vector<float> out, int scale, float dim){
for(int i = scale; i < sizeof(vals)-scale+1; i++){
float cur = comp_cur((i-scale)*dim, vals[i-1], i*dim, vals[i], (i+scale)*dim, vals[i+1]);
out.push_back(cur);
}
}
关于 comp_cur 的一切工作正常,但 comp_arr 函数抛出一个可怕的错误。我对 C 和 C++ 很陌生,所以我根本无法理解这个错误。
/tmp/ccTCZ2bX.o: In function `main':
comp.cpp:(.text+0x174): undefined reference to `__cxa_end_cleanup'
/tmp/ccTCZ2bX.o:(.ARM.extab+0x0): undefined reference to `__gxx_personality_v0'
/tmp/ccTCZ2bX.o: In function `std::vector<float, std::allocator<float> >::~vector()':
comp.cpp:(.text._ZNSt6vectorIfSaIfEED2Ev[_ZNSt6vectorIfSaIfEED5Ev]+0x6c): undefined reference to `__cxa_end_cleanup'
/tmp/ccTCZ2bX.o:(.ARM.extab.text._ZNSt6vectorIfSaIfEED2Ev[_ZNSt6vectorIfSaIfEED5Ev]+0x0): undefined reference to `__gxx_personality_v0'
/tmp/ccTCZ2bX.o: In function `std::vector<float, std::allocator<float> >::vector(std::vector<float, std::allocator<float> > const&)':
comp.cpp:(.text._ZNSt6vectorIfSaIfEEC2ERKS1_[_ZNSt6vectorIfSaIfEEC5ERKS1_]+0xb4): undefined reference to `__cxa_end_cleanup'
/tmp/ccTCZ2bX.o:(.ARM.extab.text._ZNSt6vectorIfSaIfEEC2ERKS1_[_ZNSt6vectorIfSaIfEEC5ERKS1_]+0x0): undefined reference to `__gxx_personality_v0'
/tmp/ccTCZ2bX.o: In function `std::_Vector_base<float, std::allocator<float> >::~_Vector_base()':
comp.cpp:(.text._ZNSt12_Vector_baseIfSaIfEED2Ev[_ZNSt12_Vector_baseIfSaIfEED5Ev]+0x70): undefined reference to `__cxa_end_cleanup'
/tmp/ccTCZ2bX.o:(.ARM.extab.text._ZNSt12_Vector_baseIfSaIfEED2Ev[_ZNSt12_Vector_baseIfSaIfEED5Ev]+0x0): undefined reference to `__gxx_personality_v0'
/tmp/ccTCZ2bX.o: In function `std::vector<float, std::allocator<float> >::_M_insert_aux(__gnu_cxx::__normal_iterator<float*, std::vector<float, std::allocator<float> > >, float const&)':
comp.cpp:(.text._ZNSt6vectorIfSaIfEE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPfS1_EERKf[std::vector<float, std::allocator<float> >::_M_insert_aux(__gnu_cxx::__normal_iterator< float*, std::vector<float, std::allocator<float> > >, float const&)]+0x290): undefined reference to `__cxa_end_catch'
comp.cpp:(.text._ZNSt6vectorIfSaIfEE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPfS1_EERKf[std::vector<float, std::allocator<float> >::_M_insert_aux(__gnu_cxx::__normal_iterator< float*, std::vector<float, std::allocator<float> > >, float const&)]+0x294): undefined reference to `__cxa_end_cleanup'
comp.cpp:(.text._ZNSt6vectorIfSaIfEE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPfS1_EERKf[std::vector<float, std::allocator<float> >::_M_insert_aux(__gnu_cxx::__normal_iterator< float*, std::vector<float, std::allocator<float> > >, float const&)]+0x2a0): undefined reference to `__cxa_begin_catch'
comp.cpp:(.text._ZNSt6vectorIfSaIfEE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPfS1_EERKf[std::vector<float, std::allocator<float> >::_M_insert_aux(__gnu_cxx::__normal_iterator< float*, std::vector<float, std::allocator<float> > >, float const&)]+0x308): undefined reference to `__cxa_rethrow'
/tmp/ccTCZ2bX.o:(.ARM.extab.text._ZNSt6vectorIfSaIfEE13_M_insert_auxEN9__gnu_cxx17__normal_iteratorIPfS1_EERKf[std::vector<float, std::allocator<float> >::_M_insert_aux(__gnu_cxx::__normal_iterator<float*, std::vector<float, std::allocator<float> > >, float const&)]+0x0): undefined reference to `__gxx_personality_v0'
/tmp/ccTCZ2bX.o: In function `std::_Vector_base<float, std::allocator<float> >::_Vector_base(unsigned int, std::allocator<float> const&)':
comp.cpp:(.text._ZNSt12_Vector_baseIfSaIfEEC2EjRKS0_[_ZNSt12_Vector_baseIfSaIfEEC5EjRKS0_]+0x90): undefined reference to `__cxa_end_cleanup'
/tmp/ccTCZ2bX.o:(.ARM.extab.text._ZNSt12_Vector_baseIfSaIfEEC2EjRKS0_[_ZNSt12_Vector_baseIfSaIfEEC5EjRKS0_]+0x0): undefined reference to `__gxx_personality_v0'
/tmp/ccTCZ2bX.o: In function `std::vector<float, std::allocator<float> >::_M_check_len(unsigned int, char const*) const':
comp.cpp:(.text._ZNKSt6vectorIfSaIfEE12_M_check_lenEjPKc[std::vector<float, std::allocator<float> >::_M_check_len(unsigned int, char const*) const]+0x54): undefined reference to `std::__throw_length_error(char const*)'
/tmp/ccTCZ2bX.o: In function `__gnu_cxx::new_allocator<float>::deallocate(float*, unsigned int)':
comp.cpp:(.text._ZN9__gnu_cxx13new_allocatorIfE10deallocateEPfj[__gnu_cxx::new_allocator<float>::deallocate(float*, unsigned int)]+0x1c): undefined reference to `operator delete(void*)'
/tmp/ccTCZ2bX.o: In function `__gnu_cxx::new_allocator<float>::allocate(unsigned int, void const*)':
comp.cpp:(.text._ZN9__gnu_cxx13new_allocatorIfE8allocateEjPKv[__gnu_cxx::new_allocator<float>::allocate(unsigned int, void const*)]+0x40): undefined reference to `std::__throw_bad_alloc()'
comp.cpp:(.text._ZN9__gnu_cxx13new_allocatorIfE8allocateEjPKv[__gnu_cxx::new_allocator<float>::allocate(unsigned int, void const*)]+0x50): undefined reference to `operator new(unsigned int)'
collect2: ld returned 1 exit status