如何在MinGW gcc中链接到内联函数?

时间:2018-08-19 05:52:28

标签: gcc mingw

我需要使用MinGW 4.8.2编译一些库(kuba zip)。我出现链接错误。

[2/2 12.0/sec] Linking C executable test\test.exe.exe
FAILED: test/test.exe.exe 
cmd.exe /C "cd . && C:\mingw32\bin\gcc.exe  -std=c99 -Wall -Wextra -pedantic -g   test/CMakeFiles/test.exe.dir/test.c.obj test/CMakeFiles/test.exe.dir/__/src/zip.c.obj  -o test\test.exe.exe -Wl,--out-implib,test\libtest.exe.dll.a -Wl,--major-image-version,0,--minor-image-version,0  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
test/CMakeFiles/test.exe.dir/__/src/zip.c.obj: In function `zip_entry_close':
C:\msys64\home\ivan\dev\zip\debug-qt4/../src/zip.c:440: undefined reference to `localtime_s'

这是localtime_s函数中的问题。 localtime_s被声明为inline,并且必须内联。但事实上这是没有发生的。

localtime_s声明。

__CRT_INLINE errno_t __cdecl localtime_s(struct tm *_Tm,const time_t *_Time) { return _localtime32_s(_Tm,_Time); }

我为此写了一些测试用例。

#include <time.h>
int main()
{
    struct tm _Tm;
    time_t _Time;
    localtime_s(&_Tm, &_Time);
    return 0;
}

使用gcc会产生链接错误:

$ gcc localtime_test.c
C:\msys64\tmp\ccEMjUQ8.o:localtime_test.c:(.text+0x1e): undefined reference to `localtime_s'
collect2.exe: error: ld returned 1 exit status

但是g ++或MinGW 5.3.0(gcc和g ++)都没有错误。那么如何使我的测试用例与MinGW 4.8.2 gcc一起使用?

我知道我可以使用_localtime32_s,它可以工作。但这似乎是一个错误的决定。

0 个答案:

没有答案
相关问题