cmake 使用MinGW g++ 8.3.0时,C++ Bulid错误“undefined”for dacap/clip

sc4hvdpw  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(43)

我试图在VSCode中调试一个C++程序,使用microsoft/vscode-cmake-tools扩展,但在构建步骤中出现错误。

复制步骤:

1.克隆一个库,我需要在项目目录上使用. git submodule add https://github.com/dacap/clip.git clip,假设是C:\pg\cpp_dev_02
1.创建CMakeLists.txt(下面的内容),如Home · dacap/clip Wiki(下面的cmake配置输出日志)中所述
1.单击CMake菜单上的debug以尝试开始调试
1.失败并出现错误(下面的cmake构建输出日志/下面的屏幕截图)
这就是我的问题所在。
顺便说一下,在VSCode之外使用cmake进行构建是通过的。

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

字符串
以防万一版本:

> 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)


我不知道出了什么事。谢谢你的帮助。谢谢。

  • 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配置输出日志
[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生成输出日志
[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" という名前の実行可能ファイルのターゲットを準備できませんでした

  • 截图

x1c 0d1x的数据

mgdq6dx1

mgdq6dx11#

似乎是一个与CLSID_WICPngDecoder2CLSID_WICPngDecoder1定义有关的问题没有找到。通过这个GitHub issue-35链接告诉你可能正在使用旧版本的MinGW。
导航到clip/clip_win_wic.h:210:33文件和行,并检查是否可以转到CLSID_WICPngDecoder2CLSID_WICPngDecoder1的定义,如果不能,这意味着库所需的依赖关系,特别是在您的情况下windowscodecs库,没有正确设置。

相关问题