LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   undefined reference problem (https://www.linuxquestions.org/questions/programming-9/undefined-reference-problem-909270/)

shamjs 10-21-2011 12:21 AM

undefined reference problem
 
Hi all,
compiler is reporting error as
undefined reference to `svm_check_parameter'
here is my code
Code:

/********svm.h**************/
#ifndef _LIBSVM_H
#define _LIBSVM_H

#ifdef __cplusplus
extern "C" {
#endif
.
.
struct svm_problem
{
.
.
};
struct svm_parameter
{
.
.
};
.
.
const char *svm_check_parameter(const struct svm_problem *prob, const struct svm_parameter *param);
.
.
#ifdef __cplusplus
}
#endif

#endif

/**********svm.cpp**********/
const char *svm_check_parameter(const svm_problem *prob, const svm_parameter *param)//this function is defined globally
{
.
.
.
.
}

i dont know what as went wrong(i think its not due to name mangling )plz let me know where is the fault..........
thanx for sharing your time.....

NevemTeve 10-21-2011 02:34 AM

Quote:

Originally Posted by shamjs (Post 4504007)
Hi all,
compiler is reporting error as
undefined reference to `svm_check_parameter'

You should generate svm.o, and add it to the linkage.

shamjs 10-21-2011 03:44 AM

how can i generate the object file of svm.cpp since i dont have main function written in svm.cpp
the compiler
will report error as
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status

im compiling by giving g++ -o svm svm.cpp

NevemTeve 10-21-2011 03:48 AM

Code:

g++ -W -Wall -pedantic -g -o svm.o -c svm.cpp
g++ -W -Wall -pedantic -g -o mymainprogram mymainprogam.cpp svm.o


shamjs 10-21-2011 04:16 AM

thanx lot for providing me the hint ,it helped me a lot.................

actually i have to compile using
Code:

g++ -fPIC -c svm.cpp
and then finally i have to link for my main.cpp

thanx for the support, i like this forun a lot.................................

NevemTeve 10-21-2011 04:29 AM

Well, -fPIC is not essential, when building an executable, but it doesn't hurt either. Don't omit the '-W -Wall -pedantic' part though, it will save your life many times. The same goes for the '-g' which enables debugging.


All times are GMT -5. The time now is 07:30 PM.