You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用MinGW g++8.3.0构建dacap/clip时出现未定义标识符错误

VSCode中CMake Tools构建失败但外部CMake成功的问题

在VSCode使用microsoft/vscode-cmake-tools插件调试C++程序时,构建步骤出现错误,但在VSCode外部使用CMake构建相同项目却能成功。

复现步骤

  • 在项目目录C:\pg\cpp_dev_02中执行git submodule add https://github.com/dacap/clip.git clip引入dacap/clip库
  • 按照dacap/clip官方wiki编写CMakeLists.txt(内容见下文)
  • 点击CMake菜单中的debug选项尝试启动调试
  • 构建失败并报错(构建日志见下文)

环境版本

  • g++版本:8.3.0(x86_64-posix-seh,Strawberry Perl构建)
  • 系统:Windows 10 Pro 2009
  • clip库版本:commit 94693e2414a2c69a8ca16f065240c80a94cc6221(tag: v1.7)

相关文件内容

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" という名前の実行可能ファイルのターゲットを準備できませんでした

不清楚问题出在哪里,希望能得到帮助,谢谢!


内容的提问来源于stack exchange,提问作者丶 Limeー来夢 丶

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 08:15:55