conan-io/conan

MinGW(GCC)

Closed this issue ยท 30 comments

I am using clion with MinGW compiler.Conan is detecting that i am using Visual Studio compiler

Auto detecting your dev setup to initialize the default profile (C:\Users\Name\.conan\profiles\default)

Found Visual Studio 14`

Default settings
        os=Windows
        os_build=Windows
        arch=x86_64
        arch_build=x86_64
        compiler=Visual Studio
        compiler.version=14
        build_type=Release


Indeed now cmake detects a wrong compiler.

CMake Error at .conan/conanbuildinfo.cmake:448 (message):
 Incorrect 'Visual Studio'.  Toolset specifies compiler as 'MSVC' but CMake   detected 'GNU'

Clion details
https://i.gyazo.com/47693754c3a0d7d80abb23ccd5d40c09.png

How can i fix the compiler issue ?

Create a profile for your MinGW toolchain here ~/.conan/profiles/mingw64, enter your settings eg.

[build_requires]
[settings]
    os=Windows
    os_build=Windows
    arch=x86_64
    arch_build=x86_64
    compiler=gcc
    compiler.version=7.2
    compiler.libcxx=libstdc++11
    build_type=Debug
[options]
[env]

Then use that profile when installing:

conan install .. --build=missing --profile=mingw64

Thanks you i was missing the compiler.libcxx=libstdc++11

However i get another error even with the correct profile

PROJECT: Installing C:\Users\Khav\CLionProjects\PNGTest\conanfile.txt
Requirements
zlib/1.2.11@conan/stable from 'conan-center'
Packages
zlib/1.2.11@conan/stable:afd95b1465a2ac6244975d11191af260a5294d40

zlib/1.2.11@conan/stable: Building your package in C:\Users\Khav.conan\data\zlib\1.2.11\conan\stable\build\afd95b1465a2ac6244975d11191af260a5294d40
zlib/1.2.11@conan/stable: Copying sources to build folder
zlib/1.2.11@conan/stable: Generator cmake created conanbuildinfo.cmake
zlib/1.2.11@conan/stable: Calling build()
'cmake' is not recognized as an internal or external command,
operable program or batch file.
zlib/1.2.11@conan/stable:
zlib/1.2.11@conan/stable: ERROR: Package 'afd95b1465a2ac6244975d11191af260a5294d40' build failed
zlib/1.2.11@conan/stable: WARN: Build folder C:\Users\Khav.conan\data\zlib\1.2.11\conan\stable\build\afd95b1465a2ac6244975d11191af260a5294d40
ERROR: zlib/1.2.11@conan/stable: Error in build() method, line 55
cmake.configure(build_dir=".")
ConanException: Error 1 while executing cd . && cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE="Debug" -DCONAN_EXPORTED="1" -DCONAN_COMPILER="gcc" -DCONAN_COMPILER_VERSION="7.2" -DCONAN_CXX_FLAGS="-m64" -DCONAN_SHARED_LINKER_FLAGS="-m64" -DCONAN_C_FLAGS="-m64" -DBUILD_SHARED_LIBS="ON" -DCMAKE_
INSTALL_PREFIX="C:\Users\Khav.conan\data\zlib\1.2.11\conan\stable\package\afd95b1465a2ac6244975d11191af260a5294d40" -Wno-dev C:\Users\Khav.conan\data\zlib\1.2.11\conan\stable\build\afd95b1465a2ac6244975d11191af260a5294d40

Clion works with cmake just fine though

The problem is

'cmake' is not recognized as an internal or external command

MinGW gives you a minimal PATH which does not inherit the regular Windows PATH. You need to add CMake to the MingGW PATH. One way to do it is to add CMake to the PATH in ~/.bashrc in MinGW. For example, assuming CMake is installed in C:\Program Files\CMake:

export PATH=/c/Program\ Files/CMake/bin:$PATH

This way you can also run CMake from the MinGW command line.

Alternatively you can add CMake to the PATH in your profile.

What do you mean by adding CMake to MingGW PATH.I would like to use the cmake Bundled in MinGW itself.

If i add Cmake to PATH in my profile i get the following

CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool. CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool. CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage

Thanks a lot for the help

Which shell are you running? And what is your full PATH? For example:

echo $PATH

You want to have the directory that contains mingw32-make.exe in your PATH.

For example, if you are using msys2 installed in C:\msys2 then you'll want to add /c/msys2/mingw64/bin to your PATH in ~/.bashrc. But it should already be there if you are running the MinGW64 shell.

Alternatively you can add this to your profile:

[env]
CMAKE_MAKE_PROGRAM=C:\msys2\mingw64\bin\mingw32-make.exe

Actually if you have CMake installed in mingw64, then just having /c/msys2/mingw64/bin in your PATH will work. You won't need /c/Program\ Files/CMake/bin too (that would be CMake installed for Windows).

You can tell by starting up a Mingw64 shell and running which cmake.

PATH=C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program File
s\ImageMagick-7.0.7-Q16;C:\Python27;C:\Python27\Scripts;C:\ProgramData\Oracle\J
ava\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows
System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\NVIDIA Corporation\PhysX
\Common;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files (
x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn;C:\Program Files (x86)
\Microsoft SQL Server\130\Tools\Binn;C:\Program Files (x86)\Microsoft SQL Serve
r\130\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\Manag
ementStudio;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Bin
n;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn;C:\Program Files
Microsoft SQL Server\120\Tools\Binn;C:\Program Files\Microsoft SQL Server\120\D
TS\Binn;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\Windows
PowerShell\v1.0;C:\Program Files (x86)\Skype\Phone;C:\Program Files\OpenVPN\bi
n;C:\Program Files\Git\cmd;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Progra
m Files\PuTTY;C:\Users\Khav\AppData\Local\Programs\Python\Python36-32\Scripts;
C:\Users\Khav\AppData\Local\Programs\Python\Python36-32;C:\Program Files\Common
Files\Microsoft Shared\Windows Live;C:\Users\Khav\AppData\Local\Programs\Python
\Python36\Scripts;C:\Users\Khav\AppData\Local\Programs\Python\Python36;C:\Prog
ram Files\Docker Toolbox;C:\Program Files\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5
-rev1\mingw64\bin

i am on windows 7

Ok - so it looks like you are not running a Mingw or Msys2 shell. You are running a regular Windows command prompt, is that correct?

What files are in C:\Program Files\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin?

Yes i am running a regular windows command prompt.I have many exe there like gcc.exe but cmake.exe isn't there.How is Clion detecting Cmake as Bundled then.

Is mingw32-make.exe in C:\Program Files\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin?

CLion has its own CMake that is bundled in the CLion installation.

I'm curious how you installed Mingw. I would like to try to install it the same way to try out.

As far as i can remember i install mingw64 and then that's it.

https://sourceforge.net/projects/mingw-w64/

Later i installed Cmake Gui as well for some other purpose
https://cmake.org/download/

In fact i just took cmake.exe from that cmake directory and pasted it in mingw64\bin

That seems to fix that specific error but it leads to another one

PROJECT: Installing C:\Users\Khav\CLionProjects\PNGTest\conanfile.txt
Requirements
zlib/1.2.11@conan/stable from 'conan-center'
Packages
zlib/1.2.11@conan/stable:afd95b1465a2ac6244975d11191af260a5294d40

Downloading conan_sources.tgz
[==================================================] 281B/281B
zlib/1.2.11@conan/stable: Building your package in C:\Users\Khav.conan\data\zlib\1.2.11\conan\stable\build\afd95b1465a2ac6244975d11191af260a5294d40
zlib/1.2.11@conan/stable: Configuring sources in C:\Users\Khav.conan\data\zlib\1.2.11\conan\stable\source
[==================================================] 593.5KB/593.5KB
zlib/1.2.11@conan/stable: Copying sources to build folder
zlib/1.2.11@conan/stable: Generator cmake created conanbuildinfo.cmake
zlib/1.2.11@conan/stable: Calling build()
-- The C compiler identification is GNU 7.2.0
-- The CXX compiler identification is GNU 7.2.0
-- Check for working C compiler: C:/Program Files/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/bin/gcc.exe
-- Check for working C compiler: C:/Program Files/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/bin/g++.exe
-- Check for working CXX compiler: C:/Program Files/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Conan: called by CMake conan helper
-- Conan: Compiler GCC>=5, checking major version 7.2
-- Conan: Checking correct version: 7.2
-- Conan: Using cmake global configuration
-- Conan: Adjusting default RPATHs Conan policies
-- Conan: Adjusting language standard
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of off64_t
-- Check size of off64_t - done
-- Looking for fseeko
-- Looking for fseeko - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Renaming
-- C:/Users/Khav/.conan/data/zlib/1.2.11/conan/stable/build/afd95b1465a2ac6244975d11191af260a5294d40/zlib-1.2.11/zconf.h
-- to 'zconf.h.included' because this file is included with zlib
-- but CMake generates it automatically in the build directory.
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Khav/.conan/data/zlib/1.2.11/conan/stable/build/afd95b1465a2ac6244975d11191af260a5294d40/zlib-1.2.11/_build
[ 2%] Generating zlib1rc.obj
Scanning dependencies of target zlibstatic
[ 4%] Building C object zlib-1.2.11/CMakeFiles/zlibstatic.dir/adler32.obj
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
C:\Program Files\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin\windres.exe: preprocessing failed.
mingw32-make.exe[2]: *** [zlib-1.2.11\CMakeFiles\zlib.dir\build.make:61: zlib-1.2.11/zlib1rc.obj] Error 1
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:131: zlib-1.2.11/CMakeFiles/zlib.dir/all] Error 2
mingw32-make.exe[1]: *** Waiting for unfinished jobs....
[ 7%] Building C object zlib-1.2.11/CMakeFiles/zlibstatic.dir/compress.obj
[ 9%] Building C object zlib-1.2.11/CMakeFiles/zlibstatic.dir/crc32.obj
[ 12%] Building C object zlib-1.2.11/CMakeFiles/zlibstatic.dir/deflate.obj
[ 14%] Building C object zlib-1.2.11/CMakeFiles/zlibstatic.dir/gzclose.obj
[ 17%] Building C object zlib-1.2.11/CMakeFiles/zlibstatic.dir/gzlib.obj
[ 19%] Building C object zlib-1.2.11/CMakeFiles/zlibstatic.dir/gzread.obj
[ 21%] Building C object zlib-1.2.11/CMakeFiles/zlibstatic.dir/gzwrite.obj
[ 24%] Building C object zlib-1.2.11/CMakeFiles/zlibstatic.dir/inflate.obj
[ 26%] Building C object zlib-1.2.11/CMakeFiles/zlibstatic.dir/infback.obj
[ 29%] Building C object zlib-1.2.11/CMakeFiles/zlibstatic.dir/inftrees.obj
[ 31%] Building C object zlib-1.2.11/CMakeFiles/zlibstatic.dir/inffast.obj
[ 34%] Building C object zlib-1.2.11/CMakeFiles/zlibstatic.dir/trees.obj
[ 36%] Building C object zlib-1.2.11/CMakeFiles/zlibstatic.dir/uncompr.obj
[ 39%] Building C object zlib-1.2.11/CMakeFiles/zlibstatic.dir/zutil.obj
[ 41%] Linking C static library ..\lib\libzlibstatic.a
[ 41%] Built target zlibstatic
mingw32-make.exe: *** [Makefile:129: all] Error 2
zlib/1.2.11@conan/stable:
zlib/1.2.11@conan/stable: ERROR: Package 'afd95b1465a2ac6244975d11191af260a5294d40' build failed
zlib/1.2.11@conan/stable: WARN: Build folder C:\Users\Khav.conan\data\zlib\1.2.11\conan\stable\build\afd95b1465a2ac6244975d11191af260a5294d40
ERROR: zlib/1.2.11@conan/stable: Error in build() method, line 56
cmake.build(build_dir=".")
ConanException: Error 2 while executing cmake --build . -- -j8

There seems to be some kind of issue with the path again

'C:\Program' is not recognized as an internal or external command,

I would not recommend copying stuff into mingw64\bin. If CMake is in your Windows PATH then that's all that should be necessary.

Some of the advice that I was giving you earlier was assuming that you were using msys2 as a command line shell. That's why I was talking about ~/.bashrc. You can ignore that stuff, also when I said "MinGW gives you a minimal PATH", that is msys2-related too.

To debug the error that you are seeing you should look in the CMakeFiles directory for CMakeError.log to see exactly what the cause is.

On the other hand, rather than trying to get Conan working with your installation of MinGW an alternative is to use the mingw_installer in your profile. This will download a copy of MinGW into your Conan local cache and will automatically set up all of the environment variables correctly. For example, add this to your profile:

[build_requires]
mingw_installer/1.0@conan/stable

Then you can remove this from your profile:

[env]
CMAKE_MAKE_PROGRAM=C:\msys2\mingw64\bin\mingw32-make.exe

Also this way it won't be tied to your particular installation of MinGW.

ERROR: mingw_installer/1.0@conan/stable: 'settings.compiler.exception' value not defined

I was able to replicate the problem that you had

'C:\Program' is not recognized as an internal or external command`

