The answer to your question, you don't need to convert the C libraries to C++. Basically, you can link the C library(Linux:.a/.so) or (Win:*.dll) and use that function into your corresponding modules.
Access C Code from Within C++ Source
In C++ language provides a "linkage specification" with which you declare that a function or object follows the program linkage conventions for a supported language.
The default linkage for objects and functions is C++. All C++ compilers also support C linkage, for some compatible C compiler.
When you need to access a function compiled with C linkage (for example, a function compiled by the C compiler, or a function written in assembler), declare the function to have C linkage.
Declaring Linkage Specifications
Use one of the following notations to declare that an object or function has the linkage of language language_name:
Example:
extern "C" void howdy(int);
extern "language_name" declaration ;
extern "language_name" { declaration ; declaration ; ... }
- The first notation indicates that the declaration (or definition) that immediately follows has the linkage of language_name.
- The second notation indicates that everything between the curly braces has the linkage of language_name, unless declared otherwise. Notice that you do not use a semicolon after the closing curly brace in the second notation.
You can nest linkage specifications, but the braces do not create scopes. Consider the following example:
extern "C" {
void f(); // C linkage
extern "C++" {
void g(); // C++ linkage
extern "C" void h(); // C linkage
void g2(); // C++ linkage
}
extern "C++" void k(); // C++ linkage
void m(); // C linkage
}
All the functions above are in the same global scope, despite the nested linkage specifiers.
Including C Headers in C++ Code
If you want to use a C library with its own defining header that was intended for C compilers, you can include the header in extern "C" brackets:
extern "C" {
#include "header.h"
}
SIDENOTE: You need to to add this guard in your c header files in order to use that in C++.
#ifndef __YOURLIB_H_
#define __YOURLIB_H_
#ifdef __cplusplus
extern "C" {
#endif
int sample_func(int n);
#ifdef __cplusplus
}
#endif
#endif
Tutorial to use C lib in C++.