简体   繁体   中英

Get undefined reference when compiling C++ client for ZooKeeper

I try to compile my very first program in C++ in which I try to connect to ZooKeeper and do some other stuff. In my code I have these lines:

//test.cpp

#include "zookeeper.h"
... all other header files from zookeeper/include

void main_watcher (zhandle_t *zkh,
               int type,
               int state,
               const char *path,
               void* context)
{
    if(type == ZOO_SESSION_EVENT){
        if(state == ZOO_CONNECTED_STATE){
           ...
        }
        ...
    }
}

int main(){
   return 0;
}

But when I compile this test.cpp file (indeed, I provide link to the zookeeper/.../build/usr/lib and path to all included files), I get a list of these error messages:

undefined reference to ZOO_SESSION_EVENT
undefined reference to ZOO_CONNECTED_STATE
...

What am I doing wrong?

You're forgetting to link agains zookeeper, most probably. Typically, you'd have to do something like

g++ -lzookeper -o yourprogram yourprogram.c

maybe it's

-lzookeeper-mt

maybe not. Usually, it's job of a build system to figure these things out for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM