How to compile it under linux and win32

This is a discussion on How to compile it under linux and win32 within the C Programming forums, part of the General Programming Boards category; Hi! How do I write a code so that will be compiled in Win32 and Linux enviroment with no changes ...

  1. #1
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    Question How to compile it under linux and win32

    Hi!

    How do I write a code so that will be compiled in Win32 and Linux enviroment with no changes in a code? Do I have to use the "#if", "#endif" preprocessor commands? If yes then please tell me how. And how to determine in which enviroment the user compiles the code?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #2
    ggs
    ggs is offline
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    simplest way:

    #if defined(LUNIX)

    /* linux specific code */

    #elif defined(WINDOWS)

    /* windows specific code */

    #elif etc...

    /* final case */

    #endif

    often, you can write code which works under both naturally... this can get very messy. if the project is complex enough, it's probably better to have seperate source trees
    .sect signature

  3. #3
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Alright. But will the VC++ .NET recognize the __Linux__? What about other OS's (Windows, UNIX, ...)?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  4. #4
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    I don't have this library.

    Is there any other way to detect OS?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  5. #5
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    I suppose you could have it check for the Windows registry and look for a specific phase like the version. As for the library, all I'm finding on Google.com are links to information on it and not any actual downloads.

    According to those sites, its a GNU C library, so it might be included with GCC someplace (Linux perhaps).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WIN32 API and Linux... *shudder
    By parad0x13 in forum C++ Programming
    Replies: 4
    Last Post: 07-24-2008, 08:27 PM
  2. Linux equivalent to Win32 ShellExecute
    By BobS0327 in forum Linux Programming
    Replies: 4
    Last Post: 06-07-2006, 05:35 AM
  3. Difference between win32 and linux pthreads
    By philipsan in forum C Programming
    Replies: 1
    Last Post: 02-07-2006, 04:57 PM
  4. Replies: 1
    Last Post: 10-24-2005, 07:35 AM
  5. compiling win32 apps under linux?
    By talz13 in forum Linux Programming
    Replies: 11
    Last Post: 02-07-2005, 12:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21