c++ - Xcode 找不到 PortAudio 的标签“错误”
问题描述
我正在尝试按照Initialising PortAudio 教程中的描述初始化 portaudio 。
它说要检查初始化过程中是否有错误,如下所示:
PaError err = Pa_Initialize();
if (err != paNoError) goto error;
这是我正在使用的确切代码。
我在 OS X Mojave 10.14.4 上运行它,使用 Xcode 10.1 和 10.12 OS X SDK。
我试图找到 PortAudio 文档中的错误标签无济于事,并且名为error
.
到目前为止的完整程序是:
# include <iostream>
# include "portaudio.h"
using namespace std;
// Typedef and demo callbacks here.
int main(int argc, const char * argv[])
{
PaError err = Pa_Initialize();
if (err != paNoError) goto error;
// Nothing here yet.
err = Pa_Terminate();
if (err != paNoError)
{
printf("Port audio error terminating: %s", Pa_GetErrorText(err));
}
return 0;
}
据我在教程中可以看出,这应该是一个有效的语句,但 Xcode 显示语法错误:
Use of undeclared label 'error'
解决方案
检查goto 语句的 c++ 参考 PortAudio 的示例程序,问题来自假设goto
可以访问 portaudio.h 文件中定义的内容,但事实并非如此。
如果您遇到此问题,我假设您也不熟悉goto
语句。
本教程假设主要功能中有一部分专门用于解决错误。为了解决这个问题,我们需要在我们的main
函数中定义一个错误标签来负责响应错误。
例如:
int main(void) {
PaError err;
// Checking for errors like in the question code, including goto statement.
return 1; // If everything above this goes well, we return success.
error: // Tells the program where to go in the goto statement.
Pa_Terminate(); // Stop port audio. Important!
fprintf( stderr, "We got an error: %s/n", Pa_GetErrorMessage(err));
return err;
}
推荐阅读
- optimization - TypeError: new(): data must be a sequence (got function)
- ios - 如何在使用条带时在 Firebase 中创建支付意图端点
- redis - 如何在 Azure Redis 缓存中高效缓存大型复杂对象
- uwp - 如何修复 CUIElement::IsRightToLeft 上的 UWP 应用程序崩溃
- android - Android - 无法解析符号“devbrackets”
- sql-server - SQL SERVER 的“SET ROWCOUNT”何时会停止影响 INSERT、DELETE 和 UPDATE 操作?
- kubernetes - 在部署新环境之前停止 gitlab CI 中先前部署的环境
- javascript - wdio/selenium-standalone-service 返回 getMacChromiumEdgeDriverArchitecture 错误
- java - Spring Security @RolesAllowed/@Secured 和 ROLE_ADMIN
- python - 如何在 PyQt5 中使用 QCamera 点击照片?