You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在RHEL编译Windows版ASCO时遇/bin/ld: cannot find -lws2_32错误求助

解决编译ASCO时"/bin/ld: cannot find -lws2_32"错误

问题原因

-lws2_32是Windows平台专属的套接字链接库,你当前使用的是系统原生gcc而非MinGW交叉编译器,系统gcc无法识别Windows平台的库文件,因此触发报错。

解决方案

1. 指定MinGW交叉编译器路径

修改Makefile.win中的CC变量,替换为对应MinGW版本的交叉编译器:

  • 编译64位Windows程序:x86_64-w64-mingw32-gcc
  • 编译32位Windows程序:i686-w64-mingw32-gcc

若需要编译MPI版本,CC_MPI也需使用适配MinGW的mpicc(需提前安装MinGW版MPI库)。

2. 修改后的Makefile.win示例

#
CC = x86_64-w64-mingw32-gcc
CC_MPI = <FULL_PATH_TO_MINGW_MPICH>/bin/x86_64-w64-mingw32-mpicc
CFLAGS = -Os


#
all: asco asco-test alter log monte postp

asco-test:
    $(CC) $(CFLAGS) -DDEBUG -DASCO -o asco-test.exe auxfunc.c auxfunc_alter.c auxfunc_monte.c auxfunc_measurefromlis.c rfmodule.c initialize.c errfunc.c evaluate.c asco-test.c -lm -lws2_32

asco:
    $(CC) $(CFLAGS) -DASCO -o asco.exe auxfunc.c auxfunc_alter.c auxfunc_monte.c auxfunc_measurefromlis.c rfmodule.c initialize.c errfunc.c evaluate.c de36.c hooke.c nmlatest.c asco.c -lm -lws2_32

asco-mpi:
    $(CC_MPI) $(CFLAGS) -DASCO -DMPI -o asco-mpi.exe auxfunc.c auxfunc_alter.c auxfunc_monte.c auxfunc_measurefromlis.c rfmodule.c initialize.c errfunc.c evaluate.c de36.c hooke.c nmlatest.c asco.c -lm -lws2_32

alter::
    make -C tools/alter/ -f Makefile.win32 CC=x86_64-w64-mingw32-gcc

log::
    make -C tools/log/ -f Makefile.win32 CC=x86_64-w64-mingw32-gcc

monte::
    make -C tools/monte/ -f Makefile.win32 CC=x86_64-w64-mingw32-gcc

postp::
    make -C tools/postp/ -f Makefile.win32 CC=x86_64-w64-mingw32-gcc

clean::
    rm -f asco.exe asco-test.exe
    rm -f tools/alter/alter.exe
    rm -f tools/log/log.exe
    rm -f tools/monte/monte.exe
    rm -f tools/postp/postp.exe

注意:替换<FULL_PATH_TO_MINGW_MPICH>为你实际的MinGW版MPICH路径,若不需要MPI版本可忽略asco-mpi目标。

3. 补全MinGW依赖库

在RHEL8上执行以下命令,确保安装MinGW的基础库包:

sudo dnf install mingw64-gcc mingw64-winpthreads-static mingw64-winpthreads-devel

(编译32位程序则替换为mingw32-*前缀的包)

4. 重新编译

执行make -f Makefile.win启动编译,此时MinGW编译器会自动从自身库路径中找到ws2_32库。

内容的提问来源于stack exchange,提问作者Asdf

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 08:01:23