Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why does Windows build require additional libraries? #1010

Closed
mfansler opened this issue Feb 10, 2023 · 7 comments
Closed

Why does Windows build require additional libraries? #1010

mfansler opened this issue Feb 10, 2023 · 7 comments

Comments

@mfansler
Copy link

I am trying to understand why the Windows build links against so many additional libraries. That is, when looking at build logs on all other platforms, I only ever see -lgdal -lgeos -lgeos_c -lproj. In contrast, the Makevars.win includes more than a dozen extra libraries:

terra/src/Makevars.win

Lines 9 to 20 in 7cc6ed8

PKG_LIBS = \
-L$(RWINLIB)/$(TARGET) \
-L$(RWINLIB)/lib$(R_ARCH) \
-lgdal -lsqlite3 -lspatialite -lproj -lgeos_c -lgeos \
-ljson-c -lnetcdf -lmariadbclient -lpq -lpgport -lpgcommon \
-lwebp -lcurl -lssh2 -lssl \
-lhdf5_hl -lhdf5 -lexpat -lfreexl -lcfitsio \
-lmfhdf -lhdf -lxdr -lpcre \
-lopenjp2 -ljasper -lpng -ljpeg -ltiff -lgeotiff -lgif -lxml2 -llzma -lz -lzstd \
-lodbc32 -lodbccp32 -liconv -lpsapi -lwldap32 -lsecur32 -lgdi32 -lnormaliz \
-lcrypto -lcrypt32 -lws2_32 -lshlwapi -lbcrypt

Why is this? Is this really a necessary set, or is it just including everything provided by rwinlib/gdal3 simply because it is in there?

@rhijmans
Copy link
Member

rhijmans commented Feb 10, 2023

Most of these are there to support the use of GDAL plugins for reading and writing different file formats. Some seem obscure (mariadb, jasper), but others, such as geotiff netcdf sqlite3 and hdf5, are essential.

On most platforms an installation from source would include the same libraries but you may not realize it. For example on OSX you could use "brew" to install GDAL and these libraries would be included (perhaps not exactly the same but close enough). Likewise with the Ubuntu GDAL package. That is, you would be using a installation of GDAL that was build with these other packages such that you do not need to include them again.

@mfansler
Copy link
Author

Thanks for the reply. However, I'm still confused because the other platforms never explicitly link those other libraries during the package build. That is, GDAL, etc. libraries will already be linked against their dependent libraries. So, I still don't understand why this package needs to explicitly link against such dependencies of dependencies. Shouldn't the -lgdal etc. be sufficient? Is there something about these static libraries that requires the additional specifications?

@rhijmans
Copy link
Member

I do not know. I suppose it is related to how linking works on windows vs linux. A person to ask would be Tomas Kalibera, the maintainer of Rtools (Jeroen would also know as it worked the same with his GDAL install).

But it may be more similar on other platforms that it seems. The terra configure script uses gdal-config to set PKG_LIBS

On my Ubuntu that shows

$gdal-config --dep-libs
-lheif -lcrypto -larmadillo -lpoppler -ljson-c -L/usr/lib -lfreexl -lqhull -lqhull -lgeos_c -lwebp -lodbc -lodbcinst -lkmlbase -lkmldom -lkmlengine -lkmlxsd -lkmlregionator -lexpat -lxerces-c -lpthread -lopenjp2 -L/usr/lib/x86_64-linux-gnu/hdf5/serial -lnetcdf -L/usr/lib/x86_64-linux-gnu/hdf5/serial/lib -lhdf5 -lmfhdfalt -ldfalt -logdi -lgif -lCharLS -lgeotiff -lpng -lcfitsio -lpq -llz4 -lblosc -lzstd -llzma -lsqlite3 -lproj -lsqlite3 -ltiff -ljpeg -ldeflate -lz -lpthread -lm -lrt -ldl -L/usr/lib -lspatialite -lpcre -lcurl -lfyba -lfygm -lfyut -lxml2 -lmysqlclient -lpthread -ldl -lz -lssl -lcrypto -lresolv -lm -lrt

@rhijmans rhijmans reopened this Feb 10, 2023
@rhijmans
Copy link
Member

rhijmans commented Feb 10, 2023

Reopening since I now understand that you are asking this in the context of building the package for installation on Anaconda rwinlib/gdal3#3.

@edzer
Copy link
Contributor

edzer commented Feb 12, 2023

The makefile you're looking at is used by CRAN to build a binary package. R binary packages built by CRAN for Windows or MacOS use static linking, other platforms typically use dynamic linking. Static linking requires all libraries involved to be listed during the build step; they all end up in the resulting terra.dll which is huge, but doesn't need any of the other .dll's at runtime.

On my linux system, the terra.so links dynamically to another 122 libraries:

$ ldd /home/edzer/R/x86_64-pc-linux-gnu-library/4.0/terra/libs/terra.so | wc
    122     484    9227

If any of these are updated, I may have to reinstall terra to keep things working.

You can of course build binaries for any platform using dynamic linking, but you'd have to use your own makefile, and manage the dynamically linked libraries in addition to the terra R package. CRAN doesn't do that for binary packages.

@rhijmans
Copy link
Member

Thanks @edzer

@mfansler
Copy link
Author

@edzer thanks - that very much clarifies the distinction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants