2025年11月13日 星期四

樹莓派 Pi 400 編譯與安裝 Ta-Lib 套件 (失敗)

昨天高雄放颱風假 (鳳凰颱風), 我花了一整天想把 Pi 400 的 Ta-Lib 套件安裝起來, 此套件在 Linux 機器上比較麻煩, 必須先從 C 原始碼編譯, 最後再用 pip install 安裝 Python 外殼, 忙了一天最後還是功敗垂成, 決定放棄 (這套件畢竟是太老了).  

先記錄目前檔案系統占用容量, 已用 7.4GB : 

pi@raspberrypi:~ $ df -h  
檔案系統        容量  已用  可用 已用% 掛載點
udev            1.6G     0  1.6G    0% /dev
tmpfs           760M   68M  693M    9% /run
/dev/mmcblk0p2   59G  7.4G   48G   14% /
tmpfs           1.9G  892K  1.9G    1% /dev/shm
tmpfs           5.0M   12K  5.0M    1% /run/lock
/dev/mmcblk0p1  510M   78M  433M   16% /boot/firmware
tmpfs           380M   44K  380M    1% /run/user/1000

會用到的指令如下 :

sudo apt update
sudo apt install -y build-essential wget

cd /usr/local/src
sudo wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
sudo tar -xvzf ta-lib-0.4.0-src.tar.gz
cd ta-lib
sudo ./configure --prefix=/usr
sudo make
sudo make install


1. 更新套件清單 :  

pi@raspberrypi:~ $ sudo apt update
已有:1 http://deb.debian.org/debian bookworm InRelease
下載:2 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
下載:3 http://deb.debian.org/debian bookworm-updates InRelease [55.4 kB]                     
已有:4 http://archive.raspberrypi.com/debian bookworm InRelease
下載:5 http://deb.debian.org/debian-security bookworm-security/main arm64 Packages [281 kB]
下載:6 http://deb.debian.org/debian-security bookworm-security/main armhf Packages [266 kB]
下載:7 http://deb.debian.org/debian-security bookworm-security/main Translation-en [173 kB]
取得 824 kB 用了 2s (491 kB/s)                                 
正在讀取套件清單... 完成
正在重建相依關係... 完成
正在讀取狀態資料... 完成  
35 packages can be upgraded. Run 'apt list --upgradable' to see them.


2. 安裝 C/C++ 編譯工具集 build-essential 與下載工具 wget :  

build-essential 工具集是編譯像 TA-Lib 這樣的 C 函式庫所需的工具程式, 包含 gcc (C 編譯器), gc++ (C++ 編譯器), make (自動化編譯工具), libc6-dev (C 標準函式庫開發檔案), 與 dpkg-dev (Debian 開發輔助工具); 而 wget 則用來下載原始碼. 

pi@raspberrypi:~ $ sudo apt install -y build-essential wget   
正在讀取套件清單... 完成
正在重建相依關係... 完成  
正在讀取狀態資料... 完成  
build-essential is already the newest version (12.9).
wget is already the newest version (1.21.3-1+deb12u1).
wget 被設定為手動安裝。
升級 0 個,新安裝 0 個,移除 0 個,有 35 個未被升級。

切到 /usr/local/src 下載原始碼 (apt 下載的是放在 /usr/src) : 

