[英]Building a library consisting of C and C++ files
I have a .so
library where all code was written in plain ANSI C, so compiling it is straightforward.我有一个
.so
库,其中所有代码都是用普通的 ANSI C 编写的,因此编译它很简单。 Now, I need to add C++ code in it.现在,我需要在其中添加 C++ 代码。 What would be the compilation process now?
现在的编译过程是什么?
Do I have to compile C++ files with g++
and the rest with gcc
, but what about linking into .so
file, do I do this with g++
?我是否必须用
g++
编译 C++ 文件,其余的用gcc
,但是链接到.so
文件怎么样,我用g++
来做这个吗?
Thanks!谢谢!
Yes,是的,
.c
with gcc
gcc
编译.c
.cpp
with g++
g++
编译.cpp
g++
g++
链接Note:笔记:
If a C++ function needs to be invokable from C code, wrap it in extern "C" { ... }
.如果需要从 C 代码调用 C++ 函数,请将其包装在
extern "C" { ... }
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.