Background
Whilst following Microsoft’s official instructions on how to install SQL Server for PHP, you might encounter the following problem:
/tmp/pear/temp/sqlsrv/shared/xplat.h:30:10: fatal error: sql.h: No such file or directory #include <sql.h> ^~~~~~~ compilation terminated. Makefile:194: recipe for target 'conn.lo' failed make: *** [conn.lo] Error 1 ERROR: `make' failed
Solutions for Mac M2
This solution might also work on other Macs.
sudo CXXFLAGS="-I/opt/homebrew/opt/unixodbc/include/" LDFLAGS="-L/opt/homebrew/lib/" pecl install sqlsrv sudo CXXFLAGS="-I/opt/homebrew/opt/unixodbc/include/" LDFLAGS="-L/opt/homebrew/lib/" pecl install pdo_sqlsrv
Solution for Debian/Ubuntu
The Microsoft ODBC driver’s installation page mentions that the development libraries are optional – they are not. So run the command below to get it working:
sudo apt-get install unixodbc-dev
1 thought on “How to deal with fatal error: sql.h: No such file or directory when installing pecl sqlsrv”
You are a star! I have spent all evening trying to figure this out.