GNU - 对“setmode”的未定义引用

Par*_*ani 3 c linux porting gnu

我正在 Linux 上移植一个 WIN32 库。我能够毫无错误地编译我的库。但是当我尝试链接时,它给出了以下链接错误

对“setmode”的未定义引用

我知道setmode函数是标准库函数,它驻留在unistd.h 中,我在通过终端链接时提供了参数-lc

这是使更多关于setmode链接

有同样的帮助吗?

Kaz*_*Kaz 5

I'm afraid these answers are nonsense. A program coming from the Win32 environment is using one of two possible setmode functions: either the Microsoft _setmode function documented in MSDN, or the Cygwin imitation of it called setmode.

This has nothing to do with the BSD setmode. It's a two-argument function which sets a file descriptor to either binary or text translation mode.

If your program expects this function, but you link to LibBSD, the program might link, but it is not correct.

GNU C 库不提供用于操作FILE *流或描述符的文本或二进制模式的接口,如果提供了,它也不会做任何事情,因为这两种模式是相同的。

在 Cygwinsetmode上需要 Cygwin函数的代码可能可以在 Unix 上不做任何事情而逃脱:也就是说:

#ifdef __CYGWIN__
setmode(fileno(my_stdio_stream), O_BINARY);
#elif _WIN32
_setmode(_fileno(my_stdio_stream), _O_BINARY);
#else
/* nothing on systems with no text-vs-binary mode */
#endif
Run Code Online (Sandbox Code Playgroud)