I'm trying to create a UDF function for MySQL (a C function executable by MySQL), and I'm running into issues left and right. I'm just going straight into giving you code. I have a file levenshtein.c which includes the following declarations and corresponding implementations:
my_bool sql_levenshtein_init(UDF_INIT *initid, UDF_ARGS *args, char *message);
void sql_levenshtein_deinit(UDF_INIT *initid);
longlong sql_levenshtein(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error);
I compile the file (against std=c99 and for arch=i386, if that's relevant). I copy the created .so file into my mysql plugin folder. I go into mysql and execute the command
mysql> create function sql_levenshtein returns int soname 'levenshtein.so';
Instead of this command successfully creating the function, I receive this error
ERROR 1127 (HY000): Can't find symbol 'sql_levenshtein' in library
In trying to solve the issue, I didn't come up with much useful info. After googling around, I used the command nm to look at the .so file. And I got this output:
00001600 t ___inline_memset_chk
00001870 t ___inline_strcpy_chk
U ___memset_chk
U ___stack_chk_fail
U ___stack_chk_guard
U ___strcpy_chk
00001220 T _cell_value
U _free
00001180 T _is_levenshtein_within_normthresh
00001100 T _is_levenshtein_within_thresh
00001460 T _levenshtein
00000cf0 T _levenshtein_k
U _malloc
00001400 t _minimum
00001660 T _normlevenshtein
000018f0 T _sql_levenshtein
000018c0 T _sql_levenshtein_deinit
00001710 T _sql_levenshtein_init
00001df0 T _sql_levenshtein_within_normthreshold
00001dd0 T _sql_levenshtein_within_normthreshold_deinit
00001d00 T _sql_levenshtein_within_normthreshold_init
00001c00 T _sql_normlevenshtein
00001be0 T _sql_normlevenshtein_deinit
00001b20 T _sql_normlevenshtein_init
U dyld_stub_binder
Note _sql_levenshtein, so it seems like the function exists. Not sure what else would be helpful. Thanks for your guidance!
Kurt
========= Update in response to comment: Well, for what it's worth, I also did
mysql> create function _sql_levenshtein returns int soname 'levenshtein.so';
ERROR 1127 (HY000): Can't find symbol '_sql_levenshtein' in library
So it doesn't seem like that is the root cause of the issue. Maybe I'm missing something.
sql_levenshteinand_sql_levenshteinare not the same symbol.show variables like '%plu%'gives/usr/local/mysql/lib/mysql/plugin, andls /usr/local/mysql/lib/mysql/plugin | grep levengiveslevenshtein.so.