• C

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

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?

Who is Participating?

Improve company productivity with a Business Account.Sign Up

Martin_J_ParkerConnect With a Mentor Commented:
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.

Kent OlsenData Warehouse Architect / DBACommented:
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,
ventumsolveAuthor Commented:
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.

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Kent OlsenConnect With a Mentor Data Warehouse Architect / DBACommented:
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.

ssnkumarConnect With a Mentor Commented:
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.
ventumsolveAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.