Unfortunately I wasn't able to figure out (yet) how to fix it without using mingw_installer/1.0@conan/stable. I'll try to figure that out at a later time.

This error:

ERROR: mingw_installer/1.0@conan/stable: 'settings.compiler.exception' value not defined

Is due to a missing profile setting. I was able to install zlib from source using this profile:

[build_requires]
mingw_installer/1.0@conan/stable

[settings]
os_build=Windows
os=Windows
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=7
compiler.exception=seh
compiler.libcxx=libstdc++11
compiler.threads=posix
build_type=Debug

Note the compiler.exception=seh

I believe you should install Mingw to a path without spaces to fix 'C:\Program' is not recognized as an internal or external command. For instance in C:\some_folder\.

Yep - you're right. After I moved C:\Program Files\mingw-w64 to C:\mingw-w64 and used the profile:

[settings]
os_build=Windows
os=Windows
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=7
compiler.exception=seh
compiler.libcxx=libstdc++11
compiler.threads=posix
build_type=Debug

[env]
CONAN_CMAKE_GENERATOR=MinGW Makefiles

Then I was able to

conan install zlib/1.2.11@conan/stable --build zlib -pr mingw64

Also, that's why

[build_requires]
mingw_installer/1.0@conan/stable

worked, is because the Mingw directory in the Conan cache didn't have a space in it.

