-static-libgcc | 在gcc/g++或ld中加上这个参数, 就可以不用libgcc_s_dw2-1.dll |
-static-libstdc++ | 在g++或ld中加上这个参数, 就可以不用libstdc++-6.dll |
-static | 在gcc/g++或ld中加上这个参数, 對所有的库都会采用静态链接的方式 |
D:\lmyst\Documents\Cproject>g++.exe -static-libgcc test.cpp -o test.exe
D:\lmyst\Documents\Cproject>g++.exe -static-libstdc++ test.cpp -o test.exe
D:\lmyst\Documents\Cproject>g++.exe -static test.cpp -o test.exe
3. 在程序中链接静态库
gcc test.c -lhello -L. -static -o hello.static
或者 gcc test.c libhello.a -L. -o hello.static
暂时测试的是cpp文件。
.c和.cpp的大致区别很明显就能看出来,一个表示C的源程序,一个表示C++的源程序,那么我们今天结合gcc/g++来看一下它们的区别。
可以看到g++无论是对.c文件还是.cpp文件都是按C++的方式编译的,这是和gcc是有区别的。gcc会根据文件后缀名来确定编译方式,而g++只有C++的编译方式。