pi@raspberrypi:~ $ cd /usr/local/src
pi@raspberrypi:/usr/local/src $ sudo wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
--2025-11-12 09:52:52--  http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
正在查找主機 prdownloads.sourceforge.net (prdownloads.sourceforge.net)... 104.18.12.149, 104.18.13.149, 2606:4700::6812:d95, ...
正在連接 prdownloads.sourceforge.net (prdownloads.sourceforge.net)|104.18.12.149|:80... 連上了。
已送出 HTTP 要求,正在等候回應... 301 Moved Permanently
位置: http://downloads.sourceforge.net/project/ta-lib/ta-lib/0.4.0/ta-lib-0.4.0-src.tar.gz [跟隨至新的 URL]
--2025-11-12 09:52:53--  http://downloads.sourceforge.net/project/ta-lib/ta-lib/0.4.0/ta-lib-0.4.0-src.tar.gz
正在查找主機 downloads.sourceforge.net (downloads.sourceforge.net)... 104.18.13.149, 104.18.12.149, 2606:4700::6812:c95, ...
繼續使用和 prdownloads.sourceforge.net:80 的連線。
已送出 HTTP 要求,正在等候回應... 302 Found
位置: http://zenlayer.dl.sourceforge.net/project/ta-lib/ta-lib/0.4.0/ta-lib-0.4.0-src.tar.gz?viasf=1 [跟隨至新的 URL]
--2025-11-12 09:52:53--  http://zenlayer.dl.sourceforge.net/project/ta-lib/ta-lib/0.4.0/ta-lib-0.4.0-src.tar.gz?viasf=1
正在查找主機 zenlayer.dl.sourceforge.net (zenlayer.dl.sourceforge.net)... 98.98.48.225
正在連接 zenlayer.dl.sourceforge.net (zenlayer.dl.sourceforge.net)|98.98.48.225|:80... 連上了。
已送出 HTTP 要求,正在等候回應... 200 OK
長度: 1330299 (1.3M) [application/x-gzip]
儲存到:「ta-lib-0.4.0-src.tar.gz」

ta-lib-0.4.0-src.tar.gz    100%[======================================>]   1.27M   550KB/s  於 2.4s      

2025-11-12 09:52:56 (550 KB/s) - 已儲存 「ta-lib-0.4.0-src.tar.gz」 [1330299/1330299]


3. 解壓縮原始碼 :  

用 tar 解壓縮 : 

pi@raspberrypi:/usr/local/src $ sudo tar -xvzf ta-lib-0.4.0-src.tar.gz
ta-lib/
ta-lib/config.sub
ta-lib/aclocal.m4
... (略) ...
ta-lib/src/tools/gen_code/Makefile.in
ta-lib/src/tools/gen_code/Makefile.am
ta-lib/src/tools/gen_code/mcpp.exe


4. 執行 configure 指令做 build 前準備 :  

切換到 ta-lib 目錄下 : 

pi@raspberrypi:/usr/local/src $ cd ta-lib   

執行 configure 指令, 並用 --prefix=/usr 參數指定 library 安裝到 /usr/lib, 方便系統與 Python 尋找. configure 會先檢查下列事項 :
  • C 編譯器例如 gcc 是否存在
  • 系統中有沒有必要的函式庫 (像 libm, libc, libpython 等)
  • 各種標頭檔 (如 math.h, stdlib.h)
  • 路徑權限與目錄是否正確
然後 configure 會依照系統的實際環境產生一個客製化的 Makefile 檔, 此檔會告訴 make 指令如何進行編譯 (例如要用哪些檔案, 參數, 編譯器等). 但是執行 configure 卻出現 Error :

pi@raspberrypi:/usr/local/src/ta-lib $ sudo ./configure --prefix=/usr   
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking build system type... ./config.guess: unable to guess system type

This script, last modified 2006-07-02, has failed to recognize
the operating system you are using. It is advised that you
download the most up to date version of the config scripts from

  http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.guess
and
  http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.sub

If the version you run (./config.guess) is already up to date, please
send the following data and any information you think might be
pertinent to <config-patches@gnu.org> in order to provide the needed
information to handle your system.

config.guess timestamp = 2006-07-02

uname -m = aarch64
uname -r = 6.12.47+rpt-rpi-v8
uname -s = Linux
uname -v = #1 SMP PREEMPT Debian 1:6.12.47-1+rpt1~bookworm (2025-09-16)

/usr/bin/uname -p = unknown
/bin/uname -X     = 

hostinfo               = 
/bin/universe          = 
/usr/bin/arch -k       = 
/bin/arch              = aarch64
/usr/bin/oslevel       = 
/usr/convex/getsysinfo = 

