Integrating C code into a C project in different VS2010 projects has resulted in a link error when calling a C function from C code. The error, identified as LNK2001, pertains to an unresolved external symbol.
To rectify this issue, ensure proper organization of the codebase by adhering to specific guidelines:
Modularize Code:
Create Headers and Implementation Files:
Manage Exports and Imports:
functions.h
#pragma once
#define FUNCTIONS_EXPORT_API
#if defined(__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*);
#if defined(__cplusplus)
}
#endif
functions.c
#define FUNCTIONS_EXPORTS
#include "functions.h"
char *dtoa(double, int, int, int*, int*, char**)
{
// Function implementation
}
char *g_fmt(char*, double)
{
// Function implementation
}
void freedtoa(char*)
{
// Function implementation
}
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3