matrix-io / matrix-creator-hal

Hardware Abstraction Layer for MATRIX Creator & MATRIX Voice
https://matrix-io.github.io/matrix-documentation/matrix-hal/overview/
GNU General Public License v3.0
70 stars 50 forks source link

Cannot get customized matrix-creator-hal to compile/link #91

Closed tgill880 closed 5 years ago

tgill880 commented 5 years ago

I am trying to customize my own version of MicrophoneArray::Read(), but cannot get the linker to recognize the new method.

Steps:

  1. Forked matrix-creator-hal to my own repository.
  2. Created a new method: MicrophoneArray::Read2(). The code in the method is not relevant at this point. microphone_array.h and .cpp files changed correctly.
  3. Pushed changes to my forked copy of the repository.
  4. Pulled changes down to RasPi.
  5. (Re)installed Matrix HAL from sources, as noted at this link: https://matrix-io.github.io/matrix-documentation/matrix-hal/getting-started/installation-source/. Except, of course, I am using my altered forked copy of the repository.
  6. When my own code calls Read2(), I get the following error.

/tmp/ccWgMLxt.o: In function `SLS_record<short, (unsigned short)8, (unsigned short)512, (unsigned short)2000>::start()': /home/pi/Projects/Matrix-HAL-demos/SLS_record.hpp:129: undefined reference to `matrix_hal::MicrophoneArray::Read2()' collect2: error: ld returned 1 exit status

undefined reference looks like a linker error to me. If I substitute the standard Read() call, everything builds correctly (but I don't have the new functionality I need).

  1. I confirmed the altered version of microphone_array.h is installed in /usr/local/include/matrix_hal.
  2. I have tried manually removing the headers and the lib matrix_creator_hal.so files to be sure old version were not updated.
  3. My compiler command is very simple: g++ -std=c++11 -g test_api.cpp -o test_api -lmatrix_creator_hal
  4. I can correctly build the Matrix Voice sample programs with the altered library with the above compiler command.

Any help appreciated.

samreenislam commented 5 years ago

Hello @tgill880,

Please share the fork so we can test. I recently did a similar thing where I implemented my own Read() function to get raw mic data and I didn't get the same issue so we'd need to check it out!

Best, Samreen

tgill880 commented 5 years ago

Hi, Samreen,

I solved my problem by compiling just the microphone_array.cpp with my code, which contains the overloaded ::Read(). Then I can link with the standard matrix-creator-hal.so library. Something like this: g++ -std=c++11 my_app.cpp microphone_array.cpp -o my_app -lmatrix-creator-hal -lwiringPi

I have no idea why I needed to link with wiringPi.

Declaration for new ::Read():

bool Read(std::array<int16_t, kMicarrayBufferSize>& mic_data);

Code:

bool MicrophoneArray::Read(std::array<int16_t, kMicarrayBufferSize>& mic_data) {
  if (!bus_) return false;

  irq_cv.wait(lock_);

  if (!bus_->Read(kMicrophoneArrayBaseAddress,
                  reinterpret_cast<unsigned char *>(&mic_data[0]),
                  sizeof(int16_t) * kMicarrayBufferSize)) {
    return false;
  }
  return true;
}

Let me know if you need more info.

HOWEVER, the microphone data I get is somehow corrupted or malformed, and I only get an odd 'machine like' sound out of my files. Off topic, so I will open another ticket.

I will close this issue within several days.