Create your first Conan package with Autotools in Windows (msys2)

Warning

This example is intended for the Windows OS, using the msys2 subsystem to run the autotools build system. The support is limited, the AutotoolsDeps generator still doesn’t work for Windows, so the test_package in the default template will fail.

Note this example is building with the MSVC compiler, not with MinGW/gcc. Even if the build system is autotools, the example is targeting the MSVC compiler, and the resulting package will be binary compatible and can be used from other packages using MSVC with other build systems. It is not necessary to force MinGW/gcc to use some open source dependencies that use autotools, and ConanCenter builds all of them with MSVC.

In the Create your first Conan package with Autotools tutorial, the autotools integrations are presented. Please read first that section, to understand them, as this section will only introduce the Windows/msys2 specific issues.

We will use the same the conan new command to create a “Hello World” C++ library example project:

  1. $ conan new autotools_lib -d name=mypkg -d version=0.1

Check the above tutorial to understand the created files.

Besides these files, we will create a profile file:

msys2_profile

  1. include(default)
  2. [conf]
  3. tools.microsoft.bash:subsystem=msys2
  4. tools.microsoft.bash:path=C:\ws\msys64\usr\bin\bash
  5. tools.build:compiler_executables={"c": "cl", "cpp": "cl"}

Note that you might need to adapt the path to the bash system of msys2.

In the package recipe conanfile.py we will have:

  1. win_bash = True

This is very important, it tells Conan that when this package is to be built, it has to launch a bash shell to execute the build in it.

Note

It is not necessary, and in fact it is not recommended for most cases to be already running inside an msys2 terminal. Conan will automatically run the build subprocess for autotools in the defined bash shell.

If already running in a bash shell, it is necessary to activate the tools.microsoft.bash:activate=True conf.

Let’s build the package from sources with the current default configuration, making sure to deactivate the test_package, because otherwise it will fail.

  1. # Deactivating the test_package, as AutotoolsDeps doesn't work yet.
  2. $ conan create . -pr=msys2_profile -tf=""
  3. ...
  4. mypkg/0.1: package(): Packaged 1 '.h' file: mypkg.h
  5. mypkg/0.1: package(): Packaged 1 '.la' file: libmypkg.la
  6. mypkg/0.1: package(): Packaged 1 '.lib' file: mypkg.lib
  7. mypkg/0.1: Created package revision fa661758835cf6f7f311c857447393cc
  8. mypkg/0.1: Package '9bdee485ef71c14ac5f8a657202632bdb8b4482b' created

We can now validate that the recipe and the package binary are in the cache:

  1. $ conan list "mypkg:*"
  2. Found 1 pkg/version recipes matching mypkg in local cache
  3. Local Cache
  4. mypkg
  5. mypkg/0.1
  6. revisions
  7. 6e85b0c27c7fbc8eddc1994dbb543b52 (2024-04-30 18:29:44 UTC)
  8. packages
  9. 9bdee485ef71c14ac5f8a657202632bdb8b4482b
  10. info
  11. settings
  12. arch: x86_64
  13. build_type: Release
  14. compiler: msvc
  15. compiler.cppstd: 14
  16. compiler.runtime: dynamic
  17. compiler.runtime_type: Release
  18. compiler.version: 193
  19. os: Windows
  20. options
  21. shared: False

Note how the binary is a compiler=msvc one.

See also