title: mpg123 decode mp3 to pcm in C++
body: <p>I want to decode a <code>mp3</code> file to <code>pcm</code>:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;mpg123.h&gt;
  #include &lt;out123.h&gt;
  using namespace std;
  int main()
  {
  mpg123_handle *mh;
  unsigned char *buffer;
  size_t buffer_size;
  size_t done;
  int err;
  int channels, encoding;
  long rate;
  buffer_size = mpg123_outblock(mh);
  buffer = (unsigned char*) malloc(buffer_size * sizeof(unsigned char));
  
  mpg123_init();
  mh = mpg123_new(NULL, &amp;err);
  
  mpg123_open(mh, "/home/abbas/Desktop/nastaran.mp3");
  // mpg123_getformat(mh, &amp;rate, &amp;channels, &amp;encoding);
  
  
  
  while (mpg123_read(mh, buffer, buffer_size, &amp;done) == MPG123_OK)
      cout &lt;&lt; buffer ;
  
  free(buffer);
  mpg123_close(mh);
  mpg123_delete(mh);
  mpg123_exit();
  return 0;
  }
  </code></pre>
  
  <p>But it gives me this error:</p>
  
  <pre><code>The program has unexpectedly finished.
  </code></pre>
  
  <p>This error says nothing about the reason. Where is the problem?</p>
  
  <p>Is it something about the OS?</p>
  
  <p>cmake file: </p>
  
  <pre><code>project(echoprint2)
  cmake_minimum_required(VERSION 2.8)
  
  aux_source_directory(. SRC_LIST)
  add_executable(${PROJECT_NAME} ${SRC_LIST})
  
  add_library(mpg123 SHARED IMPORTED )
  set_target_properties(mpg123 PROPERTIES IMPORTED_LOCATION  /usr/local     /lib/libmpg123.so)
  TARGET_LINK_LIBRARIES(echoprint2 mpg123)
  </code></pre>