user7042812
user7042812

Reputation: 133

Using c DLL into c++ project

So I have a problem. I have read many things but nothing seems to be working for me.

I have this C library, and I made project with file:

//send.h
#ifndef SEND_H
#define SEND_H

#ifdef __cplusplus
extern "C" {
#endif
        static int Send_Sample(void);


#ifdef __cplusplus
}
#endif

#endif /* SEND_H */

And I have

//send.c
#include "thatLibrary.h"
static int Send_Sample(void)
{ return 0; }

So I created project as Empty DLL and than after that i built it, and its ok. But when i made another project, and referenced this one in it, I do

#include "send.h"

And this include is working, he sees that .h file, but when i build the other project, it says:

Error   C2129   static function 'int Send_Sample(void)' declared but not defined    AzureEventHubClient c:\users\v-vlvesi\documents\github\azureeventhubclibrary\azureeventhubclient\source.cpp 9   

Does anyone know how to fix this ?

Thanks !

Upvotes: 0

Views: 484

Answers (1)

Stéphane Perras
Stéphane Perras

Reputation: 71

The 'static' keyword actually prevents the function from being exported from the DLL. You also have to make use of dllimport and dllexport.

You can refer to this previous answer for how to instrument your code: Exporting functions from a DLL with dllexport

Upvotes: 1

Related Questions