UNAME_MACHINE = aarch64
UNAME_RELEASE = 6.12.47+rpt-rpi-v8
UNAME_SYSTEM  = Linux
UNAME_VERSION = #1 SMP PREEMPT Debian 1:6.12.47-1+rpt1~bookworm (2025-09-16)
configure: error: cannot guess build type; you must specify one   

出現沒有指定 build type 錯誤, 問 ChatGPT 原因, 原來是 TA-Lib 原始碼裡的 configure 腳本太舊了, 它的 config.guess 是 2006 年的版本, 無法辨識 Raspberry Pi 400 + Bookworm (aarch64) 的系統類型, 解決辦法是更新 configure 的 config.guess 與 config.sub, 下載指令如下 : 

sudo wget -O config.guess  https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess 
sudo wget -O config.sub    https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub 

這樣會把舊的 2006 版本替換成可以辨識 aarch64 的最新版本 : 

pi@raspberrypi:/usr/local/src/ta-lib $ sudo wget -O config.guess  https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess  
--2025-11-12 10:11:50--  https://git.savannah.gnu.org/gitweb/?p=config.git
正在查找主機 git.savannah.gnu.org (git.savannah.gnu.org)... 209.51.188.168, 2001:470:142::168
正在連接 git.savannah.gnu.org (git.savannah.gnu.org)|209.51.188.168|:443... 連上了。
已送出 HTTP 要求,正在等候回應... 302 Moved Temporarily
位置: https://gitweb.git.savannah.gnu.org/gitweb/?p=config.git [跟隨至新的 URL]
--2025-11-12 10:11:52--  https://gitweb.git.savannah.gnu.org/gitweb/?p=config.git
正在查找主機 gitweb.git.savannah.gnu.org (gitweb.git.savannah.gnu.org)... 15.204.9.231, 38.102.85.135, 135.148.138.35, ...
正在連接 gitweb.git.savannah.gnu.org (gitweb.git.savannah.gnu.org)|15.204.9.231|:443... 連上了。
已送出 HTTP 要求,正在等候回應... 200 OK
長度: 未指定 [text/html]
儲存到:「config.guess」

config.guess                   [ <=>                                   ]  19.10K   117KB/s  於 0.2s      

2025-11-12 10:11:54 (117 KB/s) - 已儲存 「config.guess」 [19558]

pi@raspberrypi:/usr/local/src/ta-lib $ sudo wget -O config.sub    https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub  
--2025-11-12 10:12:31--  https://git.savannah.gnu.org/gitweb/?p=config.git
正在查找主機 git.savannah.gnu.org (git.savannah.gnu.org)... 209.51.188.168, 2001:470:142::168
正在連接 git.savannah.gnu.org (git.savannah.gnu.org)|209.51.188.168|:443... 連上了。
已送出 HTTP 要求,正在等候回應... 302 Moved Temporarily
位置: https://gitweb.git.savannah.gnu.org/gitweb/?p=config.git [跟隨至新的 URL]
--2025-11-12 10:12:32--  https://gitweb.git.savannah.gnu.org/gitweb/?p=config.git
正在查找主機 gitweb.git.savannah.gnu.org (gitweb.git.savannah.gnu.org)... 135.148.138.35, 38.102.85.135, 15.204.9.231, ...
正在連接 gitweb.git.savannah.gnu.org (gitweb.git.savannah.gnu.org)|135.148.138.35|:443... 連上了。
已送出 HTTP 要求,正在等候回應... 200 OK
長度: 未指定 [text/html]
儲存到:「config.sub」

config.sub                     [ <=>                                   ]  19.10K  --.-KB/s  於 0.002s    

2025-11-12 10:12:33 (11.6 MB/s) - 已儲存 「config.sub」 [19557]

然後將此兩檔案添加可執行權限 :

pi@raspberrypi:/usr/local/src/ta-lib $ sudo chmod +x config.guess config.sub

再次執行 configure 仍然出現錯誤 :

