HerpDerpington
HerpDerpington

Reputation: 4463

How can I properly configure the g++ include path with mingw64?

I have installed msys2/mingw64 because I need the g++ compiler. Now, I want to compile some c++ oce which requires openblas. I have installed the package using pacman -S mingw-w64-x86_64-openblas. However, compiling the code fails with

fatal error: cblas.h: No such file or directory

Clearly, the include path does not contain the headers from openblas which are located at C:\msys64\mings64\include\openblas. This is easy to fix by passing -I<include path> as an additional argument to g++.

Now, I was wondering whether there is an automated way to include include files/headers of installed packages in the g++ include path. The same problem also holds for libraries.

For example, pacman might be able to atomatically append these paths onto some environment variable which g++ checks.

Upvotes: 1

Views: 1390

Answers (1)

David Grayson
David Grayson

Reputation: 87436

The standard way to get compilation and linking options for a library on MSYS2 and other Unix-like systems is to run this command:

pkg-config --cflags --libs openblas

If you're just compiling, use --cflags by itself.

If you're just linking, use --libs by itself.

Here's an example Bash command you could use to compile a single-file program:

g++ foo.cpp $(pkg-config --cflags --libs openblas) -o foo

Upvotes: 1

Related Questions