Home >Backend Development >C++ >How to Resolve \'Unresolved External Symbol\' Errors When Calling C Functions from C in Visual Studio 2010?
Linker Error in Cross-Project C Function Calls in C Code in Visual Studio 2010
To address the linker error "unresolved external symbol g_fmt" encountered while calling a C function from C code in Visual Studio 2010, the following steps may assist:
1. Organization and Naming:
Ensure that each C module has its own header and implementation (extension .c). Use consistent naming conventions for files and macros, such as G_FMT_H as an include guard.
2. Header File Modifications:
Replace the header.h header file with functions.h, which includes macros for exporting functions.
<code class="c">#define FUNCTIONS_EXPORT_API __declspec(dllexport) // For DLL export #ifdef __cplusplus extern "C" { #endif FUNCTIONS_EXPORT_API char *dtoa(double, int, int, int*, int*, char**); FUNCTIONS_EXPORT_API char *g_fmt(char*, double); FUNCTIONS_EXPORT_API void freedtoa(char*); #ifdef __cplusplus } #endif</code>
3. Implementation File Modifications:
Create a corresponding implementation file, functions.c, and include the header file. Define the functions and macros for exporting.
<code class="c">#include "functions.h" char *dtoa(double, int, int, int*, int*, char**) {} // Define functions char *g_fmt(char*, double) {} void freedtoa(char*) {}</code>
4. Exporting Functions:
Define the FUNCTIONS_EXPORT macro in the project building the DLL (or as a project setting in Visual Studio) to mark the functions for export. Alternatively, use the macro automatically defined by Visual Studio IDE: ${YOUR_PROJECT_NAME}_EXPORTS.
Additional Considerations:
The above is the detailed content of How to Resolve \'Unresolved External Symbol\' Errors When Calling C Functions from C in Visual Studio 2010?. For more information, please follow other related articles on the PHP Chinese website!