Wednesday, November 20, 2013

Solved: Misleading link errors with gcc on linux

Solution Summary: LDFLAGS come in last

Background
I have been monkeying around with an issue of linking my code with xerces-c++ and xalan-c++ library for hours. Wondering what was I doing wrong.

I was issuing the following command for compiling

g++ -o file.out -lxalan-c -lxerces-c program.cpp

I was getting the following errors

program.cpp:(.text+0x75): undefined reference to `xercesc_3_1::XMLUni::fgXercescDefaultLocale'
program.cpp:(.text+0x7a): undefined reference to `xercesc_3_1::XMLPlatformUtils::Initialize(char const*, char const*, xercesc_3_1::PanicHandler*, xercesc_3_1::MemoryManager*)'
program.cpp:(.text+0x7f): undefined reference to `xalanc_1_11::XalanMemMgrs::getDefaultXercesMemMgr()'
program.cpp:(.text+0x87): undefined reference to `xalanc_1_11::XPathEvaluator::initialize(xercesc_3_1::MemoryManager&)'
program.cpp:(.text+0x8c): undefined reference to `xalanc_1_11::XalanMemMgrs::getDefaultXercesMemMgr()'
program.cpp:(.text+0x9e): undefined reference to `xalanc_1_11::XalanSourceTreeInit::XalanSourceTreeInit(xercesc_3_1::MemoryManager&)'
program.cpp:(.text+0xac): undefined reference to `xalanc_1_11::XalanSourceTreeDOMSupport::XalanSourceTreeDOMSupport()'
program.cpp:(.text+0xb1): undefined reference to `xalanc_1_11::XalanMemMgrs::getDefaultXercesMemMgr()'
program.cpp:(.text+0xcd): undefined reference to `xalanc_1_11::XalanSourceTreeParserLiaison::XalanSourceTreeParserLiaison(xalanc_1_11::XalanSourceTreeDOMSupport&, xercesc_3_1::MemoryManager&)'
program.cpp:(.text+0xea): undefined reference to `xalanc_1_11::XalanMemMgrs::getDefaultXercesMemMgr()'
program.cpp:(.text+0x112): undefined reference to `xalanc_1_11::XalanDOMString::XalanDOMString(char const*, xercesc_3_1::MemoryManager&, unsigned int)'
program.cpp:(.text+0x118): undefined reference to `xercesc_3_1::XMLPlatformUtils::fgMemoryManager'



Thanks to this Stackoverflow Discussion. I found out what I was doing wrong. Although the discussion was about compiling in windows but it gave me the clue.

So basically, while it did work on suse, the actual syntax is (LDFLAGS come in last)

g++ -o exectuable <object files> <ld flags>

So I changed my command to the following and got my issue fixed.

g++ -o file.out  program.cpp -lxalan-c -lxerces-c

I am sharing this so the next guy who has similar issues will hopefully find this post and save him some trouble.

Happy coding!

3 comments:

  1. Get a good chance at finding finance companies at loansforbadcreditwithmonthlypayments.blogspot.com. I like how they disclose all fees

    ReplyDelete
  2. Thank for helping in coding and programming. I love programming and want to know more about it. I will apply some codes in my website regarding 2020 best digital piano in range of $500.

    ReplyDelete
  3. obat kuat terbaru viagra asli yang sudah memiliki izin resmi dari bpom kini banyak diburu oleh pria dewasa untuk memelihara stamina pria saat bercinta bersama istrinya. kapsul ajaib dari erogan asli kapsul obat kuat dapat menambah stamina pria sekaligus dapat memperbaiki ukuran alat vital pria yang dapat membantu masalah biologis secara sempurna. obat dari cina seperti nangen asli zengzhangsu obat kuat impotensi dapat mengobati impotensi jika anda konsumsi secara rutin dalam 2x sehari dapat menyembuhkan secara total. levitra asli 100 mg obat disfungsi ereksi yang banyak dicari oleh kalangan pria yang ingin mendapatkan ereksi keras, kencang dan tahan lama hingga mampu klimaks secara berulang-ulang. vimax pills adalah ramuan khusus sebagai obat pembesar alat kelamin yang terbuat dari ramuan herbal yang sudah diracik dengan teknologi modern ala canada klik tautan .

    ReplyDelete