如何让MinGW 默认链接时带 -static 参数呢?

iomato 2013-04-03 07:05:22
想让 MinGW 在编译时默认静态链接,编译出的exe不依赖其他dll运行,在编译时不用加上 -static参数,而是让其自动带上这一参数...同时动态时编译std::thread会出问题:


H:\c++>g++ std.thread.cpp -std=c++11

H:\c++>a.exe
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

H:\c++>g++ std.thread.cpp -std=c++11 -static

H:\c++>a.exe can run now



下面是MinGW configure时的参数:

H:\c++>g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=h:/app/mingw32/bin/../libexec/gcc/i686-w64-mingw32/4.9.0/lto
-wrapper.exe
Target: i686-w64-mingw32
Configured with: /mnt/build/src/gcc/configure --host=i686-w64-mingw32 --build=x8
6_64-linux-gnu --target=i686-w64-mingw32 --with-sysroot=/mnt/build/mingw32mingw3
2/mingw32 --prefix=/mnt/build/mingw32mingw32/mingw32 --with-gmp=/mnt/build/prere
q/i686-w64-mingw32/install --with-mpfr=/mnt/build/prereq/i686-w64-mingw32/instal
l --with-mpc=/mnt/build/prereq/i686-w64-mingw32/install --with-cloog=/mnt/build/
prereq/i686-w64-mingw32/install --disable-cloog-version-check --with-isl=/mnt/bu
ild/prereq/i686-w64-mingw32/install --enable-cloog-backend=isl --with-host-libst
dcxx='-static -lstdc++ -lm' --enable-shared --enable-static --enable-threads=pos
ix --enable-plugins --disable-multilib --enable-languages=c,lto,c++ --enable-lib
gomp --disable-dw2-exceptions --enable-sjlj-exceptions --enable-fully-dynamic-st
ring --enable-libstdcxx-time --disable-nls --disable-werror --enable-checking=re
lease --with-gnu-as --with-gnu-ld --disable-win32-registry --disable-rpath --dis
able-werror --with-libiconv-prefix=/mnt/build/prereq/i686-w64-mingw32/install --
with-pkgversion=4.8-stdthread-edu CC= CFLAGS='-O2 -march=nocona -mtune=core2 -fo
mit-frame-pointer -momit-leaf-frame-pointer' CXXFLAGS='-O2 -march=nocona -mtune=
core2 -fomit-frame-pointer -momit-leaf-frame-pointer' LDFLAGS=' -Wl,--large-addr
ess-aware' 'BOOT_CFLAGS=-O2 -march=nocona -mtune=core2 -fomit-frame-pointer -mom
it-leaf-frame-pointer' 'BOOT_CXXFLAGS=-O2 -march=nocona -mtune=core2 -fomit-fram
e-pointer -momit-leaf-frame-pointer' 'BOOT_LDFLAGS= -Wl,--large-address-aware' '
CFLAGS_FOR_TARGET= -O2 -march=nocona -mtune=core2 -fgraphite-identity -floop-int
erchange -floop-block -floop-parallelize-all' 'CXXFLAGS_FOR_TARGET= -O2 -march=n
ocona -mtune=core2 -fgraphite-identity -floop-interchange -floop-block -floop-pa
rallelize-all' LDFLAGS_FOR_TARGET=
Thread model: posix
gcc version 4.9.0 20130402 (experimental) (4.8-stdthread-edu)


谢谢!
...全文
290 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
iomato 2013-06-23
  • 打赏
  • 举报
回复
引用 1 楼 goodboy1881 的回复:
如果跟线程有关,在编译的时候需要加上 -pthread。 另外,你做静态链接得保证你所有的库都有静态库版本。
虽然没有解决我的问题,但就你回答了,散分结贴
iomato 2013-04-08
  • 打赏
  • 举报
回复
引用 1 楼 goodboy1881 的回复:
如果跟线程有关,在编译的时候需要加上 -pthread。 另外,你做静态链接得保证你所有的库都有静态库版本。
在Win下加不加 -pthread 都一样,都是那个错,只能 -static 静态编译才能运行,我是想怎么让它在链接时默认带上 -static 参数(是不是得修改编译GCC时的参数,或修改源码)
积木 2013-04-07
  • 打赏
  • 举报
回复
如果跟线程有关,在编译的时候需要加上 -pthread。 另外,你做静态链接得保证你所有的库都有静态库版本。

24,855

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