Home >Backend Development >C++ >How to Fix Linker Errors When Calling C Functions from a C Project in Visual Studio?
Linker Error When Attempting to Call C Function from C Code in Different Project
This issue occurs when you attempt to include C code in a C project within different Visual Studio 2010 (or any version) projects. The following steps can assist in resolving this error:
1. Organize Header and Source Files
For clarity and modularity, ensure each C function has a dedicated header file and source file.
2. Header File (functions.h)
Example:
<code class="c">#define FUNCTIONS_EXPORTS #include "functions.h" char *dtoa(double, int, int, int*, int*, char**); char *g_fmt(char*, double); void freedtoa(char*);</code>
3. Source File (functions.c)
Example:
<code class="c">#define FUNCTIONS_EXPORTS #include "functions.h" char *dtoa(double, int, int, int*, int*, char**) { // Function implementation }</code>
4. Project Export Settings
5. Linker Settings
By following these steps, you can successfully mix C and C code in different projects and resolve the linker error related to the g_fmt function call.
The above is the detailed content of How to Fix Linker Errors When Calling C Functions from a C Project in Visual Studio?. For more information, please follow other related articles on the PHP Chinese website!