Repository: conan-io/conan-center-index

Issue:
Conan Error in build() method
Today I downloaded Conan, cmake, Visual studio code (including the C++, C++ makefile, Cmake, Cmake tools, and conan-tools extensions).

In order to get started, I began with the [following](https://docs.conan.io/en/latest/getting_started.html) tutorial. Everything went smoothly up until step 5, where I got the following error:

```C:\Users\rik\Documents\Coding\C++ Conan\build>conan install .. --build=missing
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=6.3
os=Windows
os_build=Windows
[options]
[build_requires]
[env]

WARN: apr-util/1.6.1: requirement expat/2.2.9 overridden by poco/1.10.0 to expat/2.2.10
WARN: libmysqlclient/8.0.17: requirement openssl/1.1.1i overridden by poco/1.10.0 to openssl/1.1.1h
apr/1.7.0: WARN: Package binary is corrupted, removing: 75bcd663b0f2f789317e8f347afd187fc180604d
conanfile.txt: Installing package
Requirements
    apr/1.7.0 from 'conan-center' - Cache
    apr-util/1.6.1 from 'conan-center' - Cache
    bzip2/1.0.8 from 'conan-center' - Cache
    expat/2.2.10 from 'conan-center' - Cache
    libmysqlclient/8.0.17 from 'conan-center' - Cache
    libpq/11.5 from 'conan-center' - Cache
    openssl/1.1.1h from 'conan-center' - Cache
    pcre/8.41 from 'conan-center' - Cache
    poco/1.10.0 from 'conan-center' - Cache
    sqlite3/3.33.0 from 'conan-center' - Cache
    zlib/1.2.11 from 'conan-center' - Cache
Packages
    apr/1.7.0:75bcd663b0f2f789317e8f347afd187fc180604d - Build
    apr-util/1.6.1:8b2f670f1c54911ff5c244c18d6d4a4abee1db7f - Build
    bzip2/1.0.8:3aee75d6bdc58b782dbb09a2263ed3abf7aa35f8 - Build
    expat/2.2.10:7bc8c2c85db7a618e5320dc997f27fc33e1df074 - Build
    libmysqlclient/8.0.17:3df753469e9528701aceb5edaaf51dd94ae01615 - Build
    libpq/11.5:9fc28f1bce9db80921859269566418c1997aa229 - Build
    openssl/1.1.1h:7bc8c2c85db7a618e5320dc997f27fc33e1df074 - Build
    pcre/8.41:00ce0eb92ff18fdcef18d35149ff79f2e13475f7 - Build
    poco/1.10.0:a62b3b7642c929f88fee01e91937e1eb4f066b68 - Build
    sqlite3/3.33.0:d7a5a0159ffdae5dbeca410940686c7d66bbd521 - Build
    zlib/1.2.11:7bc8c2c85db7a618e5320dc997f27fc33e1df074 - Build
Build requirements
    msys2/20190524 from 'conan-center' - Cache
    msys2/20200517 from 'conan-center' - Cache
    nasm/2.14 from 'conan-center' - Cache
Build requirements packages
    msys2/20190524:3cbd862cb7a3ea47ed1220dc027f344262d5224f - Cache
    msys2/20200517:3cbd862cb7a3ea47ed1220dc027f344262d5224f - Cache
    nasm/2.14:456f15897172eef340fcbac8a70811f2beb26a93 - Cache
Installing (downloading, building) binaries...
apr/1.7.0: WARN: Build folder is dirty, removing it: C:\Users\rik\.conan\data\apr\1.7.0\_\_\build\75bcd663b0f2f789317e8f347afd187fc180604d
apr/1.7.0: Copying sources to build folder
apr/1.7.0: Building your package in C:\Users\rik\.conan\data\apr\1.7.0\_\_\build\75bcd663b0f2f789317e8f347afd187fc180604d
apr/1.7.0: Generator cmake created conanbuildinfo.cmake
apr/1.7.0: Calling build()
apr/1.7.0: WARN: Error running `configure --help`: Error 1 while executing source_subfolder/configure --help
apr/1.7.0: Calling:
 > source_subfolder/configure --with-installbuilddir=${prefix}/bin/build-1 --disable-shared --enable-static --prefix=C:/Users/rik/.conan/data/apr/1.7.0/_/_/package/75bcd663b0f2f789317e8f347afd187fc180604d
'source_subfolder' is not recognized as an internal or external command,
operable program or batch file.
apr/1.7.0:
apr/1.7.0: ERROR: Package '75bcd663b0f2f789317e8f347afd187fc180604d' build failed
apr/1.7.0: WARN: Build folder C:\Users\rik\.conan\data\apr\1.7.0\_\_\build\75bcd663b0f2f789317e8f347afd187fc180604d
ERROR: apr/1.7.0: Error in build() method, line 90
        autotools = self._configure_autotools()
while calling '_configure_autotools', line 74
        self._autotools.configure(args=conf_args, configure_dir=self._source_subfolder)
        ConanException: Error 1 while executing source_subfolder/configure --with-installbuilddir=${prefix}/bin/build-1 --disable-shared --enable-static `--prefix=C:/Users/rik/.conan/data/apr/1.7.0/_/_/package/75bcd663b0f2f789317e8f347afd187fc180604d```




**I have been trying to solve the problem for a few hours now, but do not know how to continue. Does anyone have any ideas as to what I am doing wrong?

My current default conan profile looks as follows:**
```[settings]
os=Windows
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=6.3
compiler.libcxx=libstdc++11
build_type=Release
[options]
[build_requires]
[env]
```




Discussion:
Hi @RikUM 

This doesn't seem a Conan issue, but an issue of the ``apr/1.7.0`` package in ConanCenter, which doesn't correctly build using Mingw/gcc in Windows. This should be transferred to the ConanCenter conan-center-index Github repo.

If you are starting with Conan, using ConanCenter, you need to know that ConanCenter, in in general the whole Windows ecosystem is using Visual Studio as the default C++ compiler. I strongly recommend to use it as well. Libraries support for Mingw is limited, and even if package creators go to great extents and do a fantastic work, it is very challenging to have many open source libraries to build in Mingw. 

Visual Studio is completely free nowadays in the Community Edition, the compiler team is doing an amazing job catching up to latest standards, they are going open source a lot, like recently releasing in Github the STL... In the general case it is simply not worth to be fitghting with Mingw unless completely necessary, and if the goal is to start using Conan and get familiar with it, then I'd totally recommend Visual Studio.

Moving the issue to ConanCenter now.



Resolving patch:
diff --git a/recipes/apr/all/conanfile.py b/recipes/apr/all/conanfile.py
--- a/recipes/apr/all/conanfile.py
+++ b/recipes/apr/all/conanfile.py
@@ -64,13 +64,15 @@ def _configure_autotools(self):
             return self._autotools
         self._autotools = AutoToolsBuildEnvironment(self)
         self._autotools.libs = []
+        yes_no = lambda v: "yes" if v else "no"
         conf_args = [
             "--with-installbuilddir=${prefix}/bin/build-1",
+            "--enable-shared={}".format(yes_no(self.options.shared)),
+            "--enable-static={}".format(yes_no(not self.options.shared)),
         ]
-        if self.options.shared:
-            conf_args.extend(["--enable-shared", "--disable-static"])
-        else:
-            conf_args.extend(["--disable-shared", "--enable-static"])
+        if tools.cross_building(self.settings):
+            #
+            conf_args.append("apr_cv_mutex_robust_shared=yes")
         self._autotools.configure(args=conf_args, configure_dir=self._source_subfolder)
         return self._autotools
 


Test patch: