Thread: Porting an Executable from one Unix box to another.

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    1

    Porting a C Executable from one Unix box to another.

    I am new to the C language and unix as this question may imply.
    This question was asked of me and my initial thought was why not.

    Q: Can a C Source compiled executable be ported from one Unix box to another.


    If anyone can confirm or deny my initial thoughts with some details it would be greatly appreciated.
    Last edited by CTGEO33; 04-05-2011 at 02:30 PM. Reason: clarify title

  2. #2
    Registered User \007's Avatar
    Join Date
    Dec 2010
    Posts
    179
    Statically compiled or dynamic? What kinds of libraries were used etc? I guess the answer is, "It depends."

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Most likely the answer is no. Not only might static vs dynamic libraries matter, but what version of the library you use and what target architecture that library was compiled for. It also depends on what hardware you're running on, what flavor of Unix you're using and what version of the kernel you're using. And those are only the issues with the most basic C programs.

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    It's not generally possible, but it can work in some cases.

    Most importantly, the architectures must be compatible -- you can't execute SPARC code on an x86 for instance. If the architectures are compatible, the system call API/ABI must be compatible as well. If the system call API/ABI is compatible, any dynamic dependencies (shared objects) must also be compatible.

    For instance, you can run FreeBSD executables on Linux, and you can run Linux executables on FreeBSD, in certain cases. Also consider Wine, which runs Windows executables on Linux.

    Some really hairy stuff is going on behind the scenes to actually make that work. It's a last-resort sort of thing.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by CTGEO33 View Post
    Q: Can a C Source compiled executable be ported from one Unix box to another.
    A: Sure:
    Code:
    #include<stdio.h>
    int main( void )
    {
        printf( "Hello World!\n" );
        return 0;
    }
    If your code is 100% standard C, then of course you can.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    The second Unix box should be of the same architecture as the first. Even then, it's still not guaranteed to work.
    Quote Originally Posted by The Jargon File
    Microsoft Windows - A thirty-two bit extension and graphical shell to a sixteen-bit patch to an eight-bit operating system originally coded for a four-bit microprocessor which was written by a two-bit company that can't stand one bit of competition.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Porting a large C project from unix to windows
    By somekid413 in forum C Programming
    Replies: 6
    Last Post: 09-23-2010, 03:24 PM
  2. Setting up a Unix box
    By @nthony in forum Tech Board
    Replies: 6
    Last Post: 07-22-2007, 10:22 PM
  3. How to program a "back" button with MFC
    By 99atlantic in forum Windows Programming
    Replies: 3
    Last Post: 04-26-2005, 08:34 PM
  4. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 08:00 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM