Linker errors

Hello,


I would like to get your thoughts on the following linker errors I am getting for the code segment reproduced below. The code was compiled using the following command on macOS High Sierra 10.13.2:

g++ -ggdb -Wall -std=c++11 database.cpp error.cpp func_objs.cpp main.cpp sampler.cpp -o DB_sampler

The following are the linker errors that I get:

Undefined symbols for architecture x86_64:
  "sampler<database>::generate_sample()", referenced from:
      _main in main-585927.o
  "sampler<database>::sampler(database const&, double)", referenced from:
      _main in main-585927.o
  "func_objs::create_db_from_file<database>::create_db_from_file(database&)", referenced from:
      database::read_from_file() in database-d7bc7e.o
  "func_objs::create_db_from_file<database>::operator()(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      database::read_from_file() in database-d7bc7e.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I have shared at the below link, the source code from the various source files (and the corresponding header files) included in the command line above. The program is intended to sample a database (contained in a file on the disk). I am presuming that the design would be evident from the source code.

https://drive.google.com/open?id=1NmJcsM4AhqEJRiGqPWsB5Pa8FreTPMW5



I would really appreciate your thoughts.

TIA
Vin
Templates are normally defined in header files. The reason is because the compiler needs the template definitions to be available in the translation unit that instantiate the template. For that reason I think you'll have to move what you have in sampler.cpp to sampler.hpp.
This message tells you that the linker tries to find the file libaudio.so, either in the well known pathes ( might differ on distros ) /lib, /lib64, /usr/lib, /usr/lib64.
You also can tell the linker to search in other pathes with the LIBRARY_PATH environment variable. And the library has to be installed somewhere.
click the link and know more :- http://www.cetpainfotech.com/technology/unix-training
Topic archived. No new replies allowed.