简体   繁体   English

构建由 C 和 C++ 文件组成的库

[英]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,是的,

  • Compile .c with gccgcc编译.c
  • Compile .cpp with g++g++编译.cpp
  • Link with 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM