0

I have a C# project that does a Dllimport of a dll file from a c++ code. The solution is made targetting .NET Core and the executable works fine in Windows.

I tried to publish the solution using linux-x64 as target runtime. I compiled the c++ code into an .so file that is included in the project files. However, when I try to execute the program in linux I get an error Unable to load shared library

If I run file onto the shared object I get:

shared_lib.so: PE32+ executable (DLL) (console) x86-64, for MS Windows

So maybe the problem is that the .so file is not correctly compiled for linux? I basically just took the same compilation lines and changed shared_lib.dll to shared_lib.so but I guess that was too naive. In particular I have:

g++ -c -DBUILD_MY_DLL shared_lib.cpp 
g++ -shared -o shared_lib.so shared_lib.o -Wl,--out-implib,libshared_lib.a

Is there some flag that one has to set in order to make the shared library available for linux?

HTSS
  • 11
  • 1
  • ***I basically just took the same compilation lines and changed shared_lib.dll to shared_lib.so but I guess that was too naive.*** You can't just rename a windows binary to have the extension of a linux one. You need to build for linux. – drescherjm Jul 30 '21 at 21:01
  • This may help: [https://stackoverflow.com/questions/4769968/c-cross-compiler-from-windows-to-linux](https://stackoverflow.com/questions/4769968/c-cross-compiler-from-windows-to-linux) – drescherjm Jul 30 '21 at 21:02

0 Answers0