这是gcc命令,用于构建C应用程序
gcc -o bs bs/src/main3.c bs/src/gui.c bs/src/calc.c -mms-bitfields - Ic:/gtk3_32/include/gtk-3.0 -Ic:/gtk3_32/include/cairo -Ic:/gtk3_32/include/pango-1.0 -Ic:/gtk3_32/include/atk-1.0 -Ic:/gtk3_32/include/cairo -Ic:/gtk3_32/include/pixman-1 -Ic:/gtk3_32/include -Ic:/gtk3_32/include/freetype2 -Ic:/gtk3_32/include -Ic:/gtk3_32/include/libpng15 -Ic:/gtk3_32/include/gdk-pixbuf-2.0 -Ic:/gtk3_32/include/libpng15 - Ic:/gtk3_32/include/glib-2.0 -Ic:/gtk3_32/lib/glib-2.0/include -Lc:/gtk3_32/lib -lgtk-3 -lgdk-3 -lgdi32 -limm32 -lshell32 -lole32 -Wl,-luuid -lpangocairo-1.0 - lpangoft2-1.0 -lfreetype -lfontconfig -lpangowin32-1.0 -lgdi32 -lpango-1.0 -lm - latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 - lglib-2.0 -lintl
有诸如
-Bstatic
但我不知道放在哪里?在-Wl标志之后?
我在下面尝试了答案,并进行了编译,但是exe的大小是相同的,并且没有gtk文件夹(已删除它的临时文件),该exe无法启动。因此,它仍然取决于某些dll。我将标志(-Bstatic)放在-mm-bitfields之后:
gcc -o bs bs/src/main3.c bs/src/gui.c bs/src/calc.c -mms-bitfields -Bstatic -Ic:/gtk3_32/include/gtk-3.0 -Ic:/gtk3_32/include/cairo -Ic:/gtk3_32/include/pango-1.0 -Ic:/gtk3_32/include/atk-1.0 -Ic:/gtk3_32/include/cairo -Ic:/gtk3_32/include/pixman-1 -Ic:/gtk3_32/include -Ic:/gtk3_32/include/freetype2 -Ic:/gtk3_32/include -Ic:/gtk3_32/include/libpng15 -Ic:/gtk3_32/include/gdk-pixbuf-2.0 -Ic:/gtk3_32/include/libpng15 -Ic:/gtk3_32/include/glib-2.0 -Ic:/gtk3_32/lib/glib-2.0/include -Lc:/gtk3_32/lib -lgtk-3 -lgdk-3 -lgdi32 -limm32 -lshell32 -lole32 -Wl,-luuid -lpangocairo-1.0 -lpangoft2-1.0 -lfreetype -lfontconfig -lpangowin32-1.0 -lgdi32 -lpango-1.0 -lm -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lintl
最佳答案
-B
标志会影响其后的所有-l
标志。因此,例如,如果您有:
gcc -o my_prog my_prog.c -llib1 -llib2 -Bstatic -llib3 -llib4
然后
lib1
和lib2
是动态链接的,而lib3
和lib4
是静态链接的。编辑:
-B选项应立即位于一个或多个
-l
选项之前。因此,如果您想静态链接所有内容,可以这样做:gcc -o bs bs/src/main3.c bs/src/gui.c bs/src/calc.c -mms-bitfields -Ic:/gtk3_32/include/gtk-3.0 -Ic:/gtk3_32/include/cairo -Ic:/gtk3_32/include/pango-1.0 -Ic:/gtk3_32/include/atk-1.0 -Ic:/gtk3_32/include/cairo -Ic:/gtk3_32/include/pixman-1 -Ic:/gtk3_32/include -Ic:/gtk3_32/include/freetype2 -Ic:/gtk3_32/include -Ic:/gtk3_32/include/libpng15 -Ic:/gtk3_32/include/gdk-pixbuf-2.0 -Ic:/gtk3_32/include/libpng15 -Ic:/gtk3_32/include/glib-2.0 -Ic:/gtk3_32/lib/glib-2.0/include -Lc:/gtk3_32/lib -Bstatic -lgtk-3 -lgdk-3 -lgdi32 -limm32 -lshell32 -lole32 -Wl,-luuid -lpangocairo-1.0 -lpangoft2-1.0 -lfreetype -lfontconfig -lpangowin32-1.0 -lgdi32 -lpango-1.0 -lm -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lintl
编辑2:
对于gcc,用于静态链接的标志实际上是
-static
,对于动态链接,它的标志是-dynamic
。