Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compiling c++ into "real" programs

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.

like image 971
Ori Avatar asked Aug 06 '09 06:08

Ori


1 Answers

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

like image 95
Drakosha Avatar answered Nov 10 '22 08:11

Drakosha