It is very typical indeed that build scripts of libraries or some recipes won't work well with path with spaces. Not only for conan, but many other tools. I always make sure to install things when possible in paths without spaces and without any special (other than ascii) characters, it saves a lot of pain later.

I'm surprised that the Mingw installer installs to C:\Program Files by default. That's crazy! I didn't notice it the first time that I went through the wizard.

@sourcedelica

Thanks a lot , with C:\mingw-w64 and your profile worked fine.I might be asking for too much but i will take a stab at it.

I am getting the following errors

undefined reference to `__imp_htonl'

My headers are defined as

#include
#include
#include
#include <zlib.h>
#include <winsock2.h>

adding ws2_32 to the target_link_librariesin cmake solved the issue

I was too quick , i got the following error

Process finished with exit code -1073741515 (0xC0000135)

It seems like some ddl was not found

Here is my full cmake file

cmake_minimum_required(VERSION 3.10)
project(PNGTest)

set(CMAKE_CXX_STANDARD 11)

include(.conan/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(PNGTest main.cpp)
target_link_libraries(PNGTest ${CONAN_LIBS} ws2_32)

It seems like some ddl was not found

What is ddl? Did you mean dll?
How did you arrive at this conclusion?

If I were you, I would run it in a debugger to see where it is crashing.
Or you could use some dependency analyzer tool to check what libraries the binary requires.

BTW it would be easier for people to help you if you provided: detailed steps to reproduce your problem, expected result, actual result and environment information.

@ArekPiekarz
Yes i mean dll , it was a typo

The debugger give me the following error:
During startup program exited with code 0xc0000135.
I arrived to this conclusion by googling the error

What about the rest of the things I suggested you could do?

@ArekPiekarz
Full sample code can be found @ https://pastebin.com/maeXPgqL
Just run it in clion

cmake_minimum_required(VERSION 3.10)
project(ZlibExample)

include(.conan/conanbuildinfo.cmake)
conan_basic_setup()

set(CMAKE_CXX_STANDARD 11)

add_executable(ZlibExample main.cpp)
target_link_libraries(ZlibExample ${CONAN_LIBS})

The bug is in your program, you have an uninitialized z_stream zs; in function CompressStringGzip. Initializing it with z_stream zs{}; fixes the problem.

Anyway, I don't have CLion, only Qt Creator and I tested it on Msys2 with these modifications to your files to make life easier:

CMakeLists.txt

cmake_minimum_required(VERSION 3.10)
project(ZlibExample)

if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
   message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
   file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/v0.11/conan.cmake"
                 "${CMAKE_BINARY_DIR}/conan.cmake")
endif()
include(${CMAKE_BINARY_DIR}/conan.cmake)
conan_cmake_run(
    CONANFILE conanfile.txt
    BASIC_SETUP
    BUILD missing)

set(CMAKE_CXX_STANDARD 11)

add_executable(ZlibExample main.cpp)
target_link_libraries(ZlibExample ${CONAN_LIBS})

conanfile.txt

[requires]
zlib/1.2.11@conan/stable

[generators]
cmake

BTW the unitialized variable was pointed at me immediately by clang-tidy plugin in Qt Creator with enabled cppcoreguidelines checks.

I would not recommend copying stuff into mingw64\bin. If CMake is in your Windows PATH then that's all that should be necessary.

Some of the advice that I was giving you earlier was assuming that you were using msys2 as a command line shell. That's why I was talking about ~/.bashrc. You can ignore that stuff, also when I said "MinGW gives you a minimal PATH", that is msys2-related too.

To debug the error that you are seeing you should look in the CMakeFiles directory for CMakeError.log to see exactly what the cause is.

On the other hand, rather than trying to get Conan working with your installation of MinGW an alternative is to use the mingw_installer in your profile. This will download a copy of MinGW into your Conan local cache and will automatically set up all of the environment variables correctly. For example, add this to your profile:

[build_requires]
mingw_installer/1.0@conan/stable

Then you can remove this from your profile:

[env]
CMAKE_MAKE_PROGRAM=C:\msys2\mingw64\bin\mingw32-make.exe

Also this way it won't be tied to your particular installation of MinGW.

[build_requires]
mingw-builds/12.2.0

This issue was quite outdated from 2018, until recent @Baneeishaque comment.

I have just tried exactly that, having a tool-requires to mingw-builds/12.2.0 and it works pretty well, I am closing this ticket as outdated/solved, and I will probably open a PR to the docs with an example.

If there is any further issue or question, please create a new ticket. Many thanks!