Linux 部署C++音频读取方法代码遇到的问题:

参考链接:No such file or directory #include <io.h>
firstError: io.h: No such file

用命令查找io.h所在位置:
find /usr/include -name “io.h”,
结果发现在/usr/include下没有,但在/usr/include/x86_64-linux-gnu/sys 或者 /usr/include/sys 下有
这个取决于你的服务器类型是ubuntu 还是 CentOS
第一种解决办法——copy该头文件到 /usr/include 目录下:
这个方法可能需要 root 权限 才能执行如下命令

用命令把io.h复制到/usr/include下:

sudo  cp /usr/include/x86_64-linux-gnu/sys/io.h  /usr/include
或者
sudo  cp /usr/include/sys/io.h  /usr/include

第二种解决办法——修改头文件的引入路径(推荐):
本来我们引入为:

 #include <io.h>

修改为

 #include <sys/io.h>

对,讲道理这种方法应该在生产环境下更合适些的吧!!!

second: fatal error: windows.h: No such file or directory
我这里Windows 里面引用了 #include <windows.h> ,使用下面的方法测量函数运行时间

#include <iostream>
#include <windows.h>
using namespace std;
void timeTest()
{
	for(int i =0;i<1000;i++)
		cout<<i<<endl; 
}

int main()
{
	long start_time = GetTickCount();
  	timeTest();
	long end_time = GetTickCount();
    cout << "Running Time:" << end_time - start_time << "ms" << endl;
}

代码迁移到Linux下报错,找不到 windows.h。
于是选择使用Linux下的另外一种测量函数运行时间的方法,使用 #include <time.h>头文件,代码如下:

#include <iostream>
#include <time.h>
using namespace std;

void timeTest()
{
	for(int i =0;i<1000;i++)
		cout<<i<<endl; 
}

int main()
{
	clock_t start, ends;
	start = clock();
 	timeTest();
	ends = clock();
	cout << "Running Time: " << ends - start<<" ms" << endl;
}

最终准确的函数运行时间度量方法——推荐使用:
C++的<time.h>头文件中有time和clock可以用来计算时间,但是“#include ”中提供了更加精确的统计时间的方法。
下面的代码支持Windows 和 Linux,但是要求编译器必须支持C++11

#include <iostream>
#include <chrono>
using namespace std;
using std::chrono::high_resolution_clock;
using std::chrono::milliseconds;

void timeTest()
{
	for(int i =0;i<1000;i++)
		cout<<i<<endl; 
}

int main()
{
    high_resolution_clock::time_point beginTime = high_resolution_clock::now();
    
  	timeTest();
  
    high_resolution_clock::time_point endTime = high_resolution_clock::now();
    milliseconds timeInterval = std::chrono::duration_cast<milliseconds>(endTime - beginTime);
    cout << "Running Time:" << timeInterval.count()  << "ms" << endl;
}

third: error: ‘DIR’ was not declared in this scope
error: ‘opendir’ was not declared in this scope

引入头文件 #include <dirent.h>
Linux下c++遍历文件夹中文件及读取绝对路径会用到这个头文件
我的链接

fourth: error: scoped enums only available with -std=c++11 or -std=gnu++11
参考链接
需要 使用 在Linux 下 使用 C++ 11来编译文件,在 本身的 命令后面 添加 -std=c++11 即可

g++  test.cpp  main.cpp  -std=c++11

fifth: 我的cpp文件上传到Linux服务器中文出现乱码
中文注释乱码原因:windows系统的VS2017 cpp 文件的编码可能不是utf-8,需要设置一下文件的编码为utf-8
解决办法:Vs2017设置文件编码为utf-8
参考链接

猜你喜欢

转载自blog.csdn.net/sinat_28442665/article/details/84027913
今日推荐