Reputation: 905
I'm trying to compile a dynamic library for Julia using C++. Am using CLion on windows. When I compile with MinGW, ccall works perfectly with the dll. When i'm compiling with MSVC, Julia ccall can't find the function. Does anybody have any idea why and how to solve this? I have to use MSVC..
sample code:
test.h
extern "C" int add2(int in);
test.cpp
#include "test.h"
int add2(int in){
return in+2;
}
Upvotes: 4
Views: 1028
Reputation: 905
Found the answer. the MSVC compiler requires explicit instructions in order to output/input extern "C" functions. The following code works with MSVC and is recognized by Julia's ccall:
test.h
extern "C" __declspec(dllexport) int add2(int in);
test.cpp
#include "test.h"
int add2(int in){
return in+2;
}
In order to import an extern "C" function one may use:
__declspec(dllimport)
Edit: This is not compiler related, but rather needed for all dll-files. Apparentely MinGW does this automatically.
Upvotes: 1