LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 09-13-2011, 06:42 AM   #1
shamjs
Member
 
Registered: Sep 2011
Posts: 78

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


hai,
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
/*************pgm.h*****************/
__attribute__((dllexport)) double Mean(double,double);
__attribute__((dllexport)) void Display();

/**********pgm.c********************/
#include<stdio.h>
#ifdef __cplusplus

extern "C"
#endif
double Mean(double a,double b)
{
return (a+b)/2;
}

void Display()
{
printf("\nhai\n");
}

/***************pgmexe.c*******************/
#ifndef USE_PRECOMPILED_HEADERS

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

#else

#include<stdio.h>
#include<stdlib.h>
#include <sys/types.h>
#include <dlfcn.h>
#include "pgm.h"
#endif
//#include<iostream>
#endif

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

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


#ifdef WIN32
lib_handle = LoadLibrary("libpgm.so");
if (!lib_handle)
{
printf("cannot able to load so library");
}
#else
lib_handl = dlopen("libpgm.so",RTLD_LAZY);
if (!lib_handl)
{
printf("cannot able to load so library");
}
#endif

#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");
f2();

#else
dlerror();
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");
func1();
#endif

#ifdef WIN32
FreeLibrary(lib_handle);
#else
dlclose(lib_handl);
#endif
return 0;
}

finally i have created soname,realname,linker name as libpgm.so.1 libpgm.so.1.0 libpgm.so
now i have copied libpgm.so 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
thanks....................................

sham

Posts: 1
Joined: Tue Sep 13, 2011 10:39 am
 
Old 09-14-2011, 05:05 PM   #2
ta0kira
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
Guru
 
Registered: Aug 2005
Posts: 12,705

Rep: Reputation: 1688Reputation: 1688Reputation: 1688Reputation: 1688Reputation: 1688Reputation: 1688Reputation: 1688Reputation: 1688Reputation: 1688Reputation: 1688Reputation: 1688
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...)
 
  


Reply


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 05:38 AM.

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