gordonklaus / portaudio

Go bindings for the PortAudio audio I/O library
MIT License
704 stars 95 forks source link

Issues installing on Windows #47

Closed Aidan-OS closed 2 years ago

Aidan-OS commented 3 years ago

Hi,

I am trying to attach to audio streams on windows with go and have found many sources pointing to this package but I am having issues when running the go get command. Here are the steps I have taken so far:

  1. Downloaded the source for PortAudio
  2. Followed the instructions found here: https://github.com/PortAudio/portaudio/wiki/Notes_about_building_PortAudio_with_MinGW
  3. Added my PortAudio path to my PKG_CONFIG_PATH environment variable
  4. Run go get github.com/gordonklaus/portaudio

When I run the final command I get this error:

# github.com/gordonklaus/portaudio
C:\Users\user\go\pkg\mod\github.com\gordonklaus\portaudio@v0.0.0-20200911161147-bb74aa485641\portaudio.go:16:10: fatal error: portaudio.h: No such file or directory
   16 | #include <portaudio.h>
      |          ^~~~~~~~~~~~~
compilation terminated.

When looking at the file mentioned here I find that line 16 is contained in a multi line comment, so the fact that it is complaining makes no sense to me. Is there something that I have done wrong?

gordonklaus commented 3 years ago

Hi Aidan,

I'm not using Windows but maybe I can help.

Is there not a way to install a pre-compiled PortAudio on MinGW? I see there are some package managers, but I don't know if there is a package for PortAudio.

I suspect you're missing a portaudio-2.0.pc file for pkg-config. Mine (on macOS) exists at /usr/local/lib/pkgconfig/portaudio-2.0.pc. I suppose /usr/local/lib/pkgconfig/ is the default path and doesn't need to be added to PKG_CONFIG_PATH. It looks like this file is generated (from this) when you build PortAudio; otherwise you'll need to write it yourself.

You can run pkg-config portaudio-2.0 --libs --cflags to check whether the .pc file is found.

When looking at the file mentioned here I find that line 16 is contained in a multi line comment, so the fact that it is complaining makes no sense to me.

This is how cgo works: A magic comment preceding the import of pseudo-package C.

dh1tw commented 3 years ago

Hi Aidan,

Msys2 provides MinGW + Pacman, the Arch Package Manager. Through Pacman you can install most libraries, incl. portAudio.

Another option for running gcc on Windows is tdm-gcc. I also made good experience with tdm-gcc compiling cgo projects natively on Windows hosts.

For cross-compiling, feel free to fork and adjust remoteAudio-xcompile to your needs.

Raraku commented 2 years ago

I am having the exact same issue. I've added the location to the PKG_CONFIG_PATH but there's no difference

gordonklaus commented 2 years ago

I believe this issue was solved by @dh1tw's suggestion. If not, please re-open.

gordonklaus commented 1 year ago

I eventually tried to do this myself and ran into the same problem as @Raraku.

Getting this error:

$ go build .
# pkg-config --cflags  -- portaudio-2.0
Package portaudio-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `portaudio-2.0.pc'
to the PKG_CONFIG_PATH environment variable
Package 'portaudio-2.0', required by 'virtual:world', not found
pkg-config: exit status 1

in spite of this working as expected:

$ pkg-config --cflags  -- portaudio-2.0
-IC:/msys64/mingw64/include

I was able to solve the problem by installing mingw-w64-x86_64-pkg-config:

pacman -S mingw-w64-x86_64-pkg-config

I have no idea why the pre-installed pkg-config did not work as expected.