Find the answer to your Linux question:
Results 1 to 2 of 2
Hi All, im compiling using g++,the compiler is reporting error as undefined reference to `svm_destroy_model' here is my sample code Code: /********svm.h***********/ #ifndef _LIBSVM_H #define _LIBSVM_H #define LIBSVM_VERSION 288 #ifdef ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2011
    Posts
    4

    undefined reference problem for a function


    Hi All,
    im compiling using g++,the compiler is reporting error as
    undefined reference to `svm_destroy_model'
    here is my sample code
    Code:
    /********svm.h***********/
    #ifndef _LIBSVM_H
    #define _LIBSVM_H
    
    #define LIBSVM_VERSION 288
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    struct svm_model
    {
    .
    .
    };
    void svm_destroy_model(struct svm_model *model);
    .
    .
    #ifdef __cplusplus
    }
    #endif
    
    #endif // _LIBSVM_H 
    
    /********svm.cpp******/
    void svm_binary_svc_probability(const svm_problem *prob, const svm_parameter *param, double Cp, double Cn, double& probA, double& probB)//this function is defined globally(line 1892)
    {
    .
    .
    .
    svm_destroy_model(submodel);//line 1966
    .
    .
    .
    }
    int svm_cross_validation(const svm_problem *prob, const svm_parameter *param, int nr_fold, double *target)//this function is defined globally
    {
    .
    .
    svm_destroy_model(submodel);//line 2488
    .
    .
    }
    
    void svm_destroy_model(svm_model* model)//defined globally(line 2970)
    {
    .
    .
    .
    .
    }
    i have tried including body of function svm_destroy_model before line 1892 and including the prototype of the function but no use .....please help me in identifying this error
    waiting for your reply.....................
    thanx

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,755
    So, you want svm_destroy_model(svm_model*) to have C rather than C++ bindings? Why? What is the purpose of that? In any case, if you want to use C bindings you still need to extern "C" the function, as in:
    Code:
    extern "C" void svm_destroy_model(struct svm_model* model)
    {
    .
    .
    .
    }
    Otherwise, you have a C-binding declaration, but a C++ definition, which in reality has a totally different function signature, hence the compiler/linker error.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •