完全按照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-4580816534ed8fd9634ac83d46471440edd82dfe
See 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 declared
9 | 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 override
9 | 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 here
9 | 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发行版的源代码压缩包,duckdb.hpp也是一样的。
官方的步骤这么多,生成速度又慢,从开始make到出错,大概几十分钟,等不起,这就是消除插件对动态库依赖的代价,
查看libduckdb自带的duckdb.hpp文件,有关ExtensionLorder的类声明后面有注释// duckdb/main/extension/extension_loader.hpp,而git clone拉取的相应src/include目录下没有这个文件,同样src中也没有与它对应的extension_loader.cpp文
件,把它们从存储库网页上复制下来保存到两个目录,重新make还是同样的错误,改用make debug还是同样的错误,可能是其他配置文件也不对。所以到release页面,下载完整的DuckDB 1.4源代码,然后解压缩覆盖有问题的duckdb目录,再次make就编译过了这个文件。
[ 31%] Building CXX object src/main/extension/CMakeFiles/duckdb_generated_extension_loader.dir/__/__/__/codegen/src/generated_extension_loader.cpp.o
gmake[3]: Leaving directory '/par/extension-template/build/debug'
[ 31%] Built target duckdb_generated_extension_loader
gmake[3]: Entering directory '/par/extension-template/build/debug'
gmake[3]: Leaving directory '/par/extension-template/build/debug'
gmake[3]: Entering directory '/par/extension-template/build/debug'
[ 31%] Building CXX object src/main/extension/CMakeFiles/duckdb_main_extension.dir/extension_alias.cpp.o
[ 31%] Building CXX object src/main/extension/CMakeFiles/duckdb_main_extension.dir/extension_helper.cpp.o
[ 32%] Building CXX object src/main/extension/CMakeFiles/duckdb_main_extension.dir/extension_install.cpp.o
[ 32%] Building CXX object src/main/extension/CMakeFiles/duckdb_main_extension.dir/extension_load.cpp.o
[ 32%] Building CXX object src/main/extension/CMakeFiles/duckdb_main_extension.dir/extension_loader.cpp.o
make debug还有另外一个错误,检测平台失败
[ 7%] Generating duckdb_platform_out
==4761==LeakSanitizer has encountered a fatal error.
==4761==HINT: For debugging, try setting environment variable LSAN_OPTIONS=verbosity=1:log_threads=1
==4761==HINT: LeakSanitizer does not work under ptrace (strace, gdb, etc)
Provide explicit DUCKDB_PLATFORM=your_target_arch to avoid build-type detection of the platform
参考make release的输出明确填写环境变量后通过DUCKDB_PLATFORM=x64-linux make debug
替换源代码,make就重头编译实在太慢了。试图用make -j 6多任务编译也不行,报错gmake[1]: warning: jobserver unavailable: using -j1. 。
DuckDB开发团队也意识到这个,https://github.com/duckdb/extension-template 中说:
Tips for speedy builds
DuckDB extensions currently rely on DuckDB’s build system to provide easy testing and distributing. This does however come at the downside of requiring the template to build DuckDB and its unittest binary every time you build your extension. To mitigate this, we highly recommend installing ccache and ninja. This will ensure you only need to build core DuckDB once and allows for rapid rebuilds.
To build using ninja and ccache ensure both are installed and run:
GEN=ninja make
如果要开发自己的插件,还是链接动态库好了。

1051

被折叠的 条评论
为什么被折叠?



