So I was following this tutorial on CMake in VSCode setup, and everything was going good, until I tried to build project. I chose preset for urct64/bin/g++.exe. The build process exits with error and prints:
[main] Building folder: C:/Users/maxka/VSC/cmake_learn/out/build/ucrt64
[build] Starting build
[proc] Executing command: chcp
[proc] Executing command: C:\Cmake\bin\cmake.EXE --build C:/Users/maxka/VSC/cmake_learn/out/build/ucrt64 --parallel 10 --target cmake_learn --
[build] [ 50%] Building CXX object CMakeFiles/cmake_learn.dir/main.cpp.obj
[build] [100%] Linking CXX executable cmake_learn.exe
[build] collect2.exe: error: ld returned 116 exit status
[build] mingw32-make[3]: *** [CMakeFiles\cmake_learn.dir\build.make:98: cmake_learn.exe] Error 1
[build] mingw32-make[3]: *** Deleting file 'cmake_learn.exe'
[build] mingw32-make[2]: *** [CMakeFiles\Makefile2:838: CMakeFiles/cmake_learn.dir/all] Error 2
[build] mingw32-make[1]: *** [CMakeFiles\Makefile2:845: CMakeFiles/cmake_learn.dir/rule] Error 2
[build] mingw32-make: *** [Makefile:497: cmake_learn] Error 2
[proc] The command: C:\Cmake\bin\cmake.EXE --build C:/Users/maxka/VSC/cmake_learn/out/build/ucrt64 --parallel 10 --target cmake_learn -- exited with code: 2
[driver] Build completed: 00:00:01.153
[build] Build finished with exit code 2
The .cpp file I am trying to run is:
#include <iostream>
// #include <stdio.h>
#include <vector>
#include <string>
using namespace std;
int main(){
// printf("Hello world\n");
cout << "Hello world\n" << endl;
return 0;
}
When using stdio.h
and printf
instead of iostream
and cout
, it builds and works just fine.
Also, when changing the configuration preset from urct64/bin/g++ to mingw64/bin/g++ it builds with no problems, but .exe quits immideatly after start - it seems like it breaks on first iostream
function call, because if both printf
and cout
are uncommented, printf
works, but not cout
. If these rearranged so cout
is called first, both do not work.
CMakeLists is identical to one used in the tutorial:
cmake_minimum_required(VERSION 3.5.0)
project(cmake_learn VERSION 0.1.0 LANGUAGES C CXX)
include(CTest)
enable_testing()
add_executable(cmake_learn main.cpp)
set_property(TARGET cmake_learn PROPERTY CXX_STANDARD 17)
Looks like there was indeed dll compatability problem due to my unorganized MSYS packages dowloads. I reinstalled MSYS and all packeges I needed and now it works.