简体   繁体   English

为ZooKeeper编译C ++客户端时获取未定义的引用

[英]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. 我尝试用C ++编译我的第一个程序,在该程序中,我尝试连接到ZooKeeper并执行其他操作。 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: 但是,当我编译这个test.cpp文件时(实际上,我提供了zookeeper /.../ build / usr / lib的链接以及所有包含文件的路径),我得到了以下错误消息的列表:

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. 您最有可能忘了再链接一次 Zookeeper。 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. 通常, 构建系统的工作就是为您解决这些问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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