While trying to pip install mysqlclient, I had been coming across this issue for the past two days:
In file included from _mysql.c:29:
/usr/local/mysql/include/mysql.h:35:10: fatal error: 'sys/types.h' file not found
#include <sys/types.h>
^~~~~~~~~~~~~
1 error generated.
error: command 'clang' failed with exit status 1
I know how the -I flag works for gcc, but I think the -isysroot and -mmacosx-version-min maybe clang specific flags. Not sure, and not bothered at this point, since hey, pip install mysqlclient worked beautifully after this.
In file included from _mysql.c:29:
/usr/local/mysql/include/mysql.h:35:10: fatal error: 'sys/types.h' file not found
#include <sys/types.h>
^~~~~~~~~~~~~
1 error generated.
error: command 'clang' failed with exit status 1
If I were a more meticulous developer, I would have focused on the exact issue being barfed by the terminal, instead of being easily confused and distracted by the many Stack Overflow and Github suggestions.
Some of the suggestions I tried, and shot myself in the foot:
- Some SO issues had suggested to brew install mysql, which, of course, began to install the latest version of mysql (8.0), when I already had a previous version installed.
- While installing 8.0 version, I didn't know how to do an "in place" upgradation from 5.7 to 8.0, or a "logical upgradation" from 5.7 to 8.0. Either of which would have worked, but since 8.0 was installed assuming there were no previous versions of mysql installed, I ended up in a state where neither the 5.7 server nor the 8.0 server would start up.
- And since I had not taken a mysqldump backup of all my tables before starting this exercise, I had no other go than to remove both mysql versions, along with all the data directories (and thus losing my current tables on localhost), and start from scratch again.
- But hey! installing from scratch doesn't fix the above issue either!
- Installing XCode command line tools via xcode-select --install doesn't seem to fix this either!
So what's the issue here? Going through more articles and suggestions, came across this little gem by GitHub user giblfiz, which seems to suggest that the latest versions of XCode doesn't install the system headers into /usr/local/include, where every other build system worth it's salt in portability would look for by default, but instead installs it into some weird macOS specific directory.
Aha. So add this weird directory as well to look for, while searching for system headers:
export set CFLAGS="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -mmacosx-version-min=10.14"
Just throwing it out there into the Ether, so that other confused souls may find it helpful, and since I do not yet have sufficient rep to comment on SO, and neither do I want to sidetrack other bug discussions on GH.