albertlee Posted May 8, 2004 Posted May 8, 2004 This question is just for personal request.......... I am always wondering why the program from Linux cannot install in Windows.....? I know from very simple knowledge, that they are two different OS.......but still they all work on same CPU (same machine/assembly language)...........Is it a problem that windows is 64 bits and Linux is under 64 bits? (this is why Windows program cannot work under DOS, right?) I know that Windows cannot operate on Mac, because the machine language (CPU) is not compatible......right?
Dave Posted May 8, 2004 Posted May 8, 2004 Windows applications can't work on Macs because the CPU architecture is fundamentally different. You can run linux applications on windows. You just need to emulate the linux kernel (windows doesn't use the same kernel as windows, so syscalls and things like that are different), and also interpret the elf format of the linux applications. Theoretically you can run any linux program under windows, but you need to make sure that all your dynamic libraries are compiled as well. You might want to check out LINE.
albertlee Posted May 9, 2004 Author Posted May 9, 2004 So......If we have the source code of any linux program, and compile under windows, Does that mean that program can work on Windows kernel literally? Any body?
Aegir Posted May 9, 2004 Posted May 9, 2004 So......If we have the source code of any linux program' date=' and compile under windows, [i']Does that mean that program can work on Windows kernel literally?[/i] Any body? I dont think that linux programs are written in the same progrming language as windows programs... so you wouldnt find a windows compliler.
fafalone Posted May 9, 2004 Posted May 9, 2004 Actually they are written in the same language (C++ usually), but the external libraries are so different it takes a decent amount of work to port the code between OS's.
bh_doc Posted May 10, 2004 Posted May 10, 2004 It all comes down to libraries and formats. Windows has certain collections of functions (libraries) that Linux does not, and vice-versa. Linux uses formats and protocols that are different to the ones Windows uses. Take for example the executable format - EXE file on Windows, ELF on Linux. These files ARE NOT straight machine code that gets pumped into the CPU - the go through several stages of (simple) translation to load necessary dynamic libraries, reinterpret memory pointers, and other important stuff like that. EXE and ELF contain this interpretation information in different formats, and that's the single biggest reason why you can't run one as the other. There are emulators (such as Wine for running EXEs on Linux) that will do their best to translate one to another. Wine also tries to implement Windows' libraries. Recompilation of the program is another option (the language used to make the program is entirely irrelevant - all you need is a compiler for that language that can target the other platform) but recompilation requires compatible library interfaces. For example, SDL is a commonly used "cross-platform" library that can be used to make games. With it you can write (with a bit of care) code that can compile successfully using the SDL libraries on BOTH Windows and Linux. (Technically, SDL has COMPATIBLE Windows and Linux libraries since externally, ie to your code, they look the same, but internally they do things by different methods that are specific to each OS). Decisions on the fundamental operation and design of the two operating systems have made formats, libraries, and other similar things incompatible, and that's why one can't run on the other.
bh_doc Posted May 10, 2004 Posted May 10, 2004 Is it a problem that windows is 64 bits and Linux is under 64 bits? (this is why Windows program cannot work under DOS' date=' right?)[/b'] Specifically addressing this quote: Windows is generally NOT 64 bits. On most systems it is 32 bits, as is Linux. On some obscure (becoming less so) systems it is 64 bits, AS IS LINUX. The major reason Windows programs cannot work under DOS is exactly my previous post. The EXE formats are different, and the libraries are different. BTW, Linux is predominantly C. The kernel (strictly speaking, the kernel is what you should be referring to when you say "Linux") is C, GNOME is C, GIMP is C, KDE is C++, you get the idea. Mostly C. Windows is also mostly C. The fact that both are mostly C has no bearing on what language is better (use the right tool for the job), or what systems any given laguage might support. GCC (compiler collection - it supports MANY languages) can target Windows.
albertlee Posted May 10, 2004 Author Posted May 10, 2004 Ok.......Do not all versions of c language use same libraries? (ANSI C, which makes C language portable?) Any body? Albert
Dave Posted May 10, 2004 Posted May 10, 2004 ANSI C is more of a standard than just libraries. I think it defines the most basic functions for i/o things and various other bits and pieces (stdio.h, stdlib.h, etc) as well as the syntax and different data types and keywords, but in any case it's completely up to the people who design the compilers as to how to convert the source into some form of object code. In the case of linux, there's a set of libraries called glibc that deal with the actual implementation of the basic C functions, and all C programs are linked against these libraries. Also you have to remember that it doesn't come down to libraries and formats completely. Running a program has a lot to do with memory management and kernel interaction; if you want to emulate an operating system, you need to create some way of emulating the kernel of that operating system so that the program gets the right stuff when it needs it. For example, the windows program I gave a link for contains a basic ELF parser and emulates simple kernel calls. Hope this helps some.
dryan Posted May 10, 2004 Posted May 10, 2004 Windows applications can't work on Macs because the CPU architecture is fundamentally different. You can run linux applications on windows. You just need to emulate the linux kernel (windows doesn't use the same kernel as windows There are Windows emulators for Macs: Virtual PC RealPC WinTel 1.0.1 (works with OSX)
Dave Posted May 10, 2004 Posted May 10, 2004 Perhaps I should've been more specific - Windows applications can't run natively on a mac platform. I'm aware of VPC having used them extensively myself on my iMac
bh_doc Posted May 11, 2004 Posted May 11, 2004 Ok.......Do not all versions of c language use same libraries? (ANSI C, which makes C language portable?) Yes, all versions of C language supply these standard libraries. However, these libraries, while reasonably large and useful in their own right, are not complete, and much functionality that is crucial to a modern OS and its applications (graphics and windowing functions, for example) are not defined in standard C. Thus, it is up to the implementers of the OS to supply their own libraries for such tasks. Linux has X libraries, and Windows has its GDI libraries.
albertlee Posted May 11, 2004 Author Posted May 11, 2004 therefore, how can people say that c language is portable? since we have to change the source codes from different OS to another....... Any body?
Dave Posted May 12, 2004 Posted May 12, 2004 Repeatedly saying the same thing is not likely to get you more responses on the topic. You just need a bit of patience.
albertlee Posted May 12, 2004 Author Posted May 12, 2004 well dave..... I wont repeat my saying as long as my thread is in the "homepage"(active threads), because rarely any one will go and search for problems to answer, which are not in the active threads.......... so still, sorry for repeatition.... Any body for my previous message? Apreciate Albert
Dave Posted May 12, 2004 Posted May 12, 2004 I suppose we can say C is portable because if a program is written properly, it is very easy to port to other platforms with (comparitively) little effort.
bh_doc Posted May 13, 2004 Posted May 13, 2004 therefore' date=' [b']how can people say that c language is portable? [/b] since we have to change the source codes from different OS to another....... The C language IS portable: Any system that supports the C language supports the set of standard C libraries. The problem is that the C language libraries only go so far, and important additions made by third parties, not the C standards body, are not necessarily portable since they often use internal features that are unique to each system. Also understand that many functions in the C libraries are implemented by different means on different systems. They have common interfaces, but for some functions their implementation is undefined by the standard. (It doesn't matter how these functions do their job, just so long as their results for given inputs are according to the standard.) Window, graphics, sound and input device functions are not part of the standard library, that is why those particular aspects are often not portable. There are a number of efforts to make portable libraries that take care of these things, however. SDL, wXWindows, et al. These supply common interfaces to OS specific functions, but they are not part of the C standard, there are some things that may be available on the OS but these libraries can't supply, and not everyone uses them. I hope that finally answers your question.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now