Skip to content

Building libraries on Windows generates DLLs, but not the corresponding import libraries #687

@acarta

Description

@acarta

On Windows, building a shared library from a Julia package using PackageCompiler produces a shared library, but not an associated import library.
As such, shared libraries generated by PackageCompiler cannot be linked to other C/C++ code in a straightforward manner.

When using PackageCompiler to compile a package to a shared library on Windows, the output consists of DLLs corresponding to the package itself as well as the Julia-related dependencies (libjulia.dll, libamd.dll, etc.).

As a MWE, I tried compiling the Julia portion of the libcg proof-of-concept (https://github.com/simonbyrne/libcg) using the following code (run from within libcg/CG):

build_dir = "build"
target_dir = joinpath("..", "..", "target")
project_toml = realpath("Project.toml")

PackageCompiler.create_library(".", target_dir;
                            lib_name="cg",
                            precompile_execution_file=[joinpath(build_dir, "generate_precompile.jl")],
                            precompile_statements_file=[joinpath(build_dir, "additional_precompile.jl")],
                            incremental=false,
                            filter_stdlibs=true,
                            header_files = [joinpath(build_dir, "cg.h")],
                            force=true,
)

The output directory looks like this:

───bin
│       julia.exe
│       libamd.dll
│       libatomic-1.dll
│       libblastrampoline.dll
│       libbtf.dll
│       libcamd.dll
│       libccalltest.dll
│       libccolamd.dll
│       libcholmod.dll
│       libcolamd.dll
│       libcurl-4.dll
│       libdSFMT.dll
│       libgcc_s_seh-1.dll
│       libgfortran-5.dll
│       libgit2.dll
│       libgmp-10.dll
│       libgmp.dll
│       libgmpxx-4.dll
│       libgmpxx.dll
│       libgomp-1.dll
│       libjulia-internal.dll
│       libjulia.dll
│       libklu.dll
│       libldl.dll
│       libLLVM.dll
│       libllvmcalltest.dll
│       libLTO.dll
│       libmbedcrypto.dll
│       libmbedtls.dll
│       libmbedx509.dll
│       libmlir_async_runtime.dll
│       libmlir_c_runner_utils.dll
│       libmlir_runner_utils.dll
│       libmlir_test_cblas.dll
│       libmlir_test_cblas_interface.dll
│       libmpfr-6.dll
│       libmpfr.dll
│       libnghttp2-14.dll
│       libopenblas64_.dll
│       libopenlibm.dll
│       libpcre2-16-0.dll
│       libpcre2-16.dll
│       libpcre2-32-0.dll
│       libpcre2-32.dll
│       libpcre2-8-0.dll
│       libpcre2-8.dll
│       libpcre2-posix-2.dll
│       libquadmath-0.dll
│       librbio.dll
│       libRemarks.dll
│       libspqr.dll
│       libssh2.dll
│       libssp-0.dll
│       libstdc++-6.dll
│       libsuitesparseconfig.dll
│       libumfpack.dll
│       libuv-2.dll
│       libwinpthread-1.dll
│       libz.dll
│
└───include
        cg.h
        julia_init.h

However, in order for these DLLs to be implicitly linked to another library/executable (i.e. not using LoadLibrary), there should be corresponding import libraries (.lib or .dll.a); these are not generated by the compilation process initiated by PackageCompiler.

I noticed that PR #614 added tests for create_library, but examining the current state of those tests here, it looks like the test consists mainly of running create_library without checking the output.

Not sure if this is related, but I opened an issue on libcg itself related to the failing build of the C library/executable.

Version Info

julia> versioninfo()
Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake-avx512)
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS =

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions