Linking error when compiling C and C++ code with g++

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 the `extern "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.
Can you show the declaration of class BWAGenome and at least some snippets from around the calls to the 2 problem functions?

以上就是Linking error when compiling C and C++ code with g++的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准