我正在尝试使用RtAudio生成流音频。但是,当我尝试包含“ RtAudio.h”文件时,该程序总是会抱怨一些奇怪的东西。我的项目结构如下:
基本上,文件夹rtaudio是我从here安装的存储库,而CMakeList1也从那里安装。
CMakeList主文件夹下:
cmake_minimum_required(VERSION 2.8)
# Add -Wall and -Wextra. Also,
# treat C/C++ warnings as errors if -DADM_FATAL_WARNINGS=ON.
include (cmake/FatalWarnings.cmake)
ADM_EXTRA_WARNINGS()
add_subdirectory(demos)
CMakeList2:
project(malos_service C CXX)
cmake_minimum_required(VERSION 2.8)
add_definitions(-std=c++11)
FIND_LIBRARY(WIRINGPI_LIB NAMES wiringPi)
....
set(AUDIO_LIBRARY_FOUND OFF)
find_path(RTAUDIO_HEADER_PATH "RtAudio.h" HINTS ../rtaudio)
if(RTAUDIO_HEADER_PATH)
message(STATUS "Compiling provided rtaudio-library!")
add_subdirectory(../rtaudio rtaudio)
add_definitions(-DRTAUDIO_HEADER="../rtaudio/RtAudio.h")
set(AUDIO_LIBRARY_FOUND ON)
endif()
if (NOT AUDIO_LIBRARY_FOUND)
message(SEND_ERROR "no supported library")
endif()
# Check if any audio-library was added
if(NOT AUDIO_LIBRARY_FOUND)
message(SEND_ERROR "No supported audio-library found!")
endif()
....
add_executable(...)
要在Project文件夹下编译这些文件,
mkdir build
cd build
cmake ..
make
主要,我只添加:
#include "../rtaudio/RtAudio.h"
编译 make 后,我会得到很多错误:
In file included from ~/Project/demos/main.cpp:7:0:
/home/pi/Downloads/Project/demos/../rtaudio/RtAudio.h:729:5: error: expected identifier before numeric constant
OUTPUT,
^
/home/pi/Downloads/Project/demos/../rtaudio/RtAudio.h:729:5: error: expected ‘}’ before numeric constant
/home/pi/Downloads/Project/demos/../rtaudio/RtAudio.h:729:5: error: expected unqualified-id before numeric constant
In file included from /home/pi/Downloads/Project/demos/main.cpp:25:0:
/home/pi/Downloads/Project/demos/../rtaudio/RtAudio.h: In member function ‘bool RtApi::isStreamOpen() const’:
/home/pi/Downloads/Project/demos/../rtaudio/RtAudio.h:709:44: error: ‘stream_’ was not declared in this scope
bool isStreamOpen( void ) const { return stream_.state != STREAM_CLOSED; }
...
* PS:如果我直接执行rtaudio,则rtaudio下的程序可以正常工作,这意味着错误不应该来自rtaudio * (希望如此)
我做客的方式有问题吗?有人知道如何解决这个问题吗?
答案 0 :(得分:0)
得到所有这些错误的原因是因为您没有在项目中编译RtAudio
的源代码。您需要将RtAudio.cpp
文件复制到您的项目中。看来您使用的是树莓派,所以实际上编译您的项目所需要做的就是像这样设置文件:
- Project
- RtAudio.h
- RtAudio.cpp
- main.cpp
然后进行编译,您将要运行
g++ main.cpp RtAudio.cpp -o run
就是这样!假设您已经安装了RtAudio的依赖项,那么它应该编译没有问题。