__imp 使用在 mingw 下运行的 g++ 链接错误 [英] __imp link errors using g++ running under mingw

查看:72
本文介绍了__imp 使用在 mingw 下运行的 g++ 链接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的套接字程序,我正在尝试使用在 Win8 系统上的 mingw(均为最新版本)中运行的 g++ 进行编译.我遇到了常见的链接器错误

I have a simple socket program that I'm trying to compile using g++ running in mingw (both the latest versions) on a Win8 system. I'm getting the common linker errors

undefined reference to `__imp_socket'
undefined reference to `__imp_gethostbyname'

我试过添加 -lws2_32 没有运气;即它仍然找不到引用.有人可以建议我可能遗漏的其他内容吗?

I've tried adding -lws2_32 with no luck; i.e. it still can't find the references. Can someone suggest something else I might be missing?

这是完整的输出:

G:\source\kak>g++ -o ./test_client -lws2_32 test_client.C
C:\Users\kenkahn\AppData\Local\Temp\ccDZTr9b.o:test_client.C:(.text+0x4f): undefined reference to `__imp_inet_addr'
C:\Users\kenkahn\AppData\Local\Temp\ccDZTr9b.o:test_client.C:(.text+0x6b): undefined reference to `__imp_socket'
C:\Users\kenkahn\AppData\Local\Temp\ccDZTr9b.o:test_client.C:(.text+0x8b): undefined reference to `__imp_connect'
d:/program files/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\kenkahn\AppData\Local\Temp\ccDZTr9b.o: bad reloc address 0xc in section `.xdata'
collect2.exe: error: ld returned 1 exit status

推荐答案

尝试将 -lws2_32 放在 test_client.C 参数之后.gcc (ld) 的链接器对可链接事物的顺序很敏感,这可能是它在链接时找不到您导入的函数的原因.

Try putting the -lws2_32 after the test_client.C parameter. The linker of gcc (ld) is touchy about the order of linkable things, this is probably why it doesn't find your imported functions at link time.

这篇关于__imp 使用在 mingw 下运行的 g++ 链接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