Cod*_*ggo 1 c winapi printf cygwin undefined-reference
我最近刚刚通过Cygwin64将GCC安装到Windows上。我正在尝试编译一个包含Windows _ftprintf函数的程序(如 MyHandleError函数中的此处所示,并在此处记录),但是,我得到的是未定义的引用。
例如:
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
void main(void){
_ftprintf(stderr, TEXT("Test Err. \n"));
}
Run Code Online (Sandbox Code Playgroud)
以下示例在编译为时产生以下错误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
Run Code Online (Sandbox Code Playgroud)
我想念国旗吗?
如果完全声明,它将在tchar.h中声明-打开该文件并检查。但是,由于链接器也无法解析它,因此似乎根本没有在库中对其进行定义。
我不希望这在旨在支持Windows上的Linux / GNU API的Cygwin中起作用-如果在任何情况下都以Windows / Microsoft API为目标,则不合适。此外,Cygwin使用UTF-8而不是Windows UTF-16编码,因此Windows的宽字符支持不可用也就不足为奇了。
如果您正在编写Windows特定的代码并希望使用GCC,则最好使用MinGW,它是带有Windows C运行时库的GCC编译器。如果您想要一个(真正的)Linux执行环境,那么一个更好的替代Cygwin的方法是使用Windows Subsystem for Linux-这使Cygwin在很大程度上过时了。
| 归档时间: |
|
| 查看次数: |
96 次 |
| 最近记录: |