pi@raspberrypi:/usr/local/src/ta-lib $ sudo ./configure --prefix=/usr --build=aarch64-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
configure: error: cannot run /bin/bash ./config.sub  

我轉而詢問 Gemini, 它也是說 Ta-Lib 的原始碼發行版可能有點舊了, 它內附的 config.sub 和 config.guess 腳本可能無法正確識別新系統 (如 aarch64 上的 Bookworm), 建議我強制系統使用最新版的 autotools 腳本來重新產生 configure 文件 : 

pi@raspberrypi:/usr/local/src/ta-lib $ sudo apt-get update   
sudo apt-get install automake autoconf libtool  
已有:1 http://deb.debian.org/debian bookworm InRelease
已有:2 http://deb.debian.org/debian-security bookworm-security InRelease
下載:3 http://deb.debian.org/debian bookworm-updates InRelease [55.4 kB]
已有:4 http://archive.raspberrypi.com/debian bookworm InRelease
取得 55.4 kB 用了 2s (26.8 kB/s)
正在讀取套件清單... 完成
正在讀取套件清單... 完成
正在重建相依關係... 完成  
正在讀取狀態資料... 完成  
下列的額外套件將被安裝:
  autotools-dev libltdl-dev m4
建議套件:
  autoconf-archive gnu-standards autoconf-doc gettext libtool-doc gfortran | fortran95-compiler gcj-jdk
  m4-doc
下列【新】套件將會被安裝:
  autoconf automake autotools-dev libltdl-dev libtool m4
升級 0 個,新安裝 6 個,移除 0 個,有 35 個未被升級。
需要下載 2,165 kB 的套件檔。
此操作完成之後,會多佔用 7,044 kB 的磁碟空間。
是否繼續進行 [Y/n]? [Y/n] Y
下載:1 http://deb.debian.org/debian bookworm/main arm64 m4 arm64 1.4.19-3 [276 kB]
下載:2 http://deb.debian.org/debian bookworm/main arm64 autoconf all 2.71-3 [332 kB]
下載:3 http://deb.debian.org/debian bookworm/main arm64 autotools-dev all 20220109.1 [51.6 kB]
下載:4 http://deb.debian.org/debian bookworm/main arm64 automake all 1:1.16.5-1.3 [823 kB]
下載:5 http://deb.debian.org/debian bookworm/main arm64 libltdl-dev arm64 2.4.7-7~deb12u1 [165 kB]
下載:6 http://deb.debian.org/debian bookworm/main arm64 libtool all 2.4.7-7~deb12u1 [517 kB]
取得 2,165 kB 用了 1s (2,026 kB/s)
選取了原先未選的套件 m4。
(讀取資料庫 ... 目前共安裝了 130238 個檔案和目錄。)
正在準備解包 .../0-m4_1.4.19-3_arm64.deb……
Unpacking m4 (1.4.19-3) ...
選取了原先未選的套件 autoconf。
正在準備解包 .../1-autoconf_2.71-3_all.deb……
Unpacking autoconf (2.71-3) ...
選取了原先未選的套件 autotools-dev。
正在準備解包 .../2-autotools-dev_20220109.1_all.deb……
Unpacking autotools-dev (20220109.1) ...
選取了原先未選的套件 automake。
正在準備解包 .../3-automake_1%3a1.16.5-1.3_all.deb……
Unpacking automake (1:1.16.5-1.3) ...
選取了原先未選的套件 libltdl-dev:arm64。
正在準備解包 .../4-libltdl-dev_2.4.7-7~deb12u1_arm64.deb……
Unpacking libltdl-dev:arm64 (2.4.7-7~deb12u1) ...
選取了原先未選的套件 libtool。
正在準備解包 .../5-libtool_2.4.7-7~deb12u1_all.deb……
Unpacking libtool (2.4.7-7~deb12u1) ...
設定 m4 (1.4.19-3) ...
設定 autotools-dev (20220109.1) ...
設定 autoconf (2.71-3) ...
設定 automake (1:1.16.5-1.3) ...
update-alternatives: 在自動模式下以 /usr/bin/automake-1.16 來提供 /usr/bin/automake (automake)
設定 libtool (2.4.7-7~deb12u1) ...
設定 libltdl-dev:arm64 (2.4.7-7~deb12u1) ...
執行 man-db (2.11.2-2) 的觸發程式……

