I heard that it's easier to develop in Linux than in Windows, but how do I develop in Linux? I mean, I know I could make C programs, for example, or simple programs in assembly using interrupt 0x80 system calls. But is there a way to port Win32 programs, like the one in this tutorial, to Linux?
Is there a general Linux way, or do I have to write different versions for different branches of Linux (ie Ubuntu, Red Hat, Fedora Core, ...)? Does anyone know of any good resources for that?
Also, are there other, more Win32-like ways of file I/O, etc., besides using the 0x80 interrupt?
Is there a way to statically - on load time - import SO files (or whatever they're called)? Is there a kernel32.so and user32.so?
Sorry for so many questions, and thanks in advance.
16 replies to this topic
#1
Posted 23 December 2011 - 05:32 PM
|
|
|
#2
Posted 23 December 2011 - 08:11 PM
I'll answer your questions to the best extent I can, with my current knowledge of Linux:
Hope this helps some :)
- If you are referring to making a GUI program, there is no standard way to do that in Linux. It would depend on the widget toolkit (GTK+, Qt, etc) you are using. Gnome programs generally use GTK+ and KDE programs generally use Qt, for example. You could port that program, but you would pretty much need to rewrite it.
- I don't believe there are ways more similar to Win32 for file I/O and the likes, unless you used Wine.
- I think that shared libraries (.so files) are by default linked into the program at load time. I'm not sure if there is a way to dynamically load them but most likely there is.
- There isn't a kernel32.so or user32.so to my knowledge, and I don't think there is anything that is similar, because Linux works in a fundamentally different way. The things handled by kernel32.dll in Windows are handled with INT 80h calls to the Linux kernel, and things handled by user32.dll in Windows are handled by whatever GUI library you are using (in the end getting handled by the X server)
Hope this helps some :)
Latinamne loqueris?
#3
Posted 23 December 2011 - 08:25 PM
Maybe it's due to the fact that I'm used to Windows, but Linux programming seems more complicated to me than Windows programming.
I have a server that I was writing, but for some reason I couldn't run it in WINdows Emulator.
Do you get to choose the particular procedures that you want to load from an SO file, or do you have to load an SO file at a time, or is it different from the way Win32 PE files have the import tables? Are there import tables in Linux programs?
I have a server that I was writing, but for some reason I couldn't run it in WINdows Emulator.
Do you get to choose the particular procedures that you want to load from an SO file, or do you have to load an SO file at a time, or is it different from the way Win32 PE files have the import tables? Are there import tables in Linux programs?
#4
Posted 23 December 2011 - 08:43 PM
- The reason that Linux programming is supposed to be easier is that generally everything works. In my experience programming for Windows is clumsier (but I still prefer it)
- Maybe you ran into a limitation of Wine.
- I do think there is a table of libraries to use and functions to use from those libraries in ELF executables (the default format used in Linux). It probably works differently than in PE executables (those in Windows). You can't really trust me here though, you should read the specifications of these formats for more details. Also, this describes the functions used for loading a library and getting a function from it in Linux. It seems vaguely similar to the methods used in Windows.
Latinamne loqueris?
#5
Posted 23 December 2011 - 08:59 PM
That makes me wonder how a program can call dlopen () if the function is part of an SO that the program can't load on startup because it doesn't have a symbol/at least library import table :D .
#6
Posted 23 December 2011 - 09:12 PM
The ELF format DOES have an equivalent of the library import table that is in PE executables; it just works differently. In both instances the dynamic linker of whatever OS will load the appropriate libraries.
Latinamne loqueris?
#7
Posted 24 December 2011 - 01:16 AM
A few things:
1) WINE actually stands for WINE Is Not an Emulator. It's a compatibility layer, which is completely different. An emulator would require writing the entire system as a Linux program, which would be far more complicated than using a virtual machine.
2) The reason why WINE didn't work is probably because you didn't have all of the libraries your program required to run, or WINE wasn't aware of where they are.
3) Programming for Linux is easier in my opinion, even though I've spent more time programming for Windows. Since different distros all use the same Linux kernel, as long as you write portable code and use something like Qt or GTK+ you'll be fine. I make no guarantees between 32-/64-bit compatibility.
FYI, int 0x80 is actually not the best way to make system calls anymore, as interrupts are much slower than they used to be due to IDTs and stuff. Instead, you should use Intel's sysenter instruction.
1) WINE actually stands for WINE Is Not an Emulator. It's a compatibility layer, which is completely different. An emulator would require writing the entire system as a Linux program, which would be far more complicated than using a virtual machine.
2) The reason why WINE didn't work is probably because you didn't have all of the libraries your program required to run, or WINE wasn't aware of where they are.
3) Programming for Linux is easier in my opinion, even though I've spent more time programming for Windows. Since different distros all use the same Linux kernel, as long as you write portable code and use something like Qt or GTK+ you'll be fine. I make no guarantees between 32-/64-bit compatibility.
FYI, int 0x80 is actually not the best way to make system calls anymore, as interrupts are much slower than they used to be due to IDTs and stuff. Instead, you should use Intel's sysenter instruction.
sudo rm -rf /
#8
Posted 24 December 2011 - 02:06 AM
In that case, why would they use WINE? I don't see anything alcoholic about it, save for maybe the icon.
#9
Posted 24 December 2011 - 10:28 AM
#10
Posted 24 December 2011 - 12:58 PM
Ulrich Drepper has written two excellent articles on the basics of writing and using, and implementing Shared Objects in Linux and ELF. Check out www.akkadia.org/drepper/goodpractice.pdf and http://www.akkadia.o...er/dsohowto.pdf for the papers these will answer all your question and more you will probably have in the future.
What specific functionality did you want to port? To create a simple window you would use Xlib or it's modern replacement XCB.
For most functionality, how portable your application is across different Linux distributions and even operating systems is a question of what build system you use, you could choose to use a number of different build systems on Linux, most of them also address cross platform concerns. However the most common combination of build tools on Linux include autoconf, automake, libtool and pkg-config. These tools are independent of the language your application is written for and are very flexible, if used well can make your application buildable on any Linux distribution, BSD, MacOSX and Windows all the same time. Learning four completely different tools for the build processes can be daunting and seem very complex for novice developers, however other build systems like qmake or scons, try to be all in one build solutions for developers.
As for resources, I would take a look at the project pages for the build tools that mentioned before, or at projects that actually use those build systems, like the Linux Kernel which has a very sophisticated automake setup(https://github.com/mirrors/linux),or the Apache web server which uses autoconf and automake(Welcome! - The Apache HTTP Server Project), or the Mumble project that uses qmake(Mumble). Dolphin, the Wii Emulator is a project that makes use of scons(dolphin-emu - Dolphin, a Gamecube / Wii / Triforce Emulator - Google Project Hosting). There's nothing in particular about these projects with the way they use the build systems(except the Linux Kernel).
However there still are many cases, like with configuring network interfaces, where the userspace library used to provide that functionality is different by default in those distributions and thus requires different application code to handle those different distributions(unless you expect the user to install those non-default library or services).
You can use any userspace library you like to do file I/O.
Not sure if I understand this question. Did you want statically compile a shared object, link the shared object at compile time, or call functions from a shared object in runtime?
AS for the equivalents to kernel32 and user32, empirically, No. Libraries in Linux are aren't so poorly organized as to include 90% of the operating systems functionality in two libraries.
Libc however is probably the basic library that you're looking for with regards to "system calls": GNU C Library - GNU Project - Free Software Foundation (FSF)
Quote
But is there a way to port Win32 programs, like the one in this tutorial, to Linux?
Quote
Is there a general Linux way, or do I have to write different versions for different branches of Linux (ie Ubuntu, Red Hat, Fedora Core, ...)? Does anyone know of any good resources for that?
As for resources, I would take a look at the project pages for the build tools that mentioned before, or at projects that actually use those build systems, like the Linux Kernel which has a very sophisticated automake setup(https://github.com/mirrors/linux),or the Apache web server which uses autoconf and automake(Welcome! - The Apache HTTP Server Project), or the Mumble project that uses qmake(Mumble). Dolphin, the Wii Emulator is a project that makes use of scons(dolphin-emu - Dolphin, a Gamecube / Wii / Triforce Emulator - Google Project Hosting). There's nothing in particular about these projects with the way they use the build systems(except the Linux Kernel).
However there still are many cases, like with configuring network interfaces, where the userspace library used to provide that functionality is different by default in those distributions and thus requires different application code to handle those different distributions(unless you expect the user to install those non-default library or services).
Quote
Also, are there other, more Win32-like ways of file I/O, etc., besides using the 0x80 interrupt?
Quote
Is there a way to statically - on load time - import SO files (or whatever they're called)? Is there a kernel32.so and user32.so?
AS for the equivalents to kernel32 and user32, empirically, No. Libraries in Linux are aren't so poorly organized as to include 90% of the operating systems functionality in two libraries.
Libc however is probably the basic library that you're looking for with regards to "system calls": GNU C Library - GNU Project - Free Software Foundation (FSF)
#11
Posted 24 December 2011 - 01:20 PM
mebob said:
@dargueta what should I use if I have an AMD processor?
Intel and AMD are completely compatible minus a few extra instructions that AMD occasionally adds (though Intel almost always adds them later). Stick with the Intel instruction set and you'll be fine.
sudo rm -rf /
#12
Posted 24 December 2011 - 03:30 PM
@Milyardo: I meant like in NASM, Win32, I could type this:
Anyway, Windows programming seems a lot less confusing to me, where there's just one type of distribution, and where one doesn't have to worry about GUI differences, distribution deviations, etc. In any case, Windows is not too bad yet, so I guess I'll just stay on Windows at least for now.
I'm wondering if Microsoft would mind if I make Win32 PE executables (common Windows programs) compatible with the operating system I'm planning on writing. Would I need any patents or anything for that?
extern MessageBoxA import MessageBoxA user32.dll, and it would import the MessageBoxA () function from the user32.dll dynamic link library when the program is loaded into memory. I was asking whether that sort of importing is possible in Linux.
Anyway, Windows programming seems a lot less confusing to me, where there's just one type of distribution, and where one doesn't have to worry about GUI differences, distribution deviations, etc. In any case, Windows is not too bad yet, so I guess I'll just stay on Windows at least for now.
I'm wondering if Microsoft would mind if I make Win32 PE executables (common Windows programs) compatible with the operating system I'm planning on writing. Would I need any patents or anything for that?
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









