I have created a little test program to understand the __declspec(dllimport)
and
__declspec(dllexport)
preproc.
In my solution I have :
1) File: produit.h
#pragma once
int facteur = 5;
int __declspec(dllexport) base = 100;
int __declspec(dllexport) produit(int, int);
2) File : produit.cpp
#include "produit.h"
int produit(int a, int b)
{
return facteur * (a*b);
}
3) File: produitEx.h
#pragma once
__declspec(dllimport) int base;
__declspec(dllimport) int produit(int a, int b);
4) File : main.cpp
#include <iostream>
#include "produitEx.h"
using namespace std;
int main()
{
int a =5, b=2, c;
c = base + produit(a, b);
std::cout << c << std::endl;
return 0;
}
looks pretty clear and nothing special just exporting fucntions and importing them.
When Compiling (with MinGW) I got those 2 errors :
..../main.cpp:8 undefined reference to `_imp___Z7produitii'
..../main.cpp:8 undefined reference to `_imp__base'
So I did not know what's confusing for the linker ? How to resolve it?
Thank you. (I use MinGW and NetBeans Cpp)
Just to add: the Same code Works on Visual Studio.