LinuxQuestions.org
Review your favorite Linux distribution.
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 11-15-2004, 10:22 AM   #1
DavidW567
LQ Newbie
 
Registered: Nov 2004
Posts: 17

Rep: Reputation: 0
Converting Windows DLL code to Linux shared library


I have been given the job of converting a Windows DLL into the equivalent running on Linux. While I have programmed Windows\ C \C++ for many years I am new to Linux.

Are there any guides or articles specifically about the differences between programming for Windows and Linux.

The first problem I have is in the Windows code there is referece to:
__declspec(dllexport)
what is the equivalent in Linux.

David
 
Old 11-15-2004, 10:39 AM   #2
teval
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Gentoo
Posts: 720

Rep: Reputation: 30
I have no clue what that does (i'll assume it creates the ddl? as in sets it up to be one)

There is no such need under Linux. Just create your object files, eg:

cc -c meh.c

That will give you meh.o, then go

cc -o meh.so -shared meh.o

And you're done making your shared lib. To open the lib read dlopen(3). You might also want dlerror, and dlsym (gets you a pointer to a particular function). dlclose will close your lib. man any of those will give you documentation, also they're declared in dlfcn.h

A google for any of those will give you lots of info I suspect.

Please note the above is if you want to load the lib at runtime, most of the time you just want to compile against it, so it's a lot simpler.
Simply compiling with the -shared flag will generate your lib. When you're compiling your program make sure you put in -L. -lname (-L. is look for libs in this directory, -l is the lib name to look for, -L can be anyting you want of course)

This will load the lib dynamically at runtime. man ldd will give you more info on this (ldd is the dynamic loader)

Hope this helps
 
Old 11-15-2004, 10:43 AM   #3
teval
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Gentoo
Posts: 720

Rep: Reputation: 30
Oh, and before I forget you can also have static libs, but those are not recommended (and they are not like dlls). In case you heard of them, they are just a collection of archived object files included in the finaly binary (get your object files, ar -r blah.a <object files>). It's the same thing as if you were compiling against those, I don't think it's a good idea to do that in general, and it definitely doesn't apply if you want something that is dll-like.
 
Old 11-15-2004, 11:07 AM   #4
DavidW567
LQ Newbie
 
Registered: Nov 2004
Posts: 17

Original Poster
Rep: Reputation: 0
__declspec(dllexport) is at the start of the name of the exported function in the header file dfining all the functions as in:

__declspec(dllexport) UINT Acquisition_CloseAll();

I did quite alot of searching on Google, that was how I found this site.

David
 
Old 11-15-2004, 04:43 PM   #5
teval
Member
 
Registered: Jul 2003
Location: Toronto, Canada
Distribution: Gentoo
Posts: 720

Rep: Reputation: 30
You don't need that, all the functions are visible to the program that links against your library.
 
Old 11-16-2004, 02:39 AM   #6
DavidW567
LQ Newbie
 
Registered: Nov 2004
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks
 
Old 07-27-2010, 12:16 AM   #7
larshana
LQ Newbie
 
Registered: Jul 2010
Posts: 2

Rep: Reputation: 1
i have the source for the dll.(which has some header files and .c file). I want to convert this .dll file to .so file so that i can use it in Linux(open suse).please let me knw how to do it.
is it through Wine,if yes then which version?and how to go about it...
 
Old 07-27-2010, 08:15 AM   #8
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
larshana,

you have hijacked 4 different threads which have nothing to do with your question. I have moved your post to a new thread.

http://www.linuxquestions.org/questi...9/#post4046463
 
  


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
Problems while using shared library as dll.... rajsun Programming 2 09-10-2005 03:25 AM
Convert a dll code to linux EvilLinux Programming 5 12-08-2004 09:51 AM
Windows DLL to Linux .so mohan_mohan Linux - Software 3 11-04-2004 10:43 AM
Can I access a Windows DLL directly from Linux code? Silverjam Linux - Software 3 07-10-2004 09:46 PM
howto compile bin with my library using all-static and shared linked standart library stpg Programming 4 06-29-2004 04:20 AM


All times are GMT -5. The time now is 02:53 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