views:

257

answers:

4

hey, I know how to use g++ and all that to compile c++ programs. My question is, if I have some code which depends on various libraries, how can I compile it into a simple executable that I can send anyone. For this I would be happy with just keeping it on os x.

I would like to know how to compile a "real" program not just an executable I can run locally. I have tried googling this but haven't found much.

Do I have to use installing software? I know in windows you can make some simple .exe stuff that use common DLL files

Any help would be appreciated, Thanks

+6  A: 

You a looking for "static linking". That will import all the needed code from the libraries into your executable. Note the executable will get larger. If you are using standard libraries, they should be present on standard OS installation.

You should try "-static" flag of g++. Running "ldd your_executable_name" should display all libraries your executable uses (linked dynamically).

Drakosha
on os x ldd = otool -L executable, if anyone cares
Ori Cohen
A: 

You can use -static or -s option for static linking in gcc or g++

Hongseok Yoon
+2  A: 

Since you are talking about Mac OS X, you probably want to make a bundle. Qt Software has a very useful deployment guide for getting started with this kind of activity.

Ringding
A: 

Drakosha is absolutely right.

Here's a link that explains in some depth.

Eric J.