how do I create an executable to run on a machine - same platform - but no devel-stuff

Posted on 2011-03-10
Last Modified: 2012-05-11
I have a small c-program and would like it to run on a similar platform as mine (OS X, 10.6)  but on the customer server there's no xcode installed so I can't compile the program on his computer. Can I compile it on mine where I have all the headers in a way where the headers will be included in the executable out-file? So say references to time.h, string.h etc will work?

Question by:ventumsolve
LVL 45

Expert Comment

ID: 35094864
Hi ventum,

If you compile and link the program into a self-contained executable, it should run just fine on any computer running the same operating system.

If the program uses shared libraries, dll files, etc., then you might have to do some more work.  But unless you specifically code to these shared libraries you won't be using them.

Just compile the program, run the executable (test it), and copy it to the other computer.

Good Luck,
LVL 10

Accepted Solution

Martin_J_Parker earned 250 total points
ID: 35094904
If you can, link the program statically so that it won't use any dynamic libraries.  That way you won't have anything missing at the client end.  A lot of compilers have a -static or -Bstatic option to allow you to do that.


Author Comment

ID: 35095031
Apparently the static option will not work on mac 10.6. So there's no way around installing xcode I guess?

The man gcc says:
           On systems that support dynamic linking, this prevents linking
           with the shared libraries.  On other systems, this option has no

           This option will not work on Mac OS X unless all libraries
           (including libgcc.a) have also been compiled with -static.
           Since neither a static version of libSystem.dylib nor crt0.o are
           provided, this option is not useful to most people.

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

LVL 45

Assisted Solution

Kdo earned 125 total points
ID: 35095065
Hi ventum,

That basically means that you're going to have to just test it.

My expectation is that the shared libraries will be on each system to that the program should run fine.  You won't even know that the shared libraries are involved.


Assisted Solution

ssnkumar earned 125 total points
ID: 35104959
ventumsolve> So say references to time.h, string.h etc will work?
Yes. You will be including these files using #include directive.
This is just like a preprocessor directive and hence all the contents of time.h, string.h, etc will be added to your .c file itself before compilation.
So, you don't need to have time.h, string.h, etc on the computer where you will be executing this code.

But, if you are specifying any libraries during compilation (compiler will make use of some standard libraries and they should be there in the target computer also by default), you will have to make sure that they are present in the target computer also.

If you are not specifying any libraries during compilation, then no need to worry.
Your code should run without any problem on the destination computer also.

Author Closing Comment

ID: 35133202
Meanwhile .. customer installed xcode so the problem sort of disapeared. However .. I never got a working executable. Perhabs because target server was 10.5 whereas source was 10.6. Was playing with CFLAGS= -mmacosx-version-min=10.5 when customers notification about xcode saved my day.

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Why does my while loop in C run indefinitely? 10 90
Inorder binary search tree 5 153
C++ vs C compilers 13 155
sameEnds challenge 3 106
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now