[gdal-dev] building on macOS - fatal error: 'direct.h' file not found
Greg Troxel
gdt at lexort.com
Tue Jun 28 02:53:41 PDT 2022
Nik Sands <nik at nixanz.com> writes:
> Since I last built GDAL (2.2.2), cmake has been introduced and it
> appears as though it is going to be the only option going forward. So
> I’m attempting to use cmake to build GDAL 3.5.0 on macOS 12.4
> ('Monterey’). I’ve installed cmake using the ‘homebrew’ macOS package
> manager.
>
> However, I’m getting numerous build errors, starting with the
> following error when running cmake to build GDAL 3.5.0:
>
> fatal error: 'direct.h' file not found
For what it's worth I have been building gdal with cmake on NetBSD,
directly from git sources. I have not yet converted the pkgsc package.
> I’m attempting to build GDAL as follows:
>
> export LDFLAGS=-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib
> export CFLAGS="-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
> export CCFLAGS="-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
> export CXXFLAGS="-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
> export CPPFLAGS="-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
First, I suggest reading the build instructions carefully and following
them. Maybe you did, but the above flags are very surprising to me. I
understand how macOS has an sdk-only approach, but cmake ought to
support that out of the box (or else take the position that macOS is
broken in which case pretty much every cmake-using program would need
such an accomodation).
See BUILDING.md on master. Since you are using 3.5.0 and that file is
not present, the relevant bits are:
# Building with cmake
There is a [build hints](https://gdal.org/build_hints.html) page on the
website.
Beyond that page, note:
- cmake builds in the source directory are not supported (expected to
fail)
> cd gdal-3.5.0
> mkdir build
> cd build
> cmake -DPROJ_ROOT=~/build -DSQLITE3_INCLUDE_DIR=~/build/include -DSQLITE3_LIBRARY=~/build/lib/libsqlite3.a .. -DCMAKE_INSTALL_PREFIX=~/build -DCMAKE_BUILD_TYPE=Release ..
You probably should be calling cmake with
-DCMAKE_PREFIX_PATH=$HOME/build -DCMAKE_INSTALL_PREFIX=$HOME/build
according to the hints page. It is likely a bug if you need to
separately specify PROJ_ROOT. Perhaps in the cmakefiles, perhaps in
build_hints.html :-)
> I’m a hobbyist and not a professional developer, so my understanding
> of these things is quite limited. However, my research so far
> indicates that ‘direct.h’ is a Windows-specific header file and
> therefore perhaps cmake has not been configured correctly for macOS in
> this GDAL distribution?
Don't worry; almost nobody really understands cmake.
I suggest starting over following the instructions. Make really sure
there is nothing left from before -- cmake tends to create caches that
it doesn't remove.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 194 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20220628/4aa08ba8/attachment.sig>
More information about the gdal-dev
mailing list