gpt4 book ai didi

c++ - mingw 非常非常简单的代码,报告对XXX的 undefined reference

转载 作者:太空狗 更新时间:2023-10-29 21:32:49 24 4
gpt4 key购买 nike

extern int aabbcc;
void fun1()
{
aabbcc = 1;
}

用mingw编译

i686-w64-mingw32-gcc -shared -o a.dll a.c

报告错误:对'aabbcc'的 undefined reference

用linux gcc编译就可以了

gcc -fPIC -shared -o liba.so a.c

为什么? linux-gcc 和 mingw 有什么区别?

最佳答案

在 Linux 中,.so 文件允许有 undefined reference 。当 .so 加载到进程中时,它会尝试在任何其他 .so 或主程序中找到引用。 .so 甚至不必知道引用对象的位置。

在 Windows 中,.dll 文件不允许有 undefined reference 。 .dll 必须定义引用的对象本身,或者告诉加载程序在哪个其他 .dll 中找到该对象。

关于c++ - mingw 非常非常简单的代码,报告对XXX的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53644675/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com