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

极简CygWin环境编译C++程序遇_imp__未定义引用错误求助

CygWin极简GCC环境下C++编译链接错误排查

环境与测试代码

  • 仅安装gcc的极简版CygWin环境
  • 测试C++代码:
#include <cstdio>

int main()
{
  printf("asdf");
  return 0;
}

编译命令与错误信息

执行编译命令:

gcc a.cpp -L/cygdrive/c/windows/system32

触发链接错误:

ld: /usr/lib/gcc/i686-pc-cygwin/11/crtbegin.o:cygming-crtbeg:(.text+0x2c): undefined reference to `_imp__LoadLibraryA@4'
ld: /usr/lib/gcc/i686-pc-cygwin/11/crtbegin.o:cygming-crtbeg:(.text+0x32): undefined reference to `_imp__GetProcAddress@8'
ld: /usr/lib/gcc/i686-pc-cygwin/11/crtbegin.o:cygming-crtbeg:(.text+0xd6): undefined reference to `_imp__FreeLibrary@4'
collect2: error: ld returned 1 exit status

同时出现若干同类警告。此前曾通过添加kernel32.dll路径解决过类似错误,但本次问题仍存在,怀疑缺少包含_imp__前缀相关功能的库。

补充细节

  • .s汇编文件可正常编译通过
  • 尝试使用mingw32 C编译器时,出现约20条错误,多数为_imp__相关符号未定义,还涉及__acrt_iob_func、_set_invalid_parameter_handler、mark_section_writeable、matherr等符号/函数。

更新追踪信息

用strace执行编译命令,输出显示程序尝试创建a.exe文件,但最终将该文件删除,需要解读这一现象。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 19:02:00