How can I statically link a standard library to my C ++ program?

I am using the Code :: Blocks IDE (v13.12) with the GNU GCC compiler.

  • I want the linker to link the static versions of the required runtime libraries for my programs, how can I do this?
  • I already know that my executable file size will increase. Could you tell me about other disadvantages?
  • How to do it in VIsual C ++ Express?

TIA

+4
source share
2 answers

Since no one has yet come up with an answer, I will try. Unfortunately, I do not know what the Code :: Blocks IDE is, so my answer will be only partial.

1 How to create statically linked executable with GCC

IDE, GCC ( ) . , ", " main.cpp ( , ). :

  • main.cpp main.o ( ):

    $ g++ -c -Wall main.cpp
    

    -c GCC ( ). -Wall . , .; -)

  • main.o ( ), main:

    $ g++ -o main main.o -static
    

    -o main GCC a.out ( "" ).

"", .

, :

$ g++ -Wall -o main main.cpp -static

IDE /.

2

:

  • , , , , ​​ .

  • , . , CGI chroot() -.

  • , . ( , , , .)

  • , .

  • (, LAPACK) , , LD_LIBRARY_PATH. , , . , ?

:

  • , . , , , .

  • , , . , .

  • . , (-, ABI) , , . , .

    , , OpenSSL. ​​ Heartbleed, OpenSSL , , . , OpenSSL. , , , , , " " , .

  • " ". , torsocks script ( ) ( LD_PRELOAD ) , Tor. , . ( , , .) "" malloc .. .

, , . : , , .

Alf (. ), GCC ++ , . GCC:

-static-libstdc++

g++ ++, libstd++. libstd++ , -static , libstd++. . libstd++, , . -static-libstdc++ g++ libstd++ , .

+17

Visual ++ /MT , /MD . (. http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx)

/MD ++, Microsoft. ++ , , , . , , . , /MD /MT?

Linux libstd++ . libstd++ , . , libpthread libgcc, . , Linux, .

Mac OS X libstd++. , , .

+1

All Articles