Undefined symbols for architecture x86_64

Apr 11, 2016 at 11:58am
Hello,

I have a linking problem. Would you please help me understand what is going wrong here?

I checked all the member function definitions and prototypes and their arguments, and could not figure out why I have this problem.

Thanks,
mmgh

Undefined symbols for architecture x86_64:
"MyProgram::class1<double>::run()", referenced from:
MyProgram::class2::Run(__sFILE*, __sFILE*, int, int, double, int, bool, double const*, int, char const*, char const*, double, bool) in tool.cpp.o
"MyProgram::class1<double>::setParam(std::__1::vector<double, std::__1::allocator<double> >)", referenced from:
MyProgram::class2::Run(__sFILE*, __sFILE*, int, int, double, int, bool, double const*, int, char const*, char const*, double, bool) in tool.cpp.o
"MyProgram::class1<double>::class1(std::__1::function<double (double*)>, std::__1::vector<double, std::__1::allocator<double> >, std::__1::vector<double, std::__1::allocator<double> >, std::__1::vector<double, std::__1::allocator<double> >)", referenced from:
MyProgram::class2::Run(__sFILE*, __sFILE*, int, int, double, int, bool, double const*, int, char const*, char const*, double, bool) in tool.cpp.o
"MyProgram::class1<double>::getBestParam() const", referenced from:
MyProgram::class2::Run(__sFILE*, __sFILE*, int, int, double, int, bool, double const*, int, char const*, char const*, double, bool) in tool.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [bin/MyProgram] Error 1
make[1]: *** [src/programs/MyProgram/CMakeFiles/MyProgram.dir/all] Error 2
make: *** [all] Error 2




Apr 11, 2016 at 12:05pm
"MyProgram::class1<double>::run()", referenced from:
MyProgram::class2::Run(__sFILE*, __sFILE*, int, int, double, int, bool, double const*, int, char const*, char const*, double, bool) in tool.cpp.o

This says that MyProgram::class2::Run() calls MyProgram::class1<double>:run(), but MyProgram::class1<double>::run() does not exist. Go find where MyProgram::class1<double>::run() is supposed to be defined and figure out why it isn't.

The other errors are similar.
Apr 11, 2016 at 2:36pm
Thanks for your reply.

The problem is that I wrote the function prototypes for the two classes in one header file and all the definitions are in one .cpp file. The functions exit and are defined. I don't know why the compiler dose not see them :(

Best,
mmgh
Apr 11, 2016 at 2:51pm
Are they defined in tool.cpp? That's where the error is occurring. If they are then please post the definitions.
Apr 11, 2016 at 3:05pm
They are written as a separate module and the corresponding header file is included in tool.cpp.

module.h
module.cpp
tool.cpp

class 1 is written in module.h and module.cpp, and class 2 is defined in too.cpp.

The Run function in class 2 is something like this:

Run()
{
class1 object;
obejct.run();
object.setParam();
object.getBestParam();
}

run, setParam, and getBestParam are the functions of class 1 which are written in module.h and module.cpp. module.h is included in tool.cpp.


Apr 11, 2016 at 8:41pm
The template functions should be in the header file, not the cpp file.
Apr 11, 2016 at 10:37pm
Oh! that was the point. thank you so much. It is compiled now. :)
Topic archived. No new replies allowed.