Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create function after compiling library: Error: Can't find symbol 'levenshtein' in library #12

Closed
sdragnev opened this issue Apr 25, 2018 · 8 comments

Comments

@sdragnev
Copy link

sdragnev commented Apr 25, 2018

I'm trying to compile and install the library for MariaDB 10.2 but the compiled .so file appears to be missing the required symbols.
Compiling the source file appears to go through fine except for some warnings:

$ gcc -o levenshtein.so -shared levenshtein.c -fPIC `mysql_config --include`
In file included from levenshtein.c:54:0:
/usr/include/mysql/my_global.h:3:2: warning: #warning This file should not be included by clients, include only <mysql.h> [-Wcpp]
 #warning This file should not be included by clients, include only <mysql.h>
  ^
In file included from levenshtein.c:55:0:
/usr/include/mysql/my_sys.h:3:2: warning: #warning This file should not be included by clients, include only <mysql.h> [-Wcpp]
 #warning This file should not be included by clients, include only <mysql.h>
  ^

However after copying the file to the mysql plugin directory and trying to create the function with:
CREATE FUNCTION levenshtein RETURNS INT SONAME 'levenshtein.so';
I get the following error: Error: Can't find symbol 'levenshtein' in library

The library is compiled fine (it seems) and mariadb can search it but there is no sign of the levenshtein symbol.
Running nm levenshtein.so also makes no mention of any of the functions:

$ nm levenshtein.so 
0000000000201028 B __bss_start
0000000000201028 b completed.6354
                 w __cxa_finalize@@GLIBC_2.2.5
0000000000000530 t deregister_tm_clones
00000000000005a0 t __do_global_dtors_aux
0000000000200e00 t __do_global_dtors_aux_fini_array_entry
0000000000200e10 d __dso_handle
0000000000200e18 d _DYNAMIC
0000000000201028 D _edata
0000000000201030 B _end
0000000000000618 T _fini
00000000000005e0 t frame_dummy
0000000000200df8 t __frame_dummy_init_array_entry
0000000000000628 r __FRAME_END__
0000000000201000 d _GLOBAL_OFFSET_TABLE_
                 w __gmon_start__
00000000000004e0 T _init
                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
0000000000200e08 d __JCR_END__
0000000000200e08 d __JCR_LIST__
                 w _Jv_RegisterClasses
0000000000000560 t register_tm_clones
0000000000201028 d __TMC_END__

Thoughts and prayers?
Thanks!

@sdragnev
Copy link
Author

Okay, I figured it out - the suggested gcc line wasn't including the correct header files.
mysql_config --include resulted in -I/usr/include/mysql -I/usr/include/mysql/mysql
when in fact I needed -I/usr/include/mysql/server

/usr/include/mysql/my_sys.h and /usr/include/mysql/my_global.h were empty which resulted in #ifdef HAVE_DLOPEN evaluating to FALSE and none of the functions were actually getting compiled.

Score!
This is on CentOS 7 btw (with MariaDB 10.2), in case someone else runs into this.

@juanmirocks
Copy link
Owner

@sdragnev thank you for the report and for the own solution! It will be helpful to other users; I highly appreciate your detailed documentation !

@PandyLegend
Copy link

I am running in to the same issue. I ran the line
gcc -o levenshtein.so -shared levenshtein.c -fPIC -I/usr/include/mysql -I/usr/include/mysql/server -I/usr/include/mysql/mysql
but still get the Error: Can't find symbol 'levenshtein' in library

I too am running Centos 7 and MariaDB 10.2
@sdragnev @juanmirocks Any suggestions?

@sdragnev
Copy link
Author

sdragnev commented May 27, 2020

@PandyLegend two things:

  1. Make sure /usr/include/mysql/server exists and is not empty
  2. IIRC, you have to only include /usr/include/mysql/server, not all three directories you are quoting
    Looking at my solution, the issue is in /usr/include/mysql to begin with so you probably shouldn't be including it.

@SamuelBenard
Copy link

Compiling was not generating levenshtein functions too. thank to your messages, i found why.
My compile command on mint 20/mariadb 10.3 :
gcc -o levenshtein.so -shared levenshtein.c -I/usr/include/mariadb/server/private -I/usr/include/mariadb/server -fPIC

@ilbuonmarcio
Copy link

Compiling was not generating levenshtein functions too. thank to your messages, i found why.
My compile command on mint 20/mariadb 10.3 :
gcc -o levenshtein.so -shared levenshtein.c -I/usr/include/mariadb/server/private -I/usr/include/mariadb/server -fPIC

It works for me too in Arch Linux as of today, just replacing mariadb with mysql, thanks guys!

@jkumar88
Copy link

Hi
I have run this command the levenshtein.so file created.

gcc -o levenshtein.so -shared levenshtein.c mysql_config --include

after that when run

CREATE FUNCTION levenshtein RETURNS INT SONAME 'levenshtein.so'
getting error
Can't find symbol 'levenshtein' in library
Please provide any solution.

Thanks In Advance

@waldorllc
Copy link

I've tried all the options here and from the Internet, including all possible directories. Still have the error #1127 - Can't find symbol 'levenshtein' in library on create function. Tried to compile for both macOS and Ubuntu. Same result. Could you help, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants