AR# 19240

|

11.1 EDK - How can I use functions compiled with LibGen in my C++ application?

描述

How can I use functions compiled with LibGen in my C++ application?

解决方案

Depending on whether the C++ compiler or the C compiler is chosen to compile a source file, the corresponding symbol naming conventions are used. Consequently, if you try to mix and match C and C++ code and use different compilers for both, you will likely run into undefined references, when the references actually exist. In general, the C++ compiler compiles symbols for C++ linkage and the C compiler for C linkage. If you want to mix C++ and C code, you must ensure that your C++ compiler is alerted to the external C linkage by using the extern "C" { } construct. You must wrap the declarations of external C objects within this construct. For standard EDK-provided external references that have declarations in EDK header files, use something similar to the following:

extern "C" {

#include "xparameters.h"

#include "gpio.h"

}

This forces the compiler to create all references to the entities described within "xparameters.h" and "gpio.h" as C linkage.

AR# 19240
日期 12/15/2012
状态 Active
Type 综合文章
People Also Viewed