Can I call Linux .so libraries from a Windows program?

Questions about Wine on Linux
Post Reply
mhanft
Level 1
Level 1
Posts: 6
Joined: Fri Sep 15, 2017 1:46 pm

Can I call Linux .so libraries from a Windows program?

Post by mhanft » Sat Nov 21, 2020 3:44 am

Hi,

I know that sounds absurd, but I'm looking for a way how to call functions in a Linux .so library from my Windows software which runs with WINE.

The situation is as follows:
  • I have a set of .so libraries for Linux, from another manufacturer, this means no source code.
  • I have my own Windows program (source code available, of course) which runs with WINE.
The .so libraries export, for example, a function int DoSomething(char *string1, char* string2).

It there any change to call that function from a Windows program which runs with WINE?

If it's technically absolutely impossible, I could create an "intermediate layer" - this means, a Linux program (which calls the so. libraries just normally) which is called from my Windows program (which would change/reduce the question to "can I run Linux programs/scripts from a WINE Windows program?" - just like calling "ls -l" or so).

Thank you in advance,

-Matt

PS: Sorry, this should have gone to the Linux sub-forum, but I can't find a way to delete nor to move...

Bamm
Level 4
Level 4
Posts: 107
Joined: Thu May 22, 2008 3:18 am
Location: Manila, Philippines

Re: Can I call Linux .so libraries from a Windows program?

Post by Bamm » Sat Nov 21, 2020 7:57 am

It is possible to call a Linux executable from a Windows program running in Wine. So the easiest way would probably be to create a small command in Linux and call it from your Windows program. I even succeeded in calling a bash shell script from a Windows app.

mhanft
Level 1
Level 1
Posts: 6
Joined: Fri Sep 15, 2017 1:46 pm

Re: Can I call Linux .so libraries from a Windows program?

Post by mhanft » Sat Nov 21, 2020 11:14 am

Sounds interesting - but how? Windows system calls like "ShellExecute" etc. leave me within the Windows subsystem ("C:\blabla" which is "~/.wine/drive_c/blabla" in the Linux world). How can I call, let's say, "/usr/local/bin/bashscript.sh" from a (WINE) Windows program?

Or do I have to copy (or softlink) any Linux script into the "Windows world", and Windows execute functions recognize automagically if it's another Windows program or some Linux thing?

I guess I'll have to do some experimental physics... ;)

spoon0042
Level 5
Level 5
Posts: 404
Joined: Thu Dec 24, 2009 11:00 am

Re: Can I call Linux .so libraries from a Windows program?

Post by spoon0042 » Sun Nov 22, 2020 8:01 pm

There's an entry in the FAQ about running linux programs from windows ones, that's probably where you want to start: https://wiki.winehq.org/FAQ#How_do_I_la ... ication.3F

(That also mentions winepath which converts between windows and unix names.)

As for directly calling linux libraries... it may be possible in theory. At least I remember seeing warnings that malware could, again theoretically make linux syscalls. Or maybe it's possible (intentionally) with winelib, I'm not quite sure how that works.

... actually now that I look at it that seems to be right? Still seems like dark sorcery but here you go:
What you gain by recompiling your application with Winelib is the ability to make calls to Unix APIs, directly from your Windows source code.

mhanft
Level 1
Level 1
Posts: 6
Joined: Fri Sep 15, 2017 1:46 pm

Re: Can I call Linux .so libraries from a Windows program?

Post by mhanft » Mon Nov 23, 2020 3:13 am

Thanks a lot - that seems to be exactly what I was looking for, especially chapter 5:
https://wiki.winehq.org/Winelib_User%27 ... nelib_DLLs
For one reason or another you may find yourself with a Linux library that you want to use as if it were a Windows DLL. There are various reasons for this including the following:
  • You are porting a large application that uses several third-party libraries. One is available on Linux but you are not yet ready to link to it directly as a Linux shared library
  • ...
They even claim "The process for dealing with these situations is actually quite simple", but the description later on sounds a bit complicated to me... but I'll give it a try anyway ;)

Thanks again!

Post Reply