Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mingw very very simple code, report undefined reference to XXX

Tags:

c++

c

gcc

cygwin

mingw

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

compile it with mingw

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

reports error: undefined reference to 'aabbcc'

compile it with linux gcc, it is ok

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

WHY ? what is the different between linux-gcc and mingw ?

like image 571
LCY Avatar asked Nov 26 '25 08:11

LCY


1 Answers

In Linux, .so files are allowed to have undefined references. When the .so is loaded into a process, it tries to find the reference in any other .so or the main program. The .so doesn't even have to know where the referenced object is located.

In Windows, .dll files are not allowed to have undefined references. The .dll has to either define the referenced object itself, or tell the loader which other .dll to find the object in.

like image 186
user253751 Avatar answered Nov 27 '25 22:11

user253751



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!