Question

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.

Was it helpful?

Solution

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).

OTHER TIPS

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top