Function referenced in section `.text’ of …: defined in discarded section `.text’

I get an error from i686-w64-mingw32-gcc (please see subject) when linking a c-source file using CMake containing a call to Sleep(). I would like to know the reason for this in order to solve the problem.

This is the invocation of the compiler:

/usr/bin/i686-w64-mingw32-gcc   -g @CMakeFiles/MQTTAsync_publish.dir/includes_C.rsp   -o CMakeFiles/MQTTAsync_publish.dir/src/samples/MQTTAsync_publish.c.obj   -c /tmp/org.eclipse.paho.mqtt.c/src/samples/MQTTAsync_publish.c

The archiver:

/usr/bin/i686-w64-mingw32-ar cr CMakeFiles/MQTTAsync_publish.dir/objects.a @CMakeFiles/MQTTAsync_publish.dir/objects1.rsp

The linker:

/usr/bin/i686-w64-mingw32-gcc  -g  -fdata-sections -ffunction-sections -Wl,--enable-stdcall-fixup -static-libgcc -Wl,--whole-archive CMakeFiles/MQTTAsync_publish.dir/objects.a -Wl,--no-whole-archive  -o MQTTAsync_publish.exe -Wl,--out-implib,libMQTTAsync_publish.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles/MQTTAsync_publish.dir/linklibs.rsp
`_Sleep' referenced in section `.text' of CMakeFiles/MQTTAsync_publish.dir/objects.a(MQTTAsync_publish.c.obj): defined in discarded section `.text' of /usr/lib/gcc/i686-w64-mingw32/4.9-win32/../../../../i686-w64-mingw32/lib/../lib/libkernel32.a(libkernel32s01140.o)

These are the contents of the linker response file:

 libpaho-mqtt3a.dll.a -lpthread -lws2_32 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32

Minimal stripped down working sample:

main.c:

#include <windows.h>

int main(void)
{
    Sleep(10);
    return 0;
}

Compiler/Linker call:

i686-w64-mingw32-gcc -static-libgcc -lpthread -lws2_32 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -o main.exe main.c

No problem here.


Source: gcc

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.