c++ - Specify source file that defines function previously declared in a header file -
i have bunch of c++ files reference functions defined in sub-directory inside src/. there way specify cpp files inside sub-directory via g++?
here structure of package:
# seqlib # |----src # |-----|---makevars # |-----|---rcpp_hello_world.cpp # |-----|---seqlib(a submodule) # |-----|------|---seqlib # |-----|------|---fermiassembler.h # |-----|------|---src # |-----|------|---|----fermiassembler.cpp ************************* edit **************
when running -i../src/seqlib/, error undefined symbol: _zn6seqlib14fermiassemblerd1ev. using c++filt, symbol references destructor declared in fermiassembler.h but, defined in fermiassembler.cpp
you have pass .cpp files compiler command. it's discouraged include .cpp files in other .cpp files.
the command line work is:
g++ -iseqlib -o my_executable rcpp_hello_world.cpp seqlib/src/fermiassembler.cpp if have lot of files, advised create makefile script avoid recompiling code every time.
if fermiassembler product contains makefile.am/in files, can build using configure script here. general idea the:
cd seqlib ./configure make if it's library product, builds .a or .so file. in case, command line becomes:
g++ -iseqlib -o my_executable rcpp_hello_world.cpp seqlib/bin/fermiassembler.a (i'm gessing path & name of output library file)
to include .a files there, add path. not sure seqlib/bin/*.a because lib dependencies don't follow alphabetical order. bruteforce thing work specifying all .a files twice (so inter-lib dependencies work):
g++ -iseqlib -o my_executable rcpp_hello_world.cpp seqlib/bin/*.a seqlib/bin/*.a it better, though, include required .a files, respecting following order: first ones depending on following ones. last library mustn't depend of of previous ones.
Comments
Post a Comment