I'm using the Intel C++ 2024 Compiler in Visual Studio to make a DLL. I'm not encountering any compiler errors, but if I call sqrt() anywhere, the DLL silently fails when called by other programs. In other words, calling sqrt() is somehow stopping the function names from being exported properly (messing up the symbols).
The problem is easy to reproduce. The following code will compile into a DLL using oneAPI in Visual Studio but you won't be able to call any of its functions from other programs. If you comment out the line with sqrt(), then the DLL will work properly:
#include <cmath>
#define EXPORT extern "C" __declspec(dllexport)
float some_function(float num) {
num = std::sqrt(num); //comment this out and the DLL works
return num;
}
EXPORT double this_should_return_4_but_it_doesnt() {
return 4.0;
}
Note that it's not just the function that contains sqrt() that will fail; every external function that the DLL should be exposing stops working, even functions that don't call sqrt(). Also it makes no difference whether you try this with math.h or cmath, the problem is the same.
I've also tried checking the exported function names with DLL Export Viewer, and strangely, they look correct in both cases. But the DLL is silently failing when sqrt() is called anywhere.
Note that MSVC and GCC do not have this problem. They will compile the same code into a DLL and expose the functions without issues.
oneAPI can produce very efficient code and I'd like to use it for DLLs but the inability to call sqrt() is extremely limiting, and strange. Does anyone know how to fix this problem?