title: undefined reference to 'mpg123_open'
body: <p>I am just testing the functionality of the mpg123 library and I am using the code shown below.</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;cstring&gt;
  #include &lt;mpg123.h&gt;
  
  #define INBUFF  16384
  #define OUTBUFF 32768
  
  void openfile(mpg123_handle* mh , char* filename){
      int             fnum;
      int             rbytes;
      int             mpg123Status = 0;
      int             channels = 0, encoding = 0;
      long            rate = 0;
      size_t          size;
      int             decodedbytes, decodestatus;
      int             fileSizeSamples;
      unsigned int    framesConsumed;
      unsigned char   *mp3InBuf, *mp3OutBuf;
      unsigned int    mp3InBufSize, mp3OutBufSize;
      size_t          decodedNow;
  
      mp3InBufSize    = 2048;
      mp3OutBufSize   = 32768;
  
      mp3InBuf        = new unsigned char[mp3InBufSize];
      mp3OutBuf       = new unsigned char[mp3InBufSize];
  
      //Open mp3 file for reading
      fnum = open(filename, O_RDONLY);
      if(fnum &lt; 0){
          printf("ERROR opening file: %s\n", strerror(fnum));
          exit(0);
      }
  
      decodedbytes = 0;
      decodestatus = MPG123_NEED_MORE;
  
      mpg123Status = mpg123_init();
      if(mpg123Status){
          printf("Could not init MPG123: %d - %s\n", mpg123Status, mpg123_plain_strerror(mpg123Status));
          close(fnum);
          exit(0);
      }
  
      mh = mpg123_new(NULL, &amp;mpg123Status);
      if(mh == NULL){
          printf("Could not open mpg123_handle: %d - %s\n", mpg123Status, mpg123_plain_strerror(mpg123Status));
          close(fnum);
          exit(0);
      }
  
      mpg123Status = mpg123_open_feed(mh);
      if (mpg123Status) {
          printf( "Could not open mpg123 feed: %d - %s\n",  mpg123Status, mpg123_plain_strerror(mpg123Status));
          close(fnum);
          exit(0);
      }
  
      mpg123_open(mh, filename);
      fileSizeSamples = MPG123_ERR;
      framesConsumed = 0;
  
      /* determine file parameters */
      mpg123Status = -1;
      printf("Start initial decode for file params.\n");
      while (MPG123_NEW_FORMAT!=mpg123Status) {
          /* file -&gt; decoder */
          rbytes = read(fnum, mp3InBuf, mp3InBufSize);
          if (rbytes&gt;0) {
              mpg123Status = mpg123_decode(mh, mp3InBuf, rbytes, mp3OutBuf, mp3OutBufSize, &amp;size);
              if ((mpg123Status) &amp;&amp; (MPG123_NEW_FORMAT!=mpg123Status)) {
                  printf("Could not feed mpg123: read %d Bytes %d from file %d - %s\n",size, rbytes, mpg123Status, mpg123_plain_strerror(mpg123Status));
                  close(fnum);
                  exit(0);
              }
                  mpg123_getformat(mh, &amp;rate, &amp;channels, &amp;encoding);
          }
      }
  
      printf("MP3 at %d Hz %d channels %x encoding\n", rate, channels, encoding);
  
      /*Read entire file*/
      while(!EOF){
          rbytes = read(fnum,mp3InBuf,mp3InBufSize);
          decodestatus = mpg123_decode(   mh, mp3InBuf, mp3InBufSize,
                                          mp3OutBuf,mp3OutBufSize, &amp;decodedNow);
          printf("%s",mp3OutBuf);
      }
  
      //Clean up
      close(fnum);
      mpg123_close(mh);
      mpg123_delete(mh);
      mpg123_exit();
      delete [] mp3InBuf;
      delete [] mp3OutBuf;
  }
  
  int main(int argc, char **argv) {
      mpg123_handle*  mh;
  
      //for(;;){
          for(int i=1; i&lt;argc; i++){
              printf("Opening File: %s\n", argv[i]);
              openfile(mh, argv[i]);
              sleep(5);
          }
      //}
  }
  </code></pre>
  
  <p>To compile the above code I am using the following in command in linux:</p>
  
  <pre><code>g++ -o mpg123example mpg123example.cpp -lmpg123 
  </code></pre>
  
  <p>And I am getting the following error:</p>
  
  <pre><code> In function `openfile(mpg123_handle_struct*, char*)':
  mpg123example.cpp:(.text+0x196): undefined reference to `mpg123_open'
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>My confusion is if the library wan't linked properly why would it not complain about the other function calls? Any suggestions would be appreciated.</p>