You are not logged in.

#1 2018-01-01 16:41:21

joaocandre
Member
Registered: 2013-02-23
Posts: 166

GCC can't find Python.h

I've been trying to compile some C++ code that requires Python headers (through matplotlib-cpp) and can't seem to be able to point the compiler to the header file:

/usr/include/matplotlib-cpp/matplotlibcpp.h:15:10: fatal error: Python.h: No such file or directory
 #include <Python.h>

I have python installed, but the headers are inside "python2.7" and "python3.6m" under "/usr/include".  As I want the code to be compilable in other distros, how do I tell gcc to look inside those folders? I understand this maybe a basic newbie question, but what exactly am I missing here?


Thanks in advance.

Offline

#2 2018-01-01 16:50:23

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: GCC can't find Python.h

https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html and various other online references to "compiler include path"s.

Specifically, you'd want to use the pkg-config(1) utility to determine what the software advertises as its include path and other useful metadata, e.g. `pkg-config --cflags python3` and `pkg-config --libs python3` respectively for adding to your CFLAGS and LDLIBS


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#3 2018-01-01 18:07:30

joaocandre
Member
Registered: 2013-02-23
Posts: 166

Re: GCC can't find Python.h

Thanks, I've edited my makefile and now it works. Still, is there a way to make it system-wide for GCC? In my laptop I don't need to directly tell GCC where to search for headers  at each call (though I'm not sure if I have changed its settings at some point).

Offline

#4 2018-01-01 18:28:01

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: GCC can't find Python.h

Then your laptop is either using a Makefile or IDE which automatically added the header directories for you, or your laptop is compiling a different project that only uses headers in the standard system directories described in my previous link.

Because if it made sense to include every possible directory, "system-wide", then that would have already been done. But different projects need different headers, many of which redefine the same private functions that therefore clash with each other. Also it would be silly to include Python 2 in a Python 3 project, or vice  versa.

What is your actual problem?


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

Board footer

Powered by FluxBB