'Creating a shared library for both C and C++

Say I want to have a small library with some common functionality for TCP sockets. Now for C++ code I want to create classes such as TCPClient, TCPServer, etc. but for C code I want to have just functions and structs.

Is it a common/recommended practice to combine those in the same shared library?



Solution 1:[1]

You will have problem linking C with a C++ library.

Generate a C library (only functions and structs). Then you can either link it directly within C code, or write a C++ wrapper which declares the wanted Classes and calls C function, wrapped in an extern "C" {} statement.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jocelyn