然後用下列指令強制重新產生 build 系統文件, 此指令會用系統上 (來自 automake 套件) 的最新 config.sub 等文件替換掉 Ta-Lib 原始碼中舊的腳本, 並重新產生 configure 腳本 : 

pi@raspberrypi:/usr/local/src/ta-lib $ autoreconf -fiv   
autoreconf: export WARNINGS=
autoreconf: warning: autoconf input should be named 'configure.ac', not 'configure.in'
autoreconf: Entering directory '.'
autoreconf: configure.in: not using Gettext
autoreconf: running: aclocal --force 
aclocal: warning: autoconf input should be named 'configure.ac', not 'configure.in'
autoreconf: configure.in: tracing
autoreconf: running: libtoolize --copy --force
libtoolize: putting auxiliary files in '.'.
libtoolize: copying file './ltmain.sh'
libtoolize: Consider adding 'AC_CONFIG_MACRO_DIRS([m4])' to configure.in,
libtoolize: and rerunning libtoolize and aclocal.
libtoolize: Consider adding '-I m4' to ACLOCAL_AMFLAGS in Makefile.am.
autoreconf: configure.in: not using Intltool
autoreconf: configure.in: not using Gtkdoc
autoreconf: running: aclocal --force 
aclocal: warning: autoconf input should be named 'configure.ac', not 'configure.in'
autoreconf: running: /usr/bin/autoconf --force
configure.in:8: warning: The macro `AC_CONFIG_HEADER' is obsolete.
configure.in:8: You should run autoupdate.
./lib/autoconf/status.m4:719: AC_CONFIG_HEADER is expanded from...
configure.in:8: the top level
configure.in:9: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated.
./lib/autoconf/general.m4:2434: AC_DIAGNOSE is expanded from...
aclocal.m4:9517: AM_INIT_AUTOMAKE is expanded from...
configure.in:9: the top level
configure.in:13: warning: The macro `AC_PROG_LIBTOOL' is obsolete.
configure.in:13: You should run autoupdate.
aclocal.m4:122: AC_PROG_LIBTOOL is expanded from...
configure.in:13: the top level
configure.in:20: warning: The macro `AC_HEADER_STDC' is obsolete.
configure.in:20: You should run autoupdate.
./lib/autoconf/headers.m4:704: AC_HEADER_STDC is expanded from...
configure.in:20: the top level
configure.in:31: warning: The macro `AC_TYPE_SIGNAL' is obsolete.
configure.in:31: You should run autoupdate.
./lib/autoconf/types.m4:776: AC_TYPE_SIGNAL is expanded from...
configure.in:31: the top level
autoreconf: running: /usr/bin/autoheader --force
autoheader: warning: autoconf input should be named 'configure.ac', not 'configure.in'
autoreconf: running: automake --add-missing --copy --force-missing
automake: warning: autoconf input should be named 'configure.ac', not 'configure.in'
configure.in:9: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated.  For more info, see:
configure.in:9: https://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
configure.in:12: installing './compile'
configure.in:9: installing './missing'
automake: warning: autoconf input should be named 'configure.ac', not 'configure.in'
src/ta_abstract/Makefile.am:4: warning: source file 'frames/ta_frame.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
automake: warning: possible forward-incompatibility.
automake: At least one source file is in a subdirectory, but the 'subdir-objects'
automake: automake option hasn't been enabled.  For now, the corresponding output
automake: object file(s) will be placed in the top-level directory.  However, this
automake: behavior may change in a future Automake major version, with object
automake: files being placed in the same subdirectory as the corresponding sources.
automake: You are advised to start using 'subdir-objects' option throughout your
automake: project, to avoid future incompatibilities.
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_a.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_b.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_c.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_d.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_e.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_f.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_g.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_h.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_i.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_j.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_k.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_l.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_m.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_n.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_o.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_p.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_q.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_r.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_s.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_t.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_u.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_v.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_w.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_x.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_y.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am:4: warning: source file 'tables/table_z.c' is in a subdirectory,
src/ta_abstract/Makefile.am:4: but option 'subdir-objects' is disabled
src/ta_abstract/Makefile.am: installing './depcomp'
src/tools/ta_regtest/Makefile.am:6: warning: source file 'ta_test_func/test_adx.c' is in a subdirectory,
src/tools/ta_regtest/Makefile.am:6: but option 'subdir-objects' is disabled
src/tools/ta_regtest/Makefile.am:6: warning: source file 'ta_test_func/test_mom.c' is in a subdirectory,
src/tools/ta_regtest/Makefile.am:6: but option 'subdir-objects' is disabled
src/tools/ta_regtest/Makefile.am:6: warning: source file 'ta_test_func/test_sar.c' is in a subdirectory,
src/tools/ta_regtest/Makefile.am:6: but option 'subdir-objects' is disabled
src/tools/ta_regtest/Makefile.am:6: warning: source file 'ta_test_func/test_rsi.c' is in a subdirectory,
src/tools/ta_regtest/Makefile.am:6: but option 'subdir-objects' is disabled
src/tools/ta_regtest/Makefile.am:6: warning: source file 'ta_test_func/test_candlestick.c' is in a subdirectory,
src/tools/ta_regtest/Makefile.am:6: but option 'subdir-objects' is disabled
src/tools/ta_regtest/Makefile.am:6: warning: source file 'ta_test_func/test_per_ema.c' is in a subdirectory,
src/tools/ta_regtest/Makefile.am:6: but option 'subdir-objects' is disabled
src/tools/ta_regtest/Makefile.am:6: warning: source file 'ta_test_func/test_per_hlc.c' is in a subdirectory,
src/tools/ta_regtest/Makefile.am:6: but option 'subdir-objects' is disabled
src/tools/ta_regtest/Makefile.am:6: warning: source file 'ta_test_func/test_stoch.c' is in a subdirectory,
src/tools/ta_regtest/Makefile.am:6: but option 'subdir-objects' is disabled
src/tools/ta_regtest/Makefile.am:6: warning: source file 'ta_test_func/test_macd.c' is in a subdirectory,
src/tools/ta_regtest/Makefile.am:6: but option 'subdir-objects' is disabled
src/tools/ta_regtest/Makefile.am:6: warning: source file 'ta_test_func/test_minmax.c' is in a subdirectory,
src/tools/ta_regtest/Makefile.am:6: but option 'subdir-objects' is disabled
src/tools/ta_regtest/Makefile.am:6: warning: source file 'ta_test_func/test_per_hlcv.c' is in a subdirectory,
src/tools/ta_regtest/Makefile.am:6: but option 'subdir-objects' is disabled
src/tools/ta_regtest/Makefile.am:6: warning: source file 'ta_test_func/test_1in_1out.c' is in a subdirectory,
src/tools/ta_regtest/Makefile.am:6: but option 'subdir-objects' is disabled
src/tools/ta_regtest/Makefile.am:6: warning: source file 'ta_test_func/test_1in_2out.c' is in a subdirectory,
src/tools/ta_regtest/Makefile.am:6: but option 'subdir-objects' is disabled
src/tools/ta_regtest/Makefile.am:6: warning: source file 'ta_test_func/test_per_ohlc.c' is in a subdirectory,
src/tools/ta_regtest/Makefile.am:6: but option 'subdir-objects' is disabled
src/tools/ta_regtest/Makefile.am:6: warning: source file 'ta_test_func/test_stddev.c' is in a subdirectory,
src/tools/ta_regtest/Makefile.am:6: but option 'subdir-objects' is disabled
src/tools/ta_regtest/Makefile.am:6: warning: source file 'ta_test_func/test_bbands.c' is in a subdirectory,
src/tools/ta_regtest/Makefile.am:6: but option 'subdir-objects' is disabled
src/tools/ta_regtest/Makefile.am:6: warning: source file 'ta_test_func/test_ma.c' is in a subdirectory,
src/tools/ta_regtest/Makefile.am:6: but option 'subdir-objects' is disabled
src/tools/ta_regtest/Makefile.am:6: warning: source file 'ta_test_func/test_po.c' is in a subdirectory,
src/tools/ta_regtest/Makefile.am:6: but option 'subdir-objects' is disabled
src/tools/ta_regtest/Makefile.am:6: warning: source file 'ta_test_func/test_per_hl.c' is in a subdirectory,
src/tools/ta_regtest/Makefile.am:6: but option 'subdir-objects' is disabled
src/tools/ta_regtest/Makefile.am:6: warning: source file 'ta_test_func/test_trange.c' is in a subdirectory,
src/tools/ta_regtest/Makefile.am:6: but option 'subdir-objects' is disabled
autoreconf: Leaving directory '.'

