ARM Technical Support Knowledge Articles

REFERENCING C FUNCTIONS FROM C++

Applies to: RealView C Compiler

Answer


Information in this article applies to:


QUESTION

I'm calling a C function called my_func from a C++ module.  When I try to build the project, I get the following linker error:

Error: L6218E: Undefined symbol my_func().

In my C++ module, I declared the function as follows:

extern void my_func (void);

What is wrong? How do I call a C function from C++?

ANSWER

To call a C function from C++, use the following type conversion notation:

extern "C" void my_func (void);

This tells the linker that the my_func function requires a C-style linkage to the C++ module.

MORE INFORMATION

SEE ALSO

Article last edited on: 2011-09-06 11:45:01

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential