我正在尝试运行 C++ 代码,但是找不到 io.h。
'io.h' file not found
显示为
#include <io.h>
此外,我遇到了一堆奇怪的问题(对于超过 16 岁的代码):
Use of undeclared identifier '_read'
或
Unknown type name '__int64'; did you mean '__int64_t'?
或
Use of undeclared identifier '_O_RDONLY'
或
Use of undeclared identifier '_lseeki64'; did you mean 'fseeko64'?
或
Cannot initialize a parameter of type 'FILE *' (aka '_IO_FILE *') with an lvalue of type 'int'
或
Use of undeclared identifier '_lseek'; did you mean 'fseek'?
或
Use of undeclared identifier '_close'
我想知道这些是否与找不到 io.h 有关。
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.1 LTS
Release: 20.04
Codename: focal
我有CLion 2020.2.3 和
$ gcc --version
gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
添加编译器指令来管理多操作系统编译。
//old line: #include<io.h>
#ifdef _WIN32
#include <io.h>
#elif __linux__
#include <inttypes.h>
#include <unistd.h>
#define __int64 int64_t
#define _close close
#define _read read
#define _lseek64 lseek64
#define _O_RDONLY O_RDONLY
#define _open open
#define _lseeki64 lseek64
#define _lseek lseek
#define stricmp strcasecmp
#endif
//SAF_Handle.cpp line:458 old line:INFILE = _open(infilename, _O_RDONLY | _O_BINARY);
#ifdef __linux__
INFILE = _open(infilename, _O_RDONLY);
#elif
INFILE = _open(infilename, _O_RDONLY | _O_BINARY);
#endif
修复了一些未声明迭代器变量“i”的循环。
io.h 也由 winelib 提供。
使用 winelib 头文件为 Linux 编译 Windows C/C++ 包:
winemaker . && make
酿酒师有一些有用的选项,请参阅
winemaker --help
。winemaker --lower-all .
将所有包含路径转换为小写
在 debian 中,酿酒师 是 wine32-tools
和
wine64-tools
的一部分。
除了运行
make
,你还可以直接调用编译器:
wineg++ -o main main.cpp -I. -mno-cygwin