這樣再次執行 configure 就不會出現錯誤, 順利完成 Build 前之準備了 : 

pi@raspberrypi:/usr/local/src/ta-lib $ ./configure --prefix=/usr    
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a race-free mkdir -p... /usr/bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... none needed
checking whether gcc understands -c and -o together... yes
checking whether make supports the include directive... yes (GNU style)
checking dependency style of gcc... gcc3
checking build system type... aarch64-unknown-linux-gnu
checking host system type... aarch64-unknown-linux-gnu
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert aarch64-unknown-linux-gnu file names to aarch64-unknown-linux-gnu format... func_convert_file_noop
checking how to convert aarch64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for file... file
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking for dlopen in -ldl... yes
checking for pthread_create in -lpthread... yes
checking for egrep... (cached) /usr/bin/grep -E
checking for float.h... yes
checking for inttypes.h... (cached) yes
checking for limits.h... yes
checking for locale.h... yes
checking for stddef.h... yes
checking for stdint.h... (cached) yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking for unistd.h... (cached) yes
checking for wchar.h... yes
checking for wctype.h... yes
checking for an ANSI C-conforming const... yes
checking for size_t... yes
checking whether struct tm is in sys/time.h or time.h... time.h
checking for working volatile... yes
checking for ptrdiff_t... yes
checking return type of signal handlers... void
checking for working strcoll... yes
checking for strftime... yes
checking for working strtod... yes
checking for vprintf... yes
checking for floor... no
checking for isascii... yes
checking for localeconv... yes
checking for mblen... yes
checking for memmove... yes
checking for memset... yes
checking for modf... yes
checking for pow... no
checking for sqrt... no
checking for strcasecmp... yes
checking for strchr... yes
checking for strerror... yes
checking for strncasecmp... yes
checking for strrchr... yes
checking for strstr... yes
checking for strtol... yes
checking for strtoul... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating src/ta_abstract/Makefile
config.status: creating src/ta_common/Makefile
config.status: creating src/ta_func/Makefile
config.status: creating src/tools/Makefile
config.status: creating src/tools/gen_code/Makefile
config.status: creating src/tools/ta_regtest/Makefile
config.status: creating ta-lib-config
config.status: creating ta-lib.spec
config.status: creating ta-lib.dpkg
config.status: creating include/ta_config.h
config.status: executing depfiles commands
config.status: executing libtool commands


