Brian Leishman
Brian Leishman

Reputation: 8555

GCC not linking RHash?

I have this working on my testing environment, but I guess I can't figure out how I did it. Basically, I'm trying to compile a MySQL UDF that uses functions from RHash, but I'm getting this from the MySQL server

Error Code: 1126. Can't open shared library 'sha3.so' (errno: 0 /usr/lib/mysql/plugin/sha3.so: undefined symbol: rhash_msg)

On the server I've run these

apt install rhash librhash-dev

And I've even downloaded the source (only because it wasn't yet working) from https://github.com/rhash/RHash and run

./configure
make test
make install

Which doesn't seem to give me any errors, and then I compile with

gcc -I/usr/include/mysql -lrhash -o sha3.so -shared sha3.c -fPIC

Which ALSO doesn't give any errors, but then I get that MySQL error when running

create function`sha3`returns string soname'sha3.so';

What step am I doing wrong here?

Just in case, my source is here https://gist.github.com/BrianLeishman/a0f40e7a0a87a7069c5c56a768ff3179


I've seen this answer What is an undefined reference/unresolved external symbol error and how do I fix it?, but I'm pretty sure I already have the order of arguments set correctly, but maybe I'm wrong, since all of their examples talk about setting the output before the link, which is definitely not what I'm doing here.

Upvotes: 0

Views: 127

Answers (1)

Brian Leishman
Brian Leishman

Reputation: 8555

The suggested question that this is a duplicate of might be a tad too technical for someone starting out with GCC and C/C++, so while it might TECHNICALLY be a duplicate, I'd like this question/answer to stay here for people in the same spot as me.

Basically, certain versions of linux do the steps to compile differently from each other, so

gcc -I/usr/include/mysql -lrhash -o sha3.so -shared sha3.c -fPIC

might work depending on the OS and version, but to make sure this works on everything, move the -lrhash after the sha3.c (in this case) like

gcc -I/usr/include/mysql -o sha3.so -shared sha3.c -lrhash -fPIC

Upvotes: 0

Related Questions