Creating C++ Redis Module - "does not export RedisModule_OnLoad() symbol"

87 views
Skip to first unread message

Sidd S

unread,
May 17, 2018, 11:19:24 AM5/17/18
to Redis DB
I am having some trouble loading my Redis module. I am just copying the example from https://redis.io/topics/modules-intro, but I stripped it down.

#include "redismodule.h"
#include <stdlib.h>

int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
   
if (RedisModule_Init(ctx,"helloworld",1,REDISMODULE_APIVER_1)
       
== REDISMODULE_ERR) return REDISMODULE_ERR;


   
return REDISMODULE_OK;
}

This is saved in avromodules.cpp. I compile it using the following:

g++ -shared -fPIC -o avromodule.so avromodule.cpp

 Then I go over to the Redis CLI and try to load the module.

10.XXX.XXX.XXX:7004> module load /path/to/module/avromodule.so
(error) ERR Error loading the extension. Please check the server logs.

The server logs give me the following error:

159392:M 17 May 10:21:19.773 # Module /path/to/module/avromodule.so does not export RedisModule_OnLoad() symbol. Module not loaded.

The above error makes no sense to me, because I get the following output using the 'nm' command:

$ nm -CD avromodule.so | grep " T "
0000000000003622 T RedisModule_OnLoad(RedisModuleCtx*, RedisModuleString**, int)
000000000000366c T _fini
0000000000002878 T _init

Does anyone have a clue what could be going wrong here? I know that I am using C++ as opposed to the recommended C, but this should still work AFAIK.

Hampus Wessman

unread,
May 22, 2018, 1:29:43 PM5/22/18
to redi...@googlegroups.com

Hi Sidd,

Have a look at this about mixing C and C++: https://isocpp.org/wiki/faq/mixing-c-and-cpp#call-cpp

In short, add extern "C" to your functions in C++ to make them callable from C. It tells the compiler to make it compatible, which it generally won't be otherwise. I'm guessing that nm simply supports both C and C++ and won't tell you about the differences.

BR,
Hampus

hva...@gmail.com

unread,
May 22, 2018, 1:34:26 PM5/22/18
to Redis DB
My suggestion is centered around the example code you modified, and after modifying it, encountered a fundamental problem (Redis complains there's a reference to a function/method call it can't find):  Try using the example code unmodified and see if you can successfully build it as a module and have Redis load it.

If that works, you can perform your modifications, one at a time, to see which one produces the error.  From there it will probably be clearer what's missing and how to fix it.
Reply all
Reply to author
Forward
0 new messages