I am integrating a medium-sized (10,000 or so lines) program written in C into a C++ program. I have created a new class, BWAGenome
as an interface to the C code, so any access to the C functions is encapsulated. I am compiling everything with the g++
compiler. The .o files are all generated correctly, but when I attempt to link them together into a final executable, the compiler complains that it cannot find the symbols. Here is the error message I get:
Undefined symbols:
BWAGenome::BWTRestoreBWT(char const*)", referenced from:
BWAGenome::BWAGenome(char const*)in BWAGenome.o
"BWAGenome::GetMatches(unsigned int, int, bwt_t*, bwt_t*, bwt_t*, bntseq_t*, bntseq_t*)", referenced from:
BWAGenome::getMatches(unsigned int, int)in BWAGenome.o
These functions are all in the C++ class I made. They wrap functions in the C code, but I don't understand at all how the symbols could be undefined.
A few details about the code and what I have done so far:
- Everything is compiled with
g++
, so if I understand correctly I don't need theextern "C" {};
surrounding the c header files I include. - All of the code compiles correctly individually. The error only occurs during linking.
- I heard somewhere that the C code might need to be called from static functions, so I have tried wrapping each call to a C function inside a static class method and calling that instead.
Any ideas on how to solve this problem?
edit: added definitions and declarations of BWTRestoreBWT and GetMatches
//definition in BWAGenome.h
static bwt_t * BWTRestoreBWT(const char *fn);
//declaration in BWAGenome.cpp
static bwt_t * BWTRestoreBWT(const char *fn) {
return bwt_restore_bwt(fn);
//bwt_restore_bwt is a function in the C code that I am attempting to integrate
}
second edit: After much soul searching I realized the problem was pretty unrelated to most of what I thought it was. See my answer for details.