5. 用 make 進行編譯 :  

接下來就可以用 make 進行編譯了 (編譯過程很長, 從略) :

pi@raspberrypi:/usr/local/src/ta-lib $ make  
pi@raspberrypi:/usr/local/src/ta-lib $ sudo make install 

... (略) ...


6. 用 pip 安裝 ta-lib :  

編譯完成後進虛擬環境, 用 pip install ta-lib 安裝 Ta-Lib 套件 (這是外殼) :

pi@raspberrypi:/usr/local/src/ta-lib $ cd ~  
pi@raspberrypi:~ $ source ~/myenv/bin/activate  
(myenv) pi@raspberrypi:~ $ pip install ta-lib  
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting ta-lib
  Downloading ta_lib-0.6.8-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (4.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.0/4.0 MB 2.2 MB/s eta 0:00:00
Collecting build
  Downloading https://www.piwheels.org/simple/build/build-1.3.0-py3-none-any.whl (23 kB)
Requirement already satisfied: numpy in ./myenv/lib/python3.11/site-packages (from ta-lib) (1.26.4)
Requirement already satisfied: packaging>=19.1 in ./myenv/lib/python3.11/site-packages (from build->ta-lib) (25.0)
Collecting pyproject_hooks
  Downloading https://www.piwheels.org/simple/pyproject-hooks/pyproject_hooks-1.2.0-py3-none-any.whl (10 kB)
Installing collected packages: pyproject_hooks, build, ta-lib
Successfully installed build-1.3.0 pyproject_hooks-1.2.0 ta-lib-0.6.8

但是, 安裝好後匯入 talib 卻失敗 :

Python 3.11.2 (/usr/bin/python3)
>>> import talib   
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'talib'

明明編譯安裝都成功了, 卻無法匯入, 向 ChatGPT 與 Gemini 詢問原因與解決方案都失敗, 都有提到 Ta-Lib 太老舊, 最後只好放棄. 

清除以上編譯與安裝過程之檔案 :

pi@raspberrypi:~ $ sudo rm -rf /usr/local/src/ta-lib  
pi@raspberrypi:~ $ sudo rm -f /usr/local/lib/libta_lib.*  
pi@raspberrypi:~ $ sudo rm -rf /usr/local/include/ta-lib  
pi@raspberrypi:~ $ source ~/myenv/bin/activate  
(myenv) pi@raspberrypi:~ $ pip uninstall -y ta-lib  
... (略) ...
(myenv) pi@raspberrypi:~ $ deactivate 

用下列指令搜尋是否還有 ta-lib 相關檔案, 有的話刪除 : 

pi@raspberrypi:~ $ find /usr/local -name "*ta-lib*" 2>/dev/null   
/usr/local/src/ta-lib-0.4.0-src.tar.gz.2
/usr/local/src/ta-lib-0.4.0-src.tar.gz.1
/usr/local/src/ta-lib-0.4.0-src.tar.gz
pi@raspberrypi:~ $ sudo rm -f /usr/local/src/ta-lib-0.4.0-src.tar.gz.2  
pi@raspberrypi:~ $ sudo rm -f /usr/local/src/ta-lib-0.4.0-src.tar.gz.1  
pi@raspberrypi:~ $ sudo rm -f /usr/local/src/ta-lib-0.4.0-src.tar.gz   

清除 apt 系統暫存 :

pi@raspberrypi:~ $ sudo apt autoremove  
正在讀取套件清單... 完成
正在重建相依關係... 完成  
正在讀取狀態資料... 完成  
升級 0 個,新安裝 0 個,移除 0 個,有 33 個未被升級。
pi@raspberrypi:~ $ sudo apt clean   

最後用下列指令清查與 ta-lib 相關之垃圾, 有的話刪除 :

pi@raspberrypi:~ $ sudo find /usr /usr/local /home -type f -o -type d 2>/dev/null | grep -i ta-lib   
/usr/include/ta-lib
/usr/include/ta-lib/ta_defs.h
/usr/include/ta-lib/ta_abstract.h
/usr/include/ta-lib/ta_func.h
/usr/include/ta-lib/ta_common.h
/usr/include/ta-lib/ta_libc.h
/usr/bin/ta-lib-config
pi@raspberrypi:~ $ sudo rm -rf /usr/include/ta-lib   
pi@raspberrypi:~ $ sudo rm -f /usr/bin/ta-lib-config  

為了這個老套件花了一天實在不值得. 

沒有留言 :