Migrate Win32 C/C++ Applications to Linux
An anonymous reader writes "This series of articles helps you migrate your Win32 C/C++ applications to Linux on POWER. Win32 C/C++ Apps to Linux Part-1 of this series covers the Win32 APIs mapping to Linux on POWER regarding the initialization and termination, process, thread, and shared memory services. Win32 C/C++ Apps to Linux Part-2 illustrates how to map Win32 to Linux with respect to mutex application program interfaces (APIs)."
...that sometimes during the process the stragglers fall prey to hunters.
Nope. It relates to porting Mac applications to run under Solaris. They just called it "Win32C/C++ Applications to Linux" to see if you'd ask a stupid question.
Worked brilliantly, too!
To fight the war on terror, stop being afraid.
I was thinking about this today. everyone complains that there isnt *Insert Random Program HERE* available for Linux, isnt part of the problem that most code being written isnt portable? eg its too dependant on specific libraries.
.
I cant write code myself, so obviously there is a lot that i dont know. But is it really that hard to write code that is portable?
Thoughts , Ideas?
Comments and/or Flames should be posted below this line
---------------------
What I was getting at is if it was a porting or the application ran in a virtual OS.
And no, I couldn't give a shit what my karma is.
The hardest part of porting to LINUX will be refactoring all of the GUI stuff.
Does anyone know of a good book on C++ programming in Linux?
.NET as the IDE (which the instructor is not familar with and is threatening to go to Linux instead). At home, I'm using Visual C++ 6.0 Learning Edition that was provided by the Deitel and Deitel book. Tried using Visual C++ Express edition but it seems more trouble to use (e.g., there's no automatic prompt to prevent the DOS box from disappearing).
;) I would like to learn how to program basic C++ fluently on both platforms.
I'm taking a C++ class at the local college that's being taught by the Unix guru. The class is using Visual Studio
Anyway, I tried compling the sample programs under gcc and g++ on my Linux file server, and I get a lot of errors. I thought C++ (or at least, C) was supposed to portable.
Linux actually has a larger market share.
File under 'M' for 'Manic ranting'
No. No it wouldn't.
OS-X has the market share of Linux with the cost of Windows. If you want a Server, Linux is a better option. If you want a desktop, Windows generally wins out. Why the hell would it be smarter to "move apps to OS X"?
you, sir, are a moron.
Just moved J2EE webapp from windows to linux. Really nothing to it ;)
Apoptosis
Yeah, but aren't most computers running Linux backend servers? In terms of desktop users that need program X, I'd imagine there are more Mac users than Linux users.
I'm not that surprised IBM releases something like this, and looking at the documents, they seem well written. Yet they only seem to scratch the surface, and help porting the "background" part of the program. Porting the GUI will be an ultimate challenge anyway, there's no easy to way to port Win32-calls to X. And even the actual program will take a lot more than just what's told in these 2 parts. How many are they going to release, 2^n ? Somehow seems more like a marketing tool instead of real usage. Obviously someone from /. was going to post this article here, and the document has done it's publicity stunt.
Offtopic, first article was released in June 2004. If it takes 8 months to write a short addition to it, how long would it take to actually port something?-) And will "part 3" in 8 months bring again new headlines to /. by some moderator hoping for Microsoft's death?
- Yak
What's funny is that all the "Linux" code will compile fine on Windows with Services for UNIX installed correctly.
Windows and OS X will already compile and run 99% of all Open Source code anyone cares about.
- Adam L. Beberg - The Cosm Project - http://www.mithral.com/
While well meaning, the articles are only really useful for porting example code.
In reality, any large codebase will interact with APIs that don't have any mapping to Linux APIs, such as GUI components, services, and the registry. I can't think how these articles would be useful without wrappers for the above types of functions, and anyone familiar enough with Linux and Win32 application developement to write these wrappers will already know the equivalent Linux functions for Win32 functions.
To make matters worse, the first article is riddled with typos.
Migrating a Win32 app the way they suggest is going to be painful and time consuming. In addition, there are numerous things that they don't mention, like associated performance costs: is creating a thread going to be more expensive or cheaper on Linux vs. Win32? Don't look to the article for the answer. It doesn't even mention the biggest parts like the graphics/windowing library.
Secondly, it is making a wild assumption that your win32 app is written in a that is conducive to a Unix/Linux process model. Namely that you spawn processes and use environment variables as opposed to having a message loop and handlers (the way most windows apps are written).
Third, if it was so straight forward to port a Win32 app, why not just write a library that maps the windows calls onto the equivalent Linux calls instead of manually changing all your source?
Finally, why not look at a binary solution like Wine first and not touch your source at all?
This is the worst way migrate app. The source works and manually mucking with it like this is a good way to break it and introduce all sorts of bugs. Look for a binary solution like Wine. Then look to see if somebody implemented a Win32 on Linux library next to recompile (like Cygwin in reverse). Then, the last choice is to factor out your platform specific portions of your code and replace them with OS neutral calls. But beware of the performance of your app, it will probably take a hit. But, hacking apart your app like this makes me cringe.
Facts are meaningless. You could use facts to prove anything that's even remotely true! -Homer Simpson
I don't get it. IBM seems to have some massive aversion to Wine. It seems to me the easiest thing they could do would be to port Wine to the Power architecture. It would consume a little time, but surely nothing as suggesting every application developer rewrite massive parts of their Win32 app. These articles basically suggest an app needs to be rewritten from scratch, which will immediately make any ISV laugh at Linux on Power. (Why would you bother porting a Win32 app to Power? Why not just keep using a cheap Intel box running Linux?)
Winelib was specifically designed to help with porting and you can do it tiny controlled steps:
1. Port from MSVC++ to the MinGW compiler and develop things like a Makefile.
2. Test the app.
3. Port the code from Windows to Linux (not as trivial as you'd think - there are problems with case sensitivity, etc.)
4. Test compiling.
5. Finish compiling using the custom Wine tools, such as winegcc (a wrapper around gcc that makes it behave like MinGW).
6. Test your Winelib app.
7. Begin ripping out chunks of Win32 specific code and replace them with native equivalents - Wine dialogs for KDE/GNOME ones.
8. Test
That's a valid and controlled migration path. Asking developers to basically rewrite massive chunks of code involving threading, memory management, and other such exciting things is a nightmare. Oh, and after rewriting you get to debug it all. Would you trust an enterprise app that just had it's whole threading model replaced?
The part I find amazing though, is just how much they haven't addressed. What do you do when your app relies on COM? What about Windows common controls? What about networking?
Anyway, it looks like IBM missed the ball - a few engineers porting Wine to Power could have solved many of their migration issues. It certainly would have solved every single one mentioned in these articles. Instead they want the software developers of the world to take on the task of rewriting their apps.
----- obSig
But realize one thing: sometimes those libraries make your life SOOOO much easier to program. When you're writing a GUI (even in Java), certain libraries make the process much more simplistic. Window Handlers, Toolkits, and other toys exist to make the coders life much easier.
If we didn't make these libraries, we'd all still be coding our temperature converter GUI in assembly and it'd be ugly and broken and would take 1000 times as long to code.
I dont claim to know much about the differences between Linux and Windows, but my guess is that when you build an app for windows, using windows' libraries makes the whole thing snap together well. (which actually presents a security hole, but if those libraries were written well...)
If you want to make code portable, you sometimes have to give up the tricks provided by the operating system. That is why, I suppose, that standards-based applications are 'better' because any app written to that standard can be used in any other app written to that standard. Windows may accept those standards, but you can bet your ass they aren't going to translate THEIR standards into OUR standards. </aimless rant>
Wouldn't it be smarter if you Mac Zealots didn't troll every single discussion? You guys are the worst advertising imaginable.
Just use a cross-platform GUI library in the first place.
IMHO, the ease or difficulty in porting an application really begins at the design stage. If you design for a standard(GUI apps excepted) like POSIX then porting is much easier. Granted that many things on Windows become more difficult but usually not impossible. I have written many apps over the years for diverse platforms and usualy only have to rewrite one module that contains the platform specific code. For example, calling SYS$ & LIB$ functions on OpenVMS. However, whe it comes to the GUI then things get a lot more indeterminate which it where the auhor is coming from. There are some tradeoffs to be done here. Either:- 1) Design for performance 2) Design for portability If you take the former and for example, design the GUI using Visual Studio tools then you will get something that will work and perform well on Windows but moving to other platforms is nigh on impossible. So, where do we go in the future? Well Microsoft would want you to go down the .NET route but they ave singularly failed to release it for other platforms. Mono is there but it does not have the cachet of Mictosoft support which is needed in many companies.
Java is pretty portable and there are lots of skill out there to continue development.
There are other niche languages & environments that are portable but these have their roots in OSS and sometimes trying to itroduce something like Python into a totally Microsoft shop is like trying to make the Red Sea part. {I know as I tried this and was regarded as a subversive influence.}
The overall situation is cloudy but there are breaks of sunlight where Portability is a prime consideration and the company can reap the benefits in a MultiPlatform world.
I'd rather be riding my '63 Triumph T120.
>Tried using Visual C++ Express edition but it seems more trouble to use (e.g., there's no automatic prompt to prevent the DOS box from disappearing).
This is a real annoyance for me, too. I've searched through the dialogs a little and didn't find it. (Although if I program with the IDE a little more I would just Google for the option.)
Incidentally, another quick hack you can use in this situation is to add a std::cin.getline() at the end of the program. However, I feel bad saying that because you'll be far more productive in the long run if you just look it up.
Comment removed based on user account deletion
and why did we port those mainframe programs to Win32 10 years ago?
KEEP THE CUSTOMER SATISFIED, that sounds good.
There is a spark in every single flame bait point.
Because some could not wait 10 years to get the labour done a cheaper way.
Trolling using another account since 2005.
Consider the source. This information is coming from IBM, who have been been proponents of Linux. While IBM may make the G5 processor in the new line of Macs, they also make the iSeries, pSeries, and zSeries line of servers, all of which use POWER architecture and are capable of running Linux. I didn't RTFA, but I'm pretty sure what IBM is talking about here is companies moving their custom code off of Windows based servers and onto one of their servers running Linux. They aren't talking about porting your favorite desktop app.
That's what I was wondering. Linux users will demand that you release your software for free. Apple users on the other hand are accustomed to paying 3 or 4 times the value of the products they buy.
This article reminds me of the famous flaming between MINIX author and Torvalds. And I quote Linus:
i x/ browse_frm/thread/c25870d7a41696d2
"Portability is for people who cannot write new programs"
-me, right now (with tongue in cheek)
http://groups-beta.google.com/group/comp.os.min
And what the hell is POWER and pSeries? I'm pretty much going to ignore this article. I've been writing win32 software for quite some time and am seriously fed up with that platform. Rather than tweaking my software so that it works with Wine I'm much more interested in rewriting the GUI from scratch using wxWidgets. With a wx based application, you can then compile it into native Linux (GTK+), native win32, or even Mac OS X apps. To me that seems like the most promising route. I've used some wx based applications like Audacity and they're just amazing, really look like they belong on each target platform.
Actually, it's neither. The article describes the use of a portability layer abstracting the APIs.
> it is making a wild assumption that your win32 app is written in a that is conducive to a Unix/Linux process model
Just read it in reverse and you can now easily port Linux apps to Windows!
In my opinion, GUI is not all that important part in the software. Yet, nowdays its really impossible to make portable (unless you use java for gui, which hardy a good choice). So why not logically separate GUI from app core?
:)
Good example of that is mldonkey. Their server-client does not come with any gui by default, but it just provides an network interface (tcp) for it. So there are thosounds of GUIs now for all the platforms, and they work great.
Not to mention technologies like j2ee
I'd recommend using gcc/g++ to learn the languages. Using Visual C++ lets you make certain mistakes without punishing you for them; gcc/g++ WILL let you know when you haven't initalized a variable; Visual C++ - most of the time - will assume it's been set to zero and let you work from there. It makes bad habits easier to form.
Also, code written in gcc/g++ is pretty much guranteed to work in VC++; the reverse is not always true.
What I was getting at is if it was a porting or the application ran in a virtual OS.
The article (which you likely haven't bothered to read) specifically mentions porting and talks of changes to source code. So if you're wondering if it's talking about porting or something else, I guess you already have your answer.
Of course, ask a stupid question and you'll get the answers you have. Being female is no excuse for not first trying to comprehend the material.
http://developer.apple.com/documentation/Porting/C onceptual/win32porting/win32porting.html
I am not that familiar with WINE, but isn't there a package to install on Windows that integrates nicely with VisualStudio where you can simply check to see if your application will also work on Linux under WINE? That way, it would make developers conscious of whether they were using libraries that would make it incompatible with WINE. Is this already possible?
The author might have meant: "Porting Windows programmers to POSIX" :-)
SIOUX basically just creates a simple MacOS 9 app with a window that acts as a console. Just add that, and standard I/O will behave almost exactly like it does on a *nix machine.
English is easier said than done.
I for one thought that was fucking hillarious.
The second article "Migrate Win32 C/C++ application to Linux on POWER, Part 2: Mutexes" worth nothing, since you can't use semaphore (SysV semaphore) instead of mutex. It seems that the author do not know/understand the very basic difference between binary semaphore and mutex - and the difference is that there is no owner for semaphore and there is always owner for mutex. This means that once mutex taken/locked, only the thread/process which holds the lock able to release the lock, and this is not true for binary semaphore ... since it has no owner and any process/thread can unlock it.. I can even say that the example demonstrated in second article is dangerous.. Since it leads to misunderstanding and production of wrong/problematic code. At the moment there is no standard way to map Wind0ze inter-process mutex to Linux, this could probably be done using FUTEX API, but it is still changing, not standard and not well documented.
Regards,
Mike
Thank you. I've been planning to purchase an iBook in the near future and run mainly Gentoo on it. I was really excited about the Mac mini as a cheap(!) alternative to a mini-ITX PC to run a server or MythTV. After seeing most of the comments on the "How to Install Debian on Mac Mini" article (to the effect of: 'MacOS rules. Linux is dumb. You're not allowed to run Linux on a Mac, because it's dumb.'), I'm actually reconsidering. I don't want to be associated with that culture.
Please guys, do Apple a favor and SHUT THE FUCK UP.
Being female is no excuse for not first trying to comprehend the material The only person to imply that is you.
And no, I couldn't give a shit what my karma is.
Third, if it was so straight forward to port a Win32 app, why not just write a library that maps the windows calls onto the equivalent Linux calls instead of manually changing all your source?
What do you think WINE is? It's exactly that library, plus a loader and relinker and other related tools. You certainly can compile win32 programs against it for porting purposes.
WINE is a binary solution only in the worst case -- if the port is being done by someone with the source, they can recompile against winelib and so be portable to non-x86 targets.
It reminds me Monty Python's restaurant sketch.
Coders sometimes go mmmmmad from customer's requirements.
Programmer loves to make everything perfect, nice and neat and in a moment, when everything goes smoothly, the customer comes with their little silly unimportant requirements!!
Oh, the war wound, aaarrrghhh!
My my, have we learned nothing from tv commercials or George Bush? come on now say it with me, repitition, repitition, repitition. Yes, it is brainwashing, and yes, it works.
In addition to the farcical nature of an article like this (this 1:1 API mapping doesn't begin to get into the nuances in actually going over from a Win32 model (which has things like SEH, IOCP, no signals) to POSIX (which has signals, totally different process and thread model, shared anonymous mappings and forking) many of their examples are written carelessly with no consistent style (which adds to the professionalism), but are outright wrong.
For example, the kill followed by an immediate WNOHANG wait is falacious. There is no guarantee that the thread will be processed by the time the waitpid is called. This is a laughable way of handling child processes, and I don't see how it helps.. I would still have to instruct a Win32 programmer on process hierarchy and SIGCLD semantics.
Next, look at that memory mapping example. They have a mem_shared_struct (I won't even get started on their weird naming conventions), and they define a pointer to one called token. Then they go on to do things like:
*token = malloc and
(*token)->hFileMapping.
What the fuck is that? This "senior programmer" clearly doesn't have a clue when it comes to C. I ask these types of pointer questions as prescreening to entry level candidates.. jeez.
There are probably more egregious errors, but life is too short.
Here's how to migrate applications between operating systems... Use Java ;)
Well, considering that most of the apps i've written under MSVC utilize either MFC ( yea i know its 'orrible but gets the job done ), ATL and COM, with very little direct code interfacing to Win32 layer, this doesnt help much.
For similar app under linux its easier to start from a scratch and just lift the parts of the code that are separate classes/libs with no or little platform-specific dependencies.
http://validator.w3.org/check?uri=http%3A%2F%2Fwww.slashdot.org Errors found while checking this document as HTML5!
It's been basically shown that Macs are not more powerful than PCs for multimedia (cost wise, high-high end PCs are faster asfaik but the cost is insane). Macs aren't slower either so there is no incentive to switch to PCs, but there is also no incentive to switch to Macs (power wise I mean). In other words: they used Macs in the past and they continue to use Macs since it doesn't really matter.
http://sourceforge.net/projects/dxglwrap/
Just expand dxglwrap to incude the functions you use. This is Direct X to opengl. Note there are performance problems ie Slower.
The trick is having a platform independant lib. Openoffice and Mozilla depend on a corelib system.
Note porting from Linux to Mac or Amiga is not a problem. It is just porting from windows due to no standard compad because they did not want it.
Only direct hardware access software not access by a standard lib have problems. Ie direct device access. This is they way it sould be.
What, you don't want to write a macro that converts all the zero length arrays to four^H^H^H^Hone length empty arrays, and modify the allocation to remember that zero means one?
Firstly, Linux users pay for software. Secondly, serious people use Linux. Thirdly, that macs are more powerful is an illusion.
In this world nothing is certain but death, taxes and flawed car analogies.
There are several assumptions that you make that are not that []
.dll.
- Associated performance costs; for most (business related) applications, you don't give a darn. You want it well designed, but the difference in creating a thread? I don't think that would matter much (linux is very probably faster anyway).
- About having a message loop and handlers; it seems to me that this is about an application that is written from the GUI down. If you cannot seperate your core logic from your GUI, there comes a time where you will be hit *big time*, such as when you are going to port your application.
- As for the library that maps the windows calls to linux/posix ones: yes, that could be a good idea in some circumstances, but it might be much harder than you think. You will have an additional library to maintain, and if you expand your original program than you will probably have to expand the library within as well - in the end you'll have another wine.
Obviously if wine works, there might be little reason to bother, but Wine won't work always. A Win32 library for Linux IS wine, stop looking further. Sometimes you need to hack your app this way, for instance if you would want to make a Linux compatible library...not much fun to have a linux library implemented by a
eek!
strcasecmp() ? not quite... (the 'n' still missing... what now?)
They may not be 100% portable, but they are, definitely, not *just as* dependent as Windows programs. Setting a symbolic link pointing to
is that I found it was far too easy to do most of what I wanted without installing openBSD or Linux (Debian or whatever). So I kind of lost my motivation for heading that direction until I can afford to buy a new iBook (I have an old clamshell, which is serving my personal site, and, no, I have not tuned it for a slashdotting, so no urls.) and a couple of Mac Minis.
You gotta watch that trap if you do go with Apple hardware.
One notibly important difference between Win32 and Linux is that the internal Unicode encoding is UTF-8 as opposed to UTF-16LE. This takes some getting used as it requires special consideration when working with text (e.g. when iterating over individual characters). I have prepared a document and a text.h header file [1] that could assist people with porting Win32 applications to Linux. Or at the very least it explains how to maintain I18N support as you migrate code.
[1] The header is part of a library but you can easily remove the library specific #defines.
The (*token)->blah is an example of "Call By Reference" and when using C, that means passing a pointer to a variable rather than the variable itself and using (*foo) everywhere instead of foo.
// call by reference // call by value // cleanup
The code snippets are difficult to understand because they are so severely snipped: we see "return" statements but we don't see any function declaration . With suitable function declarations it would make sense.
Consider for example:
int main()
{
char *x;
scanf( "%as", &x );
printf( "%s\n", x );
free( x );
}
The argument about whether call by reference is good program design is too long and complex to even start on but since the original program was win32, good program design is probably way off the radar anyhow.
Yes. They used Macs in the past and they know how much less Mac OS X needs maintenance than Windows in the long run. Macs save them time and money in getting the job done.
I think there will be a lot of misunderstanding of your reference to power.
The power, for instance, to do stupid things like host your personal web site on your old 300MHz iBook while it is being used as the family computer is a concept that seems to slip right past some people.
The hardest part of porting to LINUX will be refactoring all of the GUI stuff.
.NET, they can also become very useful when porting.
------------
al912912
Haven't you heard of it, I think it might help you in your problem.
Any way, if you are making GUIs in Linux, it's the best way to go.
On the other hand, why isn't everyone talking about mono &
Writing perfectly portable code is possible, but as they say "there ain't no such thing as a free meal." Let's take your DirectX vs OpenGL example, just as a random example, to illustrate the problems.
1. It costs extra time and money.
And it costs time and money to also _test_ it on the new platform. Otherwise you won't even know what functions don't exactly work the same. Or you won't even know that the widget sizes are different on the other platform, and the whole GUI is a disfunctional piece of junk with truncated texts and buttons falling completely out of the dialog box.
(Writing the code is not the alpha and the omega, as you undoubtedly already know. Testing and debugging can easily account for 10 times more time.)
The promised DirectX-vs-OpenGL example: Now _Direct3D_ is pretty much an equivalent of OpenGL. No, not the same function calls, but you can get the same results.
But DirectX offers a lot more than that. Direct3D is just a part of it. You also get networking, sound, etc. If you wanted to stay portable and _only_ use OpenGL, you'd have to write all those extra bits yourself. Which costs time and money.
2. Performance problems, here we come.
Of course, you could just use a wrapper that encapsulates, abstracts and emulates everything. Proper software engineering, right? The problem is: it costs performance.
DirectX-vs-OpenGL fits nicely here too: as fate would have it, Matrox already tried handling that via a wrapper. Back in the days of the G100 and G200, Matrox thought the're smart. No use writing two different 3D libraries that do the same, right? So they actually wrote their OpenGL implementation as a wrapper around DirectX.
The problem? Performance was abysmal. No, not just bad. It _killed_ 3D gaming. With Doom 2 and such being the "killer apps" of video gaming back then, Matrox lost gamer market share (and game developper mind share) with both hands. And who rose like a star? NVidia, who to this day still has the fastest OpenGL implementation.
Just in case you wonder why no games are written using one of those wrapper libraries, now you know why. Because noone wants to make a game that looks like classic ass (low polygon count) or gets single digit FPS. Or both.
3. Those pesky users.
There's one thing that all these emulation and one-lib-to-rule-them-all apologists just don't get: reusing existing skills is good.
When Joe Average gets a Windows app.. actually, screw Joe: when even _I_ get a Windows app, I expect it to look and behave exactly like every other Windows app. No, I don't want it to look like Swing, I don't want it to look like QT, and I sure don't want Mozilla's skinned idiocy, and I'm gonna puke if I have to use another idiotic GTK file dialog in _Windows_, etc. I want it to look and _act_ exactly like one thing: the Win32 widgets. Nothing else.
And if I were on a Mac, I'd expect it to look and feel like on a Mac. I would _not_ want an app that looks and acts like Windows (e.g., wants me to right-click) in the middle of an Aqua desktop.
It's possible to get it right, yes. See for example IBM's SWT widget set for Java. But it's also quite the norm to get it awfully wrong: witness Sun's Swing.
A polar bear is a cartesian bear after a coordinate transform.
and the avoidance thereof, could I suggest?
Sure, the concept stuff is out there, but I have not seen any serious exploits in the wild yet.
If you want to look at it from the customer's perspective, there are more things to consider than market share and water-cooled over-clocked games beasties, fun as the latter are.
If you don't understand and don't know how to ask the question, you won't understand the answer. So why even bother asking?
And source code delivery has nothing to do with it being commercial or free, in either the "beer" or "speech" sense. When the software is important enough, having the source code is an absolute necessity which every system administrator will insist upon. There's a disturbing meme going through the industry that "COTS" (commercial, off-the-shelf) software can be sold without source code. That's bullshit. When your company's business is totally dependent on a system, you must have access to the source code, no matter what the licence is.
Of course it could _help_ in migration even with the source. You could partly port the application and partly extend wine until it ran the application
http://michaelsmith.id.au
If Linux is all that it say it is, why develop a porting mechanism from an 'inferior' OS? Why brute force specific Win32 apps into Linux? Aren't your equivalent native apps suffecient? Or there aren't any at all?
Why bash MS' OS, media player, office yet at the same time green with envy with their 'inferior' products?
I think I hear an echo from Byelorussia
Of course, I also hear an echo from my own stomache.
Somehow, the words, only monopolizing the PC OS market have the strangest ring to them.
In gcc declaring an array of 0 length does not allocate space for the pointer! It's basically an inline memory pointer. Given:
// inline ptr
struct {
int a;
int b[0];
} test;
Assuming a 4 byte int and the object is at address 0. (yes, yes, NULL pointer and all that rot)
sizeof(test) = 4
&test.a = 0x0
&test.b[0] = 0x4
&test.b[1] = 0x8
One use is to allocate the memory yourself and then use the struct to map that memory. The sizeof() would give you the header size. Then (sizeof(header) + allocated data storage) is the total size to alloc.
See: Zero Length (gcc)
IMO, it is a very bad habit to use "type name[0]" when you mean "type* name".
Doing what you claim (sorry, you're AC) is the "Microsoft way" will cause memory corruption in GCC.
There are two kinds of people: 1) those that need closure
A serious point, if IBM is really serious about people to port their Windows apps to "Linux on POWER" (which does have a nice ring to it) then why are all IBM's POWER based systems so expensive?!
;-)
Now Apple can make a PowerPC based system for £339 (BYODKM as Steve might say) why can't IBM create something similar? Preload it Linux and we'd all be happy little "porters". Now if they really wanted us to do this then a laptop would be really great. But presently IBM will only sell expensive POWER systems.
Now after you've ported your "killer app" to LoP, how the heck do you deploy it? On what? Some mega-expensive POWER Server? Doesn't IBM realise that Windows apps are usually run on the desktop or laptop? I mean they're not suggesting we're using Windows as a server OS are they?
PS. Anyone from IBM reading this - yes I would buy an IBM LoP box if it was sub £500 BYODKM.
The same can be applied to GUIs, though for Windows you'll have to write a WinMain wrapper.
Agreed. Closed-source software companies can be extremely abusive in hiding the fact that some crucial element of their software doesn't really work. You may have to use the software for 3 months (off and on, few people can drop everything to evaluate software) to discover that it is so much hassle that it is useless to you.
And once you pay for their software, you have absolutely no recourse. In decades of evaluating software, I've never known a company that listened to their technical support people.
Girls port software for guys!
The guy who can migrate OpenSTA for me gets a crate of Champagne.
Atheism is a non-prophet organisation
Those who aren't working with cross-platform GUIs may not know that WxWindows is now WxWidgets.
See the name change page. Don't use the word "windows" unless you mean a Microsoft product, because Microsoft owns the word in the UK and in the United States.
Corrupt governments don't just support overly broad trademarks against their people, they kill Iraqis for oil profits, too.
Most of the examples/documentation use lpszHungarian notation. Newbies naturally attempt to copy the examples they're given. Newbies make mistakes. As a result, you're likely to see a lot of badly written windows code that uses hungarian notation.
;)
Note: You're also very likely to find very beautiful, very badly written linux code that uses prfx_lwrcs notation. Why? Linux examples are in that style, and linux newbies have access to the indent program.
In conclusion: Newbies will be newbies. Don't judge a style based on what a newbie can break with it.
I cant write code myself, so obviously there is a lot that i dont know. But is it really that hard to write code that is portable?
Part of the problem is that unless a developer tests their code on another platform, you don't know if it is truely portable (unless you are writing a pretty basic application that is compiled with -ansi -pedantic). As you can imagine, a lot of developers will not take the time to do this testing, maynot want to support other platforms, or maynot own other platforms on which to test their code.
-- Mike
This was posted on OSNews.com a while back. Not only did people find lots of typos, but also lots of semantic errors. It appears the author hasn't done much Windows programming and never tried to compile the code samples he displays.
It should be taken with a grain of salt
WhatAboutMacintoshNotationThen?
...of a Linux business model. If you really need an Oracle database, it is because it is a major, vital part of your company where you can accept nothing less but full ACID compliance, replication, load balancing etc. etc. If you could run it without support, you don't need Oracle. Basicly, you're buying an Oracle server which happens to run some OS.
Yes, other sofrware is fairly critical to your business too, like desktops / email / webserver / whatnot. But they are not more critical than that you most of the time can work with the "find stable version, test new version, upgrade to new stable version" kind of support, at least when it comes to non-internet accessible software. And the rest are for many businesses mozilla, apache, openssh and whatever you use for an email server. All well supported by a community, nothing you need commercial support for.
Kjella
Live today, because you never know what tomorrow brings
.
There aren't any hard statistics either which way - the few that I've seen (from IDC) show Linux either matched 1:1 with the Mac or ahead. Which doesn't surprise me - Linux is free and works on Intel PCs, and MacOS X is expensive and only works on dedicated hardware. If Linux does have higher market share that's no reflection on MacOS, just the realities of hte market.
Seems like it would be better to hire a consultant who has win32 and pthread experience to do the porting since that person would know all the gotcha's. I happen to know there are people with those skills available.
I thought that was the best part of it!
... mmmm, spammer!*
*imagines a crocodile picking off Mr. Iwritespam Formoney while he's trying to port "New Smileys For Your Computer!" to Linux
While what you say is true to an extent, I think you're ignoring a valid point. Sure, Microsoft plays fast and loose with its own apps, particularly the menu, toolbar and open/save dialogs. Others tailor the interface somewhat as well. But the vast majority of the conventions -- the things an average user will just assume to work -- are the same in pretty much all native Windows apps. A right-click brings up a context menu. You save your work by going to File->Save, and you'll find the Open, Print and Exit commands in the same place. The max/min/restore buttons are at the top-right of the window if applicable. And so it goes.
Some variations on the theme work very well. I was impressed with the simple but effective variation Firefox has adopted for its "find" feature, for example. Others suck: after my first experience using the GIMP on Windows, when it insisted on trying to use completely unfamiliar UI conventions, I gave up.
But the bottom line is that most native Windows apps do have a high level of UI consistency, and if you're going to vary the theme, it should be for a clear reason (such as the Firefox feature I mentioned) and not just because you're developing an app with an inadequate toolkit that can't handle native widgets properly.
If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
And if I were on a Mac, I'd expect it to look and feel like on a Mac. I would _not_ want an app that looks and acts like Windows (e.g., wants me to right-click) in the middle of an Aqua desktop.
You are 100% right --- ported apps should have "native look and feel" on each platform! A good cross-platform API that has been designed with this goal in mind since the start is wxWidgets.
Unfortunately it doesn't cover the really fun part -- mapping windows Event into pthread's Conditional Variable.
I passed the Turing test.
sometimes, it is much cheaper just to rewrite the entire software in a new platform than having to port the code. at least, you get to improve the previous software in terms of features and all the bad programming stuff. this is problem that we are actually facing, and we decided for ourselves to write applications (and i am still in the process of trying to convince to make it open source in the future.)
Live your life each day as if it was your last.
Ha, I notice you carefully said "Windows generally wins out" and not "Windows is a better option". Because Windows is of course not a "better" desktop OS ... it only "generally wins out" because of other factors not relating to OS quality, and in fact the primary factor is lack of application support (games, business apps etc.). But hang on, this is exactly the topic of the discussion: porting apps to platforms like Mac OS to fix the "lack of application support" problem .. so what was your point again? Actually all you just did is reference the "chicken and egg" problem. And the reason people want to solve this problem is that there are better eggs out there .. or is that better chickens? Whatever. It's "smarter" from a macro-economic perspective because using a better platform increases productivity and efficiency and lowers downtime and training costs, increasing the competitiveness and productivity of the economy, and makes peoples lives easier.
Why the hell would it be smarter to "move apps to OS X"?
To put it another way: it's smarter because allowing yourself (or your customers) to be locked in to a single vendor means that single vendor can charge monopoly ("what the market will bear") pricing for their solutions. In other words, it's smarter because if everyone does it, single-vendors can't extort exorbitant profits from you. If two platform vendors stood on equal footing, unless they fixed prices it would naturally reduce the extortion rates (I don't know about you, but 80% profit margins seem to prove this point!)
Something else to consider is that porting to any second platform from Win32/MFC etc. is usually "the" major step, and porting to a third platform is usually minimal, cost-wise, because once you've ported once, you've already done the vast majority of the work in organizing your code for portability. If you do it right, and choose the right APIs, the cost proportions can look more or less like this e.g.:
This makes a Mac OS port almost a "no-brainer". Oh, and the above example is a real example of a project I'm currently nearing completion of.
No offense, but you seem to make two of them yourself.
1. Basically "if we don't have 100% consistency, we should go for 0% instead". Or, if you will, "bah, you already had a change of look-and-feel some 5 years ago, so suck it up and accept one daily, for each program."
Sorry, no. The real world isn't that clear-cut black-and-white. Sometimes you have to settle for "good enough" instead of "perfect".
2. More importantly, the underlying fallacy is "looks are all that matters." Seein' as what you came up with is flat buttons or different icons.
And that's not just a fallacy, it's also _the_ number one _failure_ of GUIs designed by programmers, graphics artists, marketting, etc. (Though each of them for very different reasons.) Generally anyone else who really has _zero_ clue about usability, and just thinks anything graphical will do.
What I'm more concerned with isn't "waaah, but they changed the 'new folder' icon in XP!" I'm more concerned with how things work. Which is why my point explicitly said "reusing skills" not "reusing graphics."
Take the Windows file open dialog for example. Sure, some apps might add a preview field next to it, or a couple of extra fields, but by and large it stayed the same since Windows '95. You can still do the same things (e.g., creating or renaming a folder right in the list), in the same way, in all apps that use it.
The important thing is: Once you've learned to use it once, you can do it mechanically, without even thinking about it. Even if you just bought/downloaded/compiled/whatever a brand new app, you already know how its file dialog works. That's one less thing to go through a learning curve about.
Now kindly open a GTK dialog box in Windows. E.g., open a file in Gimp. Ugh. WTF is that box? What was wrong with the "normal" box, that needed replacing? Or try it with a Swing app. Ugh. Why does everything look and act differently?
Try to answer those questions _without_ going into technical details about widget sets and libraries. Pretend I'm Joe Average, who doesn't even know what GTK is. And more importantly, who doesn't _care_ about such details. I just want to use the program, with a minimum of learning curve or thinking.
What was wrong, from a _functionality_ point of view, with the old dialog? What end-user functionality absolutely wasn't available through it, so that it needed a completely different dialog?
A polar bear is a cartesian bear after a coordinate transform.
Total Commander 6.5 killed -> magnific Krusader-1.51 + KDiff.
Rational Rose a/o Sparx a/o Visio killed -> niceful Umbrello-1.3.2.
VMWare-4.5.x killed -> marvellous Xen-2.0.4.
open4free © : using QT-3.3.3/KDE-3.3.2
...would be for developers to more strongly commit to the Linux / Open Source platform, develop more games, utils, apps, etc. for Linux, so that there is no more need to migrate to/from Windoze!
You can use the Unix Application Migration Guide.
Reverse as needed.
Wouldn't it be smarter to move apps to OS X?
Only if you prefer the fire to the frying pan. Let us know when Apple supports 95% the available hardware out there.
Time is what keeps everything from happening all at once.
Yes, but only if you have the source code (eg: you created the program, or a windows only OSS project.)
Having gone to a college that only taught windows based programming, this could be very useful. (No I haven't RTFA'd yet)
DarkMantle I been bored, so I started a blog.
and they'll do the work for you. The ACE libraries are invaluable for cross platform network programming (Winsock? What's that?), and the TAO CORBA implementation can't be beat. I prototype code on my Win32 laptop all the time, copy the same source files to solaris, and recompile with no problems. Well, ok, it took a day to get the makefiles straightened out, but now, I can take the
For GUIs, I lean towards Tcl/Tk. It's as cross platform as it needs to be, and GUIs really come together fast with it.
How's my programming? Call 1-800-DEV-NULL
The other nice thing is that a bug that doesn't cause any symptoms on one platform might crash immediately and horribly on another platform. A lot of bugs get caught very early in the development cycle this way, too.
Separating out the GUI is important for real portability. Fortunately, the vast majority of apps can decompose pretty naturally into an "engine" and a "GUI".
Either:- 1) Design for performance 2) Design for portability
It's not impossible to design for both. Indeed, even games can be done this way - look at the original Quake, which had (at least) a software, Glide, and OpenGL renderer, and ran well even on hardware people literally throw out today.
But if you've got an already-written app, the saying above comes into play. Heck, I once worked with an app that had been designed to be portable, but the people writing it hadn't actually run it on anything but Solaris. Moving it even to other Unixes was a real chore; I'd run screaming before trying to port it to Win32.
PHEM - party like it's 1997-2003!
Because I use REALbasic [realsoftware.com] I can deploy my desktop applications on Windows, MacOS Classic, MacOS X and Linux by selecting target platform(s) and pressing a button. The finished apps do not require an installer (everything is in the executable.) REALbasic isn't suitable for everything, but more than adequate for the average desktop program. It has a Visual Basic Project Converter and a nice IDE. It also has OOP RAD. I'm done with C/C++ hell.
I ported a Win32 MFC app which graphed a heartbeat line for a particular metric to wxPython http://wxpython.org/ recently and it's worked out great. It now works on Win32 (nicely wrapped up using py2exe and Nullsoft Installer) as well as any Linux system with the wxWindows libs installed. It was even easy to make a simple curses interface for the hard-core command liners. Our ops team has modifed the code now to measure and graph all kinds of metrics, all of which are multi-platform and don't require compilation via Visual Studio. Highly recommended.
I'm not sure if this should be a reply to someone else's comment, so I'll start anew.
I'm the guy who helped port the gaim-encryption plugin FROM Linux over TO Win32. (The opposite of the article and this topic, I know). But, after I sent the patches back up to the maintainer, he was able to easily carry it in his source tree.
I used Cygwin and MingW to handle the compilation with his original autoconf, etc. build environment. Of course, there was the requisite GTK+ libraries, etc. that went along with it too. But the magic was MingW and Cygwin.
Perhaps this could give the various developers some insight that "it really can be done".
--
3. Don't forget to enjoy!
Namely that you spawn processes and use environment variables as opposed to having a message loop and handlers (the way most windows apps are written).
Time to wakeup and smell the ashes. Any GUI program worth its weight in polystyrene beads has an event (think "message") loop and handlers. On Linux too.
$ cp /mnt/samba/xyzzy/programs/windows_app.exe . ./windows_app
$ objcopy -O elf32-i386 windows_app.exe windows_app
$
I'm afraid that information is also many years out of date. Overheads for unusued RTTI and EH support are almost zero in any decent C++ compiler today.
If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
pthread_mutexattr_setpshared:
Use that and your program will be portable to all platforms which implement pthreads properly. (Maybe even Win32 pthreadsEnjoy,
-- Jamie
Is there a way to portably build portable C++ code?
GNU Make can do it in theory, but it lacks (direct) support for configurations (easy switch between debug and release build), lacks portable generation of dependencies, does not handle interdependencies between projects well (e.g. EXE that depends on DLLs), has difficulties when multiple compilers should build the same source tree (so target dirs for binaries should be separated), and is generally pain in the neck.
Is there a build system that does not require you to change project files (or makefiles or whatever you call them...) when you change the platform or compiler or configuration?
I've had much experience with writing code that compiles on windows and linux and found that when I used a pthreads library on Windows, I had no problems porting the code by changing only a few lines of code.
Avoid Microsoft specific API's. pthread libraries make your code generally compatible and handle all the mapping of the calls for you.
I feel your pain..
WMP can't play jack without hunting down codecs from all over.
I think that's more of an issue with the Windows DirectShow architecture than anything else. (I completely agree that the interface design is fugly, and needs to die die die.) The codec problem is still there in Media Player Classic, which, aside from that, is a rather good media player. (MPC gives better codec-not-found messages than WMP, though.)
I think it's like gPhoto: camera drivers are written modularly, to be camera drivers. They don't come with sixteen different sorts of cutesy crap-ridden software (which has some sort of "friendly" interface made of circles because they're friendlier); they're camera drivers, and that's all they do. Compare that to Windows, where you need to install a different kind of software, never mind a different driver, for a new camera.
Codecs are a bit like that. Want Real codecs? Whoops, you'll need RealPlayer. Want QuickTime codecs? Well, guess what.
There are hacks, like {Real,QuickTime}Alternative, but they're (a) not really legal, and (b) not widely used.
Sometimes I think the lack of mainstream software support for Linux is a good thing.
--grendel drago
Laws do not persuade just because they threaten. --Seneca
Ah, you beat me to it. I'm doing some wxPerl development (for FreeMED) at the moment, and moving from one platform to another is trivial. I especially like the use of native dialogs for file-selection, color-selection, printing and so forth. If it's all done right, you don't even know that the app uses Wx. (I didn't know that Audacity did until quite recently.)
(Though I wish Wx::Config were implemented in the Windows/ActivePerl port. I had much desired to make use of it.)
--grendel drago
Laws do not persuade just because they threaten. --Seneca
I think the "first unix" figures for Linux are dwarfed by those for Mac OSX. I mean, its proponents keep assuring me that it's a "real unix"...
--grendel drago
Laws do not persuade just because they threaten. --Seneca
Windows, Linux. They both systems support processes, threads, semaphores, shared memory, TCP/IP stacks, pipes and files, porting these structures was never that big of a deal. Why do you think most Linux apps still remain CLI? Because the real pain in the butt comes when one needs to port the GUI, since the bulk of the code always seem to be the GUI. Face it, for better or worse Windows remains the #1 windowing system. There are no *nix equivalents to MFC, .NET, VB or the Win32 API. If anyone knows of a good IBM article on how to port a full blown MFC app to GTK+, I'd love to hear about it.
If I'm developing primarily on Linux, what sort of things do I need to look out for to make my application build on other Unices? On Mac OSX, which is sort of a pseudo-Unix in some ways?
Is there a good tutorial for this sort of thing? I'm sure folks would be better at not writing unportable kibble if they just knew better.
--grendel drago
Laws do not persuade just because they threaten. --Seneca
His point is that HN encourages bad code. Not that it enforces it. Like talking on a cell phone in a car encourages bad driving.
And, who knows, maybe he has a valid point. I'm working in Perl at the moment, so my variables, depending how you look at it, are either untyped, or have built-in HN. ($foo is a $calar, @bar is an @rray, and so forth.)
Then again, I have GUI components which might use various widgets, and I need to call different methods on them based on what widget they're using. (GetValue versus GetSelection, for instance.) So I'll call an OK-button $self->{b_ok}, because it helps and because I'm going to use it later.
Though I've never seen the point in labeling every single variable by the Hungarian method. I don't use this for local variables; I use it for maybe one in ten variables, because it helps.
Am I for or against HN? Now I can't even tell. It works for me, sometimes, in some contexts.
--grendel drago
Laws do not persuade just because they threaten. --Seneca
I'm Hungarian, and a progammer, you insensitive clod!
Seriously, Hungarian notation was great... back in the 80's... and only at Microsoft... Let it die already... or at the very least, stop calling it Hungarian... One single Hungarain born, American residing, developer working at Microsoft came up with it... Why the hell don't they call it the charles notation?
---
Programming is like sex... Make one mistake and support it the rest of your life.
I wrote an application that worked on Windows, Unix, Linux, and mainframe. I wrote the GUI separately calling the library function then a simple command line version for Unix.
What I should have done is totally separate the GUI and the application entirely. I could rewrite the GUI in in a portable framework on linux faster than any port of the Windows software. I could then install the framework on all the windows desktops and have them work the same. Not port but total rewrite in a portable framework.
Problem with a lot of GUI code is that the business logic becomes intertwined with the GUI logic. It is incredibly easy to do especially with the Rapid Application Development (RAD) tools and this cause nightmares in porting if your RAD tool is not cross platform.
There was no court loss for WxWidgets. Microsoft challenged the WxWidgets team over the name WxWindows, and they decided not to fight. This was sensible, since the law in Great Britain is more supportive of big companies than even that of the United States.
Story about Lindows: http://www.vnunet.com/news/1130639
It can be done for different operating systems running on exactly the same computer hardware if you are willing to add more complexity (some times the complexity you add to make it portable can exceed the complexity of the program it's self) to your code. But once you factor in different computer hardware, it's usually easier to have a different library of source code at some level than it is to try to write uber-generic code that runs on all computers ever made.
yeah sure .. i knew this option ... but, as far as i remember, last time i checked it not worked properly .. is it possible to use it with completely not related (by fork) processes ? ...
...
anywayz the not-so-famous author of the article did not mention this option at all
I believe it works with NPTL threads (the current Linux threading library) - if you map a file or shared memory so it's visible in both processes, then you can initialise the pshared mutex and use it from both.
With the older LinuxThreads, I'd be surprised if it works.
-- Jamie
yeah .. gotta check it .. as always there are different NPTL support in various kernels/glibc-s .. :)
thanks,
-M
This rather obvious error was the first thing I saw when just glancing quickly at the code. I hope that the rest of IBMs code isn't as shabby.
/ The Arrow
"How lovely you are. So lovely in my straightjacket..." - Nny
...but they don't have that pause at the beginning while a 20MB+ VM spins up, they don't have Microsoft shipping mutant versions of the standard, and they're a lot more fun to write.
Finally, as a Java afficiondo, you can have the best of both worlds in at least two different ways as well.
Got time? Spend some of it coding or testing
Sometimes a program can be a lot more efficient if it wasn't hobbled by starting with the only available native approach to doing things. Portability generally equals abstraction, and that abstraction can be valuable. The incredible number of applications badly nobbled by being jammed into Microsoft's bizarre idea of an MDI is a long-standing example.
And of course the time-consuming part goes away when you factor in the pain in tracking API changes and chasing down weird bugs when you tightly integrate, problems whiach are a lot more transparent with a more generalised set of underpinnings. This is not helped by the lack of alternate debugging platforms, on which you can quickly find out whether the problem lies within your code or the system you're writing to, not to mention flushing out subtler bugs by being able to change fundamental things like endian-ness and word size.
Then when the platform you tightly integrated with gets obsoleted, or your major client(s) change platforms, or the API you integrated with suddenly becomes expensive (as happened with MS-Office after they undermined their visible competition) you're up sheeite creek in a barbed-wire canoe, sans paddle.
Got time? Spend some of it coding or testing
...in an "I link". (-:
Got time? Spend some of it coding or testing
If you can't use 100% Java and most of your Windows specific code is Interface/Graphics related:
Port Windows specific C/C++ code. There shouldn't be too much of it because all GUI code is in Java. So porting process should be quite painless. You still have advantages of C/C++.