Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-13-2011, 06:42 AM   #1
Registered: Sep 2011
Posts: 81

Rep: Reputation: Disabled
how to convert .so file of linux as corresponding .dll in windows

im working on linux .so files i want this .so file to be compatible with windows that is i want to convert linux .so file to corresponding .dll file , i have written the code in portable manner. here is my linux code
__attribute__((dllexport)) double Mean(double,double);
__attribute__((dllexport)) void Display();

#ifdef __cplusplus

extern "C"
double Mean(double a,double b)
return (a+b)/2;

void Display()


#ifdef WIN32
#include <direct.h>
#include <windows.h>


#include <sys/types.h>
#include <dlfcn.h>
#include "pgm.h"

int main()
#ifdef WIN32
HINSTANCE lib_handle;
void *lib_handl;

double (*func)(double,double);
void (*func1)();

#ifdef WIN32
lib_handle = LoadLibrary("");
if (!lib_handle)
printf("cannot able to load so library");
lib_handl = dlopen("",RTLD_LAZY);
if (!lib_handl)
printf("cannot able to load so library");

#ifdef WIN32
func f1=(func)GetProcAddress(lib_handle,"Mean");
double d =f1(4.6,5.4);
printf("\nmean %f\n",d);

func1 f2=(func1)GetProcAddress(lib_handle,"Display");

func =dlsym(lib_handl,"Mean");
const char* dlsym_error = dlerror();
if (dlsym_error)
printf("cant able to load mean");
double d =func(4.6,5.4);
printf("mean %f",d);

func1 =dlsym(lib_handl,"Display");

#ifdef WIN32
return 0;

finally i have created soname,realname,linker name as
now i have copied and renamed it as libpgm.dll and pasted in path of client program(i.e in windows) now im trying to execute it but im getting error as bad image check your installation diskette(similarly i copied all .so file one by one and renamed and i tried to compile on windows the same error i got),but the same code as executed sucessfuly in linux, plz let me knw the solution


Posts: 1
Joined: Tue Sep 13, 2011 10:39 am
Old 09-14-2011, 05:05 PM   #2
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
You need to compile it with Windows as the target. To do that you either need to compile it from Windows or use a cross-compiler.
Kevin Barry
Old 09-14-2011, 08:09 PM   #3
John VV
LQ Muse
Registered: Aug 2005
Posts: 15,262

Rep: Reputation: Disabled
on the windows machine run Mingw the default compiler is gcc 3.4 ( a old beta 4.1 in on sourceforge GnuWin32 )
and build it in mingw
first the *.so/*.la & .def then with dlltool convert it to a win dll
( it has been a few years since i have done that so...)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get under linux information about Windows EXE/DLL file VladVons Linux - General 11 06-17-2011 08:26 AM
How to convert the .dll file to .so file? larshana Programming 1 07-27-2010 07:21 PM
porting a windows dll into linux so file bianchi Programming 1 12-20-2005 02:58 PM
Convert a dll code to linux EvilLinux Programming 5 12-08-2004 09:51 AM

All times are GMT -5. The time now is 06:49 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration