Become a fan of Slashdot on Facebook

 



Forgot your password?
typodupeerror
×
Programming Software IT Technology Linux

Migrate Win32 C/C++ Applications to Linux 393

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)."
This discussion has been archived. No new comments can be posted.

Migrate Win32 C/C++ Applications to Linux

Comments Filter:
  • "windows" (Score:5, Insightful)

    by tonekids ( 465665 ) on Monday February 14, 2005 @02:32AM (#11665384) Homepage Journal
    The hardest part of porting to LINUX will be refactoring all of the GUI stuff.
  • Re:Portable code (Score:5, Insightful)

    by mboverload ( 657893 ) on Monday February 14, 2005 @02:40AM (#11665419) Journal
    That's what alot of FreeBSD people complain about. Programs for Linux are supposed to be so portable, but many times they are just as dependent as their Windows brethren.
  • Re:OS X? (Score:2, Insightful)

    by Anonymous Coward on Monday February 14, 2005 @02:41AM (#11665420)
    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"?
  • by Apoptosis66 ( 572145 ) on Monday February 14, 2005 @02:43AM (#11665429)
    Just moved J2EE webapp from windows to linux. Really nothing to it ;)

    Apoptosis
  • Re:Portable code (Score:5, Insightful)

    by AmberBlackCat ( 829689 ) on Monday February 14, 2005 @02:46AM (#11665441)
    I don't think portability is such a big problem for somebody who has time and resources. I think the biggest problem is people who make software for money are concerned that Linux users want everything to be available for free. And on top of that, a lot of them want it to be open source. So anybody who makes software for a living is going to feel like Linux is a hostile or unprofitable market to enter, unless they're making corporate software.
  • by mingot ( 665080 ) on Monday February 14, 2005 @02:49AM (#11665451)
    I'm taking a C++ class at the local college that's being taught by the Unix guru. The class is using Visual Studio .NET as the IDE (which the instructor is not familar with and is threatening to go to Linux instead).

    No offense, but anyone who can't figure out how to use and become familar enough with the visual studio IDE to use it in a teaching environment shouldn't be called a guru of anything. It's extremely simple to use until you want to start doing very complex things. And that's when you start pining for makefiles. I can't imagine you're writing anything that complex for (what your post would indicate is) an introductory c++ class.

    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).

    Actually, there is. Where it is buried in the settings? Couldn't tell you off the top of my head, but here is something for you to try: Navigate to the directory where the exe is being dumped and run the thing from the command line yourself.

    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. ;) I would like to learn how to program basic C++ fluently on both platforms.

    Not familiar with the book, but unless it is doing something windows specific (and it may be) you should not have any trouble compiling simple programs under gcc and the MS c++ compiler.
  • by Anonymous Coward on Monday February 14, 2005 @02:54AM (#11665466)
    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.

  • by Mystic0 ( 807930 ) on Monday February 14, 2005 @03:02AM (#11665501)

    I take it back when I said "C++ is not supposed to be portable." It really depends. Straight C++ with no OS specific calls should work just fine on any platform. (You'll have to recompile it of course)

    If you are having problems, make sure that there aren't any OS specific calls being used.

  • by Soko ( 17987 ) on Monday February 14, 2005 @03:13AM (#11665538) Homepage
    I don't get it. IBM seems to have some massive aversion to Wine.

    Stop thinking purely as a techie/develper for a second, will you? THINK for a second about the whole, big picture, not just implications for developers.

    IBM is pushing Linux, has it's own line of pretty nice processors and just sold off it's PC division. And now they want native ports of applications to thier chosen OS and platform. Hmmmmm...

    I'm no business genius by any stretch, but do you see any place for Wintel in the picture that's being painted?

    Soko
  • Re:Portable code (Score:5, Insightful)

    by Anonymous Coward on Monday February 14, 2005 @03:16AM (#11665546)
    Nope, it's because people hard code paths (and other distribution dependancies), use the innards of various structs, use /proc, assume the entire world is Intel, assume various GNU options are available for build - configure - install, etc.
  • Re:Portable code (Score:3, Insightful)

    by Anonymous Coward on Monday February 14, 2005 @03:28AM (#11665598)
    Yes, but aren't those details Situation Normal in the *nix world?

    Neither Linux nor FreeBSD have the right to complain about portability because neither strictly follow the Single Unix Specification.
  • Re:Portable code (Score:2, Insightful)

    by starfishsystems ( 834319 ) on Monday February 14, 2005 @03:48AM (#11665660) Homepage
    You can build your program on top of a layer of your own that serves as an interface with whatever API is needed.

    The idea being that all of the portability issues will be confined to the interface layer. Moving to a different platform, or even tracking changes to an existing platform, should then have no effect on the majority of program code, since it lies outside of this layer.

    That's the theory. In practice the effort required can vary a lot from one application to another. The easiest cases are operations which are to be expressed have fairly conventional meaning, for example getting a list of network interfaces from the system. Conversely, the most challenging cases involve fundamentally dissimilar models or capabilities, or else semantic complexity and context that has to be carried around.

    The strategy for the first alternative, if you're committed to portability, is to restrict your design to a modest set of platform capabilities. That's always a good design discipline anyway, so I think you actually come out ahead if you think in terms of portability for any design project, excepting perhaps proofs of concept and other transient projects.

    The second alternative is the really expensive one, since what you're really doing in the interface layer is building some kind of elaborate context management system on top of some other elaborate context management system. And I think this illustrates the point being made by the parent in saying you have to be expecting the contexts you want to support.

  • Re:But... (Score:2, Insightful)

    by Anonymous Coward on Monday February 14, 2005 @03:58AM (#11665691)
    That's because most programs for Linux are written with portability in mind, including the libraries. That's why the Linux code compile fine on other platforms, including Win32, and not always the other way around.
  • by GbrDead ( 702506 ) on Monday February 14, 2005 @04:00AM (#11665698)
    The author might have meant: "Porting Windows programmers to POSIX" :-)
  • Re:Stupid question (Score:0, Insightful)

    by Mercedes308 ( 832423 ) on Monday February 14, 2005 @04:14AM (#11665731)
    Being female is no excuse for not first trying to comprehend the material
    The only person to imply that is you.
  • not much help (Score:3, Insightful)

    by savuporo ( 658486 ) on Monday February 14, 2005 @04:54AM (#11665838)
    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.
  • Yes and no (Score:5, Insightful)

    by Moraelin ( 679338 ) on Monday February 14, 2005 @05:25AM (#11665922) Journal
    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.
  • by MichaelSmith ( 789609 ) on Monday February 14, 2005 @05:31AM (#11665937) Homepage Journal

    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

  • Re:Portable code (Score:3, Insightful)

    by Anonymous Coward on Monday February 14, 2005 @05:35AM (#11665950)
    MSYS [mingw.org] is what you are looking for.
  • Cheap POWER? (Score:4, Insightful)

    by Jezza ( 39441 ) on Monday February 14, 2005 @05:40AM (#11665959)
    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.
  • by KidSock ( 150684 ) on Monday February 14, 2005 @05:49AM (#11665976)
    ... its true power lies in providing windows api's on linux that you can compile against.

    As cool as that would be I seriously doubt people will get very far with this approach. There are too many libraries that WINE simply doesn't support without linking against MS' DLLs. There's structured storage, NDR / RPC, MAPI, workstation management and security network functions, etc, etc, etc. Sure they might have a few individual ops that have been cobbled together using libsmbclient or some OpenLDAP code but the API is not nearly as complete and robust as it needs to be to actually compile a stand alone binary that doesn't require emulation.
  • by Anonymous Coward on Monday February 14, 2005 @06:49AM (#11666150)
    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. ;)
  • Re:Portable code (Score:3, Insightful)

    by DrXym ( 126579 ) on Monday February 14, 2005 @07:11AM (#11666197)
    To be frank, those things are trivial to fix and can be expected when moving any Unix program to some other platform. Once a program goes through a few iterations, gains an autoconf script and some maintainers, it will build and run happily on lots of platforms.

    Contrast that with Win32 vs Linux where the API is different, the compiler is different, the build system is different, the underlying OS is totally different etc.

  • by kemelma ( 610569 ) on Monday February 14, 2005 @07:33AM (#11666248)
    yeah right .. and how'd you treat WaitForMultipleObjects ? as far as i can see Wine does not solve this ... at least i can't see how can you solve this effectively without kernel intervention ...
  • Re:Yes and no (Score:5, Insightful)

    by Quattro Vezina ( 714892 ) on Monday February 14, 2005 @08:33AM (#11666428) Journal
    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.

    That's a fallacy. Windows hasn't had anything resembling a consistent look and feel since Windows 3.1, if even then.

    Even Windows applications made by Microsoft don't have a consistent look and feel. IE draws its own widgets. Office not only draws its own widgets, but it drastically changes those widgets with every version (fyi, Office XP was patterned on a theme for the WinXP beta that MS later decided not to include in Windows). Same goes with Windows Media Player--it's even less consistent than Office. Visual Studio does the same thing--try running VS2003 on Windows 2000 and you'll see what I mean.

    Speaking of Office, not only does it draw its own widgets, but it creates its own open and save dialogs. Office 2000's open and save dialogs look like the Windows 2000 dialogs, but they still look like the Windows 2000 dialogs even on older versions of Windows. "Older versions of Windows" also includes Windows NT 3.x. Try running Office 97 or 2000 on NT 3.x and note the stark contrast between Office's 3D widgets and NT's fugly flat widgets.

    Also, I'll add that some of the most popular non-Microsoft 3rd party apps do this as well. WinAmp was the most popular media player on Windows for a long time, and it never had anything remotely resembling the Win32 widgets.
  • Hey! (Score:2, Insightful)

    by ggvaidya ( 747058 ) on Monday February 14, 2005 @08:59AM (#11666519) Homepage Journal
    I thought that was the best part [wikipedia.org] of it!

    *imagines a crocodile picking off Mr. Iwritespam Formoney while he's trying to port "New Smileys For Your Computer!" to Linux ... mmmm, spammer!*
  • Re:Portable code (Score:5, Insightful)

    by dustmite ( 667870 ) on Monday February 14, 2005 @09:45AM (#11666754)

    Reduced efficiency I'll give you, but because (and only because) Win32 and MFC are such mind-numbingly bad APIs, writing portable code can often be a massive time-saver if you use more well-designed libraries, like wxWidgets [wxwidgets.org] ... for our company's main project, I estimate that choosing wxWidgets over Win32 or MFC easily cut down development time by 30% (and that's in spite of our developers all having Win32/MFC experience). And as a bonus, our code is now only a stone's throw away from Linux and Mac ports, which we fully intend on developing.

  • Re:Portable code (Score:1, Insightful)

    by Anonymous Coward on Monday February 14, 2005 @09:50AM (#11666803)
    Qt (which is much more than just a GUI library) will be available in GPL form on Windows soon, making it a good choice for open-source programs.

    Sadly, not as good as you might think. All non-standard toolkits - and Java, GTK, and .NET have the same problem - suffer from the fact that you either have to distribute the toolkit with your program (which feels kind of silly when the program is 300 KB and the toolkit is 20 MB), or you have to tell your users to get the toolkit if they don't have it already (which confuses the fuck out of most people, who don't know whether they have it or not, and still irritates them when they have to download a 20 MB toolkit just to run a 300 KB program).

    For traditional CD-based apps, or large apps where the toolkit is not disproportionately large compared to the program, it can make sense. But for most people it just doesn't work.

    Even wxWidgets, which proudly proclaims that it uses native widgets, adds a couple of megabytes to the download. That MORE THAN DOUBLES the size of most programs. Doubling the size is not exactly convenient in a world where many people still use dialup connections...
  • The real falacies (Score:5, Insightful)

    by Moraelin ( 679338 ) on Monday February 14, 2005 @10:58AM (#11667464) Journal
    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?
  • by oo_waratah ( 699830 ) on Monday February 14, 2005 @07:18PM (#11673003)
    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.

Remember to say hello to your bank teller.

Working...