Quantcast
Channel: Questions in topic: "dll"
Viewing all articles
Browse latest Browse all 706

Native c++ (mingw) plugin works in editor but not in build

$
0
0
I have a minimal c++ script that's called from a minimal c# script. The dll is compiled on Windows 10 using mingw g++ and it works fine in the editor. Build an run however leads to the following error message:> Plugins: Failed to load 'C:/(...)/dll-example_Data/Plugins/libTest.dll' with error 'A dynamic link library (DLL) initialization routine failed. Here's the .cs file: using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Runtime.InteropServices; public class TestScript : MonoBehaviour { [DllImport("libTest", CallingConvention = CallingConvention.StdCall, ExactSpelling = true)] public static extern int TestFunction(); void Start() { Debug.LogFormat("libTest says: {0}", TestFunction()); } } And the .cpp: extern "C" { int __stdcall __declspec(dllexport) TestFunction() { int* test = new int[1]; // removing this line will make everything work when building return 4; } } Here's how I build it: g++ -O2 -g -Wall -c -fmessage-length=0 Test.cpp g++ -shared -o libTest.dll Test.o So If I delete the marked line (int* test = ...), recompile and replace the .dll everything works fine using the build .exe and the editor. Any suggestions would be appreciated! I've tried finding a difference between the dlls using ldd, objdump and dumpbin.exe but couldn't find anything obvious, however I'm not quite an expert with these tools.

Viewing all articles
Browse latest Browse all 706

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>