用DuckDB官方的步骤生成 1.4版插件的问题和解决
完全按照https://github.com/duckdb/extension-template 介绍的步骤,结果有一些问题。
- vcpkg/scripts/bootstrap.sh执行出错
一开始是没装zip,
root@6ae32a5ffcde:/par/extension-template# sh ./vcpkg/scripts/bootstrap.sh -disableMetrics
Could not find zip. Please install it (and other dependencies) with:
装上就往下执行了,但是执行到第185行出错,
root@6ae32a5ffcde:/par/extension-template# apt install zip
Setting up zip (3.0-13) ...
root@6ae32a5ffcde:/par/extension-template# sh ./vcpkg/scripts/bootstrap.sh -disableMetrics
./vcpkg/scripts/bootstrap.sh: 185: .: cannot open //scripts/vcpkg-tool-metadata.txt: No such file
这个目录明显错误。
185行原文是
. "$vcpkgRootDir/scripts/vcpkg-tool-metadata.txt"
而在bootstrap.sh文件开头有计算vcpkgRootDir的代码,把它们都注释掉。
# Find .vcpkg-root.
#vcpkgRootDir=$(X= cd -- "$(dirname -- "$0")" && pwd -P)
#while [ "$vcpkgRootDir" != "/" ] && ! [ -e "$vcpkgRootDir/.vcpkg-root" ]; do
# vcpkgRootDir="$(dirname "$vcpkgRootDir")"
#done
然后把vcpkgRootDir
手工设置,就走下去了。
export vcpkgRootDir=/par/extension-template/vcpkg
root@6ae32a5ffcde:/par/extension-template# sh ./vcpkg/scripts/bootstrap.sh -disableMetrics
Downloading vcpkg-glibc...
vcpkg package management program version 2025-09-03-4580816534ed8fd9634ac83d46471440edd82dfeSee LICENSE.txt for license information.
2.make 执行出错
root@6ae32a5ffcde:/par/extension-template# export VCPKG_TOOLCHAIN_PATH=`pwd`/vcpkg/scripts/buildsystems/vcpkg.cmake
root@6ae32a5ffcde:/par/extension-template# make
mkdir -p build/release
cmake -DEXTENSION_STATIC_BUILD=1 -DDUCKDB_EXTENSION_CONFIGS='/par/extension-template/extension_config.cmake' -DOSX_BUILD_ARCH= -DVCPKG_BUILD=1 -DCMAKE_TOOLCHAIN_FILE='/par/extension-template/vcpkg/scripts/buildsystems/vcpkg.cmake' -DDUCKDB_EXPLICIT_PLATFORM='' -DCUSTOM_LINKER= -DOVERRIDE_GIT_DESCRIBE="" -DUNITTEST_ROOT_DIRECTORY="/par/extension-template/" -DBENCHMARK_ROOT_DIRECTORY="/par/extension-template/" -DENABLE_UNITTEST_CPP_TESTS=FALSE -DBUILD_EXTENSION_TEST_DEPS=default -DVCPKG_MANIFEST_DIR='/par/extension-template/' -DCMAKE_BUILD_TYPE=Release -S "./duckdb/" -B build/release
-- Found Python3: /usr/bin/python3 (found version "3.11.2") found components: Interpreter
CMake Error at /par/extension-template/vcpkg/scripts/buildsystems/vcpkg.cmake:943 (message):Could not find .vcpkg-root
Call Stack (most recent call first):/usr/share/cmake-3.25/Modules/CMakeDetermineSystem.cmake:124 (include)CMakeLists.txt:23 (project)
943行的内容如下
if(Z_VCPKG_HAS_FATAL_ERROR)message(FATAL_ERROR "${Z_VCPKG_FATAL_ERROR}")
endif()
再搜索错误提示Could not find .vcpkg-root
,在403行找到
if(NOT Z_VCPKG_ROOT_DIR)z_vcpkg_add_fatal_error("Could not find .vcpkg-root")
endif()
还是找不到vcpkg根目录,在 403行前加入一行手工设置,set(Z_VCPKG_ROOT_DIR /par/extension-template/vcpkg)
,就又走下去了。
3.找不到ExtensionLoader类编译错误
[ 32%] Building CXX object src/main/extension/CMakeFiles/duckdb_generated_extension_loader.dir/__/__/__/codegen/src/generated_extension_loader.cpp.o
In file included from /par/extension-template/build/release/codegen/include/generated_extension_headers.hpp:4,from /par/extension-template/duckdb/src/include/duckdb/main/extension/generated_extension_loader.hpp:1,from /par/extension-template/build/release/codegen/src/generated_extension_loader.cpp:1:
/par/extension-template/src/include/quack_extension.hpp:9:19: error: 'ExtensionLoader' has not been declared9 | void Load(ExtensionLoader &db) override;| ^~~~~~~~~~~~~~~
/par/extension-template/src/include/quack_extension.hpp:9:14: error: 'void duckdb::QuackExtension::Load(int&)' marked 'override', but does not override9 | void Load(ExtensionLoader &db) override;| ^~~~
In file included from /par/extension-template/duckdb/src/include/duckdb/main/extension/generated_extension_loader.hpp:1:
/par/extension-template/duckdb/src/include/duckdb/main/database.hpp: In instantiation of 'void duckdb::DuckDB::LoadStaticExtension() [with T = duckdb::QuackExtension]':
/par/extension-template/build/release/codegen/src/generated_extension_loader.cpp:9:45: required from here9 | db.LoadStaticExtension<QuackExtension>();| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
/par/extension-template/duckdb/src/include/duckdb/main/database.hpp:119:19: error: cannot declare variable 'extension' to be of abstract type 'duckdb::QuackExtension'119 | T extension;| ^~~~~~~~~
/par/extension-template/src/include/quack_extension.hpp:7:7: note: because the following virtual functions are pure within 'duckdb::QuackExtension':7 | class QuackExtension : public Extension {| ^~~~~~~~~~~~~~
In file included from /par/extension-template/duckdb/src/include/duckdb/main/database.hpp:14:
/par/extension-template/duckdb/src/include/duckdb/main/extension.hpp:22:33: note: 'virtual void duckdb::Extension::Load(duckdb::DuckDB&)'22 | DUCKDB_API virtual void Load(DuckDB &db) = 0;| ^~~~
/par/extension-template/duckdb/src/include/duckdb/main/database.hpp:123:31: error: cannot convert 'duckdb::DuckDB' to 'int&'123 | extension.Load(*this);| ~~~~~~~~~~~~~~^~~~~~~
/par/extension-template/src/include/quack_extension.hpp:9:36: note: initializing argument 1 of 'void duckdb::QuackExtension::Load(int&)'9 | void Load(ExtensionLoader &db) override;| ~~~~~~~~~~~~~~~~~^~
gmake[3]: *** [src/main/extension/CMakeFiles/duckdb_generated_extension_loader.dir/build.make:76: src/main/extension/CMakeFiles/duckdb_generated_extension_loader.dir/__/__/__/codegen/src/generated_extension_loader.cpp.o] Error 1
gmake[3]: Leaving directory '/par/extension-template/build/release'
gmake[2]: *** [CMakeFiles/Makefile2:6462: src/main/extension/CMakeFiles/duckdb_generated_extension_loader.dir/all] Error 2
gmake[2]: Leaving directory '/par/extension-template/build/release'
gmake[1]: *** [Makefile:136: all] Error 2
gmake[1]: Leaving directory '/par/extension-template/build/release'
make: *** [extension-ci-tools/makefiles/duckdb_extension.Makefile:161: release] Error 2
root@6ae32a5ffcde:/par/extension-template#
这个类是1.4版新引入的,我在自己用动态链接库编译时,动态链接库附带的duckdb.hpp中有它的声明,但是源代码中的duckdb.hpp只有如下5行
#pragma once#include "duckdb/main/connection.hpp"
#include "duckdb/main/database.hpp"
#include "duckdb/main/query_result.hpp"
#include "duckdb/main/appender.hpp"
一开始以为是git clone了错误版本,手工下载了1.4发行版的源代码压缩包,也是一样的,就没办法了。
官方的步骤这么多,生成速度又慢,从开始make到出错,大概几十分钟,等不起,这就是消除插件对动态库依赖的代价,如果要开发自己的插件,还是链接动态库好了。