0

I'm trying to use RtAudio to generate streaming audio. However, when I try to include "RtAudio.h" file, the program always complain something weird. My project structure looks like:

  • Project
    • rtaudio
      • CMakeList1
      • RtAudio.h
    • demos
      • main.cpp
      • CMakeList2
    • CMakeList

Basically, the folder rtaudio is the repository I installed from here and the CMakeList1 is also from there.

CMakeList under the main folder:

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(...)

To compile these, under Project folder,

mkdir build 
cd build
cmake ..
make

In main, I just add:

#include "../rtaudio/RtAudio.h"

After I compile make, I will get a lot of error:

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: if I directly cmake rtaudio, the program under rtaudio is all working, which means the error should not comes from rtaudio * (Hopefully)

Is the way I cmake has problem? Is anybody know how to fix this?

Pang
  • 9,564
  • 146
  • 81
  • 122
Arlene Fu
  • 11
  • 5
  • Smells like you have `OUTPUT` macro or enumeration constant **already defined**. It is difficult to say more without viewing **your code** (before including the `RtAudio.h`) too. You may also try to move `#include` directive to the top of your code. – Tsyvarev Jun 21 '18 at 08:04
  • @Tsyvarev My code is working without including the RtAudio.h. But I need to include that project to use their structure. And I double checked there is no overlapped definition for OUTPUT. – Arlene Fu Jun 21 '18 at 17:16

1 Answers1

0

The reason you are getting all of those errors is because you aren't compiling the source code from RtAudio with your project. you need to copy the RtAudio.cpp file into your project. It appears you are using a raspberry pi, so really all you need to do to compile your project is to set up your files like this:

- Project
  - RtAudio.h
  - RtAudio.cpp
  - main.cpp

then to compile, you will want to run

g++ main.cpp RtAudio.cpp -o run

that's it! assuming that you have the dependencies of RtAudio installed, it should compile without issue.

Derrick
  • 3,669
  • 5
  • 35
  • 50
Ethan Smith
  • 67
  • 1
  • 7
  • I tried similar stuff and the error message is still the same. And according to the hint provided by @Tsyvarev, I notice if I change the name "OUTPUT" into another name then the code compiles. However, I still cannot find the structure inside rtaudio. There must be something wrong to the way I link the library. – Arlene Fu Jun 22 '18 at 03:01