UDF (User Defined Function) defined by SQL1999
UDFはSQL1999により定義されたSQL99の標準機能なわけでして,これをMySQLに作って使ってみようとしていたら・・・.
mysql> CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "udf_example.so"; ERROR 1126 (HY000): Can't open shared library 'udf_example.so' (errno: 22 /usr/lib/udf_example.so: undefined symbol: __gxx_personality_v0) mysql>
ううむ.なぜだろう.
追記
MySQL 4.1.16で以下のように2段階で共有オブジェクトを作ったら上手くいった.なぜかは知らない.
shell> g++ -I "/usr/local/mysql/include" -c -o udf_example.o udf_example.cc shell> gcc -o udf_example.so -shared udf_example.o
インストール,呼び出し,アンインストールOK
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 to server version: 4.1.16-max Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> create function metaphon returns string soname "udf_example.so"; Query OK, 0 rows affected (0.00 sec) mysql> select metaphon("hoge"); +------------------+ | metaphon("hoge") | +------------------+ | HJ | +------------------+ 1 row in set (0.00 sec) mysql> drop function metaphon; Query OK, 0 rows affected (0.00 sec) mysql>
もっかいMySQL 5.0系でトライしてみる.
やってみた.
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 to server version: 5.0.18-max Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> create function metaphon returns string soname "udf_example.so"; ERROR 1126 (HY000): Can't open shared library 'udf_example.so' (errno: 2 /usr/lib/udf_example.so: undefin ed symbol: __gxx_personality_v0) mysql> create function metaphon returns string soname "udf_example.so"; ERROR 1126 (HY000): Can't open shared library 'udf_example.so' (errno: 22 /usr/lib/udf_example.so: undefi ned symbol: __gxx_personality_v0) mysql> create function metaphon returns string soname "udf_example.so"; ERROR 1126 (HY000): Can't open shared library 'udf_example.so' (errno: 22 /usr/lib/udf_example.so: undefi ned symbol: __gxx_personality_v0) mysql>
やっぱ"undefined symbol"エラー.しかも謎なのがerrnoが1回目の試行だと"2"なのに2回目以降は"22"となる点.
さらに追記:
shell> g++ -I "/usr/local/mysql/include" -c -o udf_example.o udf_example.cc shell> g++ -o udf_example.so -shared udf_example.o
こっちが正解だ.これで4.1系も5.0系もどちらもいく.gccじゃなくてg++と明記すること,2段階でやること.