I am trying to include the C code that I found in our C ++ project. The function is defined as in C.
#ifdef __cplusplus extern "C" { #endif extern char *dtoa(double, int, int, int *, int *, char **); extern char *g_fmt(char *, double); extern void freedtoa(char*); #ifdef __cplusplus } #endif char * g_fmt(register char *b, double x) {
The VS project in which I include this creates a dll. The file is compiled as C, other files in the project are compiled as C ++.
I added a header to be included in my C ++ files
#ifndef G_FMT_H #define G_FMT_H #ifdef __cplusplus extern "C" { #endif extern char *dtoa(double, int, int, int *, int *, char **); extern char *g_fmt(char *, double); extern void freedtoa(char*); #ifdef __cplusplus } #endif #endif
In another project in the solution, I include my header and try to call the g_fmt function.
#include "header.h" ... g_fmt(my_array, 2.0);
This project refers to another, I can call C ++ functions in the first library without any problems. However, adding the specified line results in lnk2001 error.
error LNK2001: unresolved external symbol g_fmt
I found a number of other questions about mixing C and C ++, and I seem to have done everything I need with the extern keywords in the right places, however I still can't link. Is there anything specific I need to do in VS2010?