c and c++ code Use C and C++ code together   undefined reference galoreIf word on the street is to be believed, C and C++ can coexist peacefully. Just include the C library< 's header into your C++ file, put them both in a project as seen on the left, and you are set to go.

Unfortunately, this isn't the case - things like polymorphism and other properties of C++ lead to loads of "Undefined reference" errors when trying to access C functions from C++ code and vice versa.

The solution consist of special extern directives - the two sites below should keep you covered:
Mixing C and C++ code in the same program
How to mix C and C++

Good luck porting!

Related posts:

  1. On C style or is code formatting everything?
  2. Code Bubbles – cool new IDE concept
  3. Beautiful Code – the review
  4. The best code optimizer – the brain
  5. On inserting DRM/error catch&terminate code early

4 Responses to “Use C and C++ code together – undefined reference galore”

  1. Under normal circumstances there should be no trouble mixing C and C++ code (in my experience, at least). It simply takes a little common sense to predict what may cause a problem (one of the small, but still significant, syntax changes between the languages for instance) to avoid it. My code is C++ with fairly significant C code mixed in and I’ve never had the sort of problem you speak of

  2. Hi med,
    thank you so much for talking back!

    The problem I had was that I got a large lump of C code which I had to integrate – the code was not written by me…

    All the best
    Tam Hanna

  3. I think the first few times I saw linker errors due to C++ mangling I was very confused but once you’ve seen it a few times and you know there’s C mixed with your C++ you tend to remember pretty quickly.

  4. Hi Lincoln,
    I’ll definitely remember it now – thats why I posted it in the first place ;)

    All the best
    Tam Hanna

Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting

© 2013 TamsPalm - the Palm OS / web OS Blog Suffusion theme by Sayontan Sinha