我最近刚刚通过Cygwin64将GCC安装到Windows上。我正在尝试编译一个程序,该程序在MyHandleError函数和(as shown here中包含Windows _ftprintf
函数documented here,但是,我得到的是未定义的引用。
例如:
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
void main(void){
_ftprintf(stderr, TEXT("Test Err. \n"));
}
以下示例在编译为gcc test.c
时产生以下错误:
test.c: In function 'main':
test.c:6:5: warning: implicit declaration of function '_ftprintf'; did you mean '__eprintf'? [-Wimplicit-function-declaration]
_ftprintf(stderr, TEXT("Test Err. \n"));
^~~~~~~~~
__eprintf
/cygdrive/c/Users/Dan/AppData/Local/Temp/ccEa2phm.o:test.c:(.text+0x21): undefined reference to `_ftprintf'
/cygdrive/c/Users/Dan/AppData/Local/Temp/ccEa2phm.o:test.c:(.text+0x21): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `_ftprintf'
collect2: error: ld returned 1 exit status
我是否缺少旗帜?
答案 0 :(得分:5)
If it is declared at all, it will be declared in tchar.h - open that file and check. However, since the linker also cannot resolve it it would appear that it does not it is not defined in the library at all.
I would not expect this to work in Cygwin which is intended to support the Linux/GNU API on Windows - it is not appropriate if you are targeting the Windows/Microsoft API in any case. Moreover Cygwin uses UTF-8 rather then Windows UTF-16 encoding so it is not really surprising that Windows' wide-character support is not available.
If you are writing Windows specific code and want to use GCC, then you will be better off using MinGW - it is the GCC compiler with the Windows C run-time library. A better alternative to Cygwin if you want a (true) Linux execution environment is to use Windows Subsystem for Linux - a thing that renders Cygwin largely obsolete.