I would like to create a dll library from C ++ code and use it in a C program . I would like to export only one function:
GLboolean load_obj (const char *filename, GLuint &object_list);
Library header file:
#ifndef __OBJ__H__
#define __OBJ__H__
#include <windows.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include <GL/glu.h>
#include <GL/glut.h>
#if defined DLL_EXPORT
#define DECLDIR __declspec(dllexport)
#else
#define DECLDIR __declspec(dllimport)
#endif
extern "C" GLboolean load_obj (const char *filename, GLuint &object_list);
#endif
in .cpp (in the library project) is also declared as:
extern "C" GLboolean load_obj (const char *filename, GLuint &object_list)
{
code...
}
The .lib file is added to the VS project options (Linker / Input / Additional dependencies) .. dll is in the folder where the .exe is located. When I compile the C project - error:
Error 1 error C2059: syntax error : 'string'
This is the part of "extern" C "" in the header file.
I tried changing the header file:
extern GLboolean load_obj (const char *filename, GLuint &object_list);
then
Error 1 error C2143: syntax error : missing ')' before '&'
Error 2 error C2143: syntax error : missing '{' before '&'
Error 3 error C2059: syntax error : '&'
Error 4 error C2059: syntax error : ')'
and even when I changed & to *:
Error 6 error LNK2019: unresolved external symbol _load_obj referenced in function _main main.obj
I do not know why this is wrong .. lib.h and .dll are added correctly.
source
share