Issue
I'm trying to debug a C++ program in VSCode, using the microsoft/vscode-cmake-tools extension, but I get an error while the build step.
Reproduction Steps:
- Clone a library I need to use.
git submodule add https://github.com/dacap/clip.git clip
on the project directory, let's sayC:\pg\cpp_dev_02
- Create
CMakeLists.txt
(the content below), as documented on Home · dacap/clip Wiki (the cmake configuration output log below) - Click
debug
on the CMake menu to try to start debugging - Fails with an error (the cmake build output log below / the screenshot below)
That's all about the issue I have.
By the way building with cmake outside of VSCode passes.
cd C:\pg\cpp_dev_03\; mkdir build; cd build;
cmake ..
cmake --build . --config Release
C:\pg\cpp_dev_03\build\Release\myproject.exe
echo $? # True
Just in case the versions:
> g++ --version
g++.exe (x86_64-posix-seh, Built by strawberryperl.com project) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> Get-ComputerInfo|select WindowsProductName, WindowsVersion
WindowsProductName WindowsVersion
------------------ --------------
Windows 10 Pro 2009
# the exact commit of the the library using
> cd clip; git log
commit 94693e2414a2c69a8ca16f065240c80a94cc6221 (HEAD -> main, tag: v1.7, origin/main, origin/HEAD)
I have no clue what was wrong. I appreciate your help. Thanks.
CMakeLists.txt
cmake_minimum_required(VERSION 3.27)
project(myproject)
# Disable clip examples and tests
set(CLIP_EXAMPLES OFF CACHE BOOL "Compile clip examples")
set(CLIP_TESTS OFF CACHE BOOL "Compile clip tests")
# In case that you have ${PNG_LIBRARY} set to support copy/paste images on Linux
#set(CLIP_X11_PNG_LIBRARY "${PNG_LIBRARY}")
# Add clip subdirectory to compile the library
add_subdirectory(clip)
add_executable(myproject tmp3.cpp)
target_link_libraries(myproject clip)
tmp3.cpp
#include "clip/clip.h"
#include <iostream>
int main()
{
clip::set_text("Hello World");
std::string value;
clip::get_text(value);
std::cout << value << "\n";
}
- cmake configuration output log
[main] プロジェクトを構成しています: cpp_dev_02
[proc] コマンドを実行しています: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=C:\Strawberry\c\bin\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\Strawberry\c\bin\g++.exe -SC:/pg/cpp_dev_02 -Bc:/pg/cpp_dev_02/build -G "Unix Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] CMake Deprecation Warning at clip/CMakeLists.txt:4 (cmake_minimum_required):
[cmake] Compatibility with CMake < 3.5 will be removed from a future version of
[cmake] CMake.
[cmake]
[cmake] Update the VERSION argument <min> value or use a ...<max> suffix to tell
[cmake] CMake that the project does not need compatibility with older versions.
[cmake]
[cmake]
[cmake] -- Configuring done (0.2s)
[cmake] -- Generating done (0.1s)
[cmake] -- Build files have been written to: C:/pg/cpp_dev_02/build
- cmake build output log
[main] フォルダーのビルド中: cpp_dev_02 all
[build] ビルドを開始しています
[proc] コマンドを実行しています: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/pg/cpp_dev_02/build --config Debug --target all -j 10 --
[build] [ 16%] Building CXX object clip/CMakeFiles/clip.dir/clip_win.cpp.obj
[build] C:/pg/cpp_dev_02/clip/clip_win.cpp:467:19: warning: multi-character character constant [-Wmultichar]
[build] bi->bV5CSType = LCS_WINDOWS_COLOR_SPACE;
[build] ^~~~~~~~~~~~~~~~~~~~~~~
[build] In file included from C:/pg/cpp_dev_02/clip/clip_win.cpp:19:
[build] C:/pg/cpp_dev_02/clip/clip_win_wic.h: In function 'bool clip::win::read_png(const uint8_t*, UINT, clip::image*, clip::image_spec*)':
[build] C:/pg/cpp_dev_02/clip/clip_win_wic.h:210:33: error: 'CLSID_WICPngDecoder2' was not declared in this scope
[build] HRESULT hr = CoCreateInstance(CLSID_WICPngDecoder2,
[build] ^~~~~~~~~~~~~~~~~~~~
[build] C:/pg/cpp_dev_02/clip/clip_win_wic.h:210:33: note: suggested alternative: 'CLSID_WICPngDecoder'
[build] HRESULT hr = CoCreateInstance(CLSID_WICPngDecoder2,
[build] ^~~~~~~~~~~~~~~~~~~~
[build] CLSID_WICPngDecoder
[build] C:/pg/cpp_dev_02/clip/clip_win_wic.h:214:27: error: 'CLSID_WICPngDecoder1' was not declared in this scope
[build] hr = CoCreateInstance(CLSID_WICPngDecoder1,
[build] ^~~~~~~~~~~~~~~~~~~~
[build] C:/pg/cpp_dev_02/clip/clip_win_wic.h:214:27: note: suggested alternative: 'CLSID_WICPngDecoder'
[build] hr = CoCreateInstance(CLSID_WICPngDecoder1,
[build] ^~~~~~~~~~~~~~~~~~~~
[build] CLSID_WICPngDecoder
[build] gmake.exe[2]: *** [clip/CMakeFiles/clip.dir/build.make:104: clip/CMakeFiles/clip.dir/clip_win.cpp.obj] Error 1
[build] gmake.exe[1]: *** [CMakeFiles/Makefile2:126: clip/CMakeFiles/clip.dir/all] Error 2
[build] gmake.exe: *** [Makefile:91: all] Error 2
[proc] コマンド "C:\Program Files\CMake\bin\cmake.EXE" --build c:/pg/cpp_dev_02/build --config Debug --target all -j 10 -- はコード 2 で終了しました
[driver] ビルド完了: 00:00:02.763
[build] ビルドが終了コード 2 で終了しました
[main] "undefined" という名前の実行可能ファイルのターゲットを準備できませんでした
- Screenshot
Solution
Seems to be an issue pertaining to CLSID_WICPngDecoder2
and CLSID_WICPngDecoder1
definition not being found. Going through this GitHub issue-35 link tells that you are probably using an old version of MinGW.
Navigate to the clip/clip_win_wic.h:210:33
file and line, and check whether you can go to the definition of CLSID_WICPngDecoder2
and CLSID_WICPngDecoder1
, if not, that means the required dependencies of the library, especially windowscodecs
library in your case, are not setup properly.
Answered By - Ujjwal Raut Answer Checked By - Terry (WPSolving Volunteer)