2013-02-12 1 views
1

의 이해 할 수없는 오류가 있습니다 : comp_cur에 대한사용하여 벡터는 나에게 나는 다음과 같은 코드는

#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_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 
+4

연결 단계가 C++ 표준 라이브러리와 연결되어 있지 않은 것 같습니다. –

+0

패스 바이 패스를 사용중인 것 같습니다. 하나의 참조를 사용하거나 포인터를 사용하십시오. [위키] (http://en.wikipedia.org/wiki/Reference_ (C % 2B % 2B)) –

+1

전체 명령 줄을주십시오. 그리고 예, 참조에 의해'vector's를 ('comp_arr'에 인수 목록에있는'std :: vector const & vals' 등) – Walter

답변

3

나는 당신이 어떻게 컴파일하고 있는지 알지 못하는 사이에 교양있는 추측을 할 것입니다. 자동 g++ 표준 라이브러리에 링크를 포함하여, 당신을 위해 C++를 컴파일하기위한 몇 가지 옵션을 설정 -

g++보다는 gcc 컴파일해야합니다. 또는 -lstdc++-x c++ 옵션을 제공하십시오.