我是zeromq的新手。安装zeromq-4.1.3后,我只是按照以下方式从“http://zguide.zeromq.org/page:all”运行C中的“Hello World”示例:
gcc -c hwclient.c
g++ -o client hwclient.o -lzmq
但它似乎有许多“未定义的引用”:(很抱歉,我没有足够的代表来上传截图)
// usr / local / lib / libzmq.a(libzmq_la-pipe.o):在函数
zmq::mutex_t::try_lock()': /usr/software/zeromq-4.1.3/src/mutex.hpp:114: undefined reference to
pthread_mutex_trylock'中 //usr/local/lib/libzmq.a(libzmq_la-ctx.o):在函数zmq::ctx_t::~ctx_t()': /usr/software/zeromq-4.1.3/src/ctx.cpp:117: undefined reference to
randombytes_close'中 //usr/local/lib/libzmq.a(libzmq_la-thread.o):在函数thread_routine': /usr/software/zeromq-4.1.3/src/thread.cpp:91: undefined reference to
pthread_sigmask'中 //usr/local/lib/libzmq.a(libzmq_la-thread.o):在函数zmq::thread_t::start(void (*)(void*), void*)': /usr/software/zeromq-4.1.3/src/thread.cpp:105: undefined reference to
pthread_create'中 //usr/local/lib/libzmq.a(libzmq_la-thread.o):在函数zmq::thread_t::stop()': /usr/software/zeromq-4.1.3/src/thread.cpp:111: undefined reference to
pthread_join'中 //usr/local/lib/libzmq.a(libzmq_la-zmq_utils.o):在函数zmq_curve_keypair': /usr/software/zeromq-4.1.3/src/zmq_utils.cpp:202: undefined reference to
crypto_box_keypair'中 //usr/local/lib/libzmq.a(libzmq_la-curve_client.o):在函数zmq::curve_client_t::encode(zmq::msg_t*)': /usr/software/zeromq-4.1.3/src/curve_client.cpp:151: undefined reference to
crypto_box_afternm'中 //usr/local/lib/libzmq.a(libzmq_la-curve_client.o):在函数zmq::curve_client_t::decode(zmq::msg_t*)': /usr/software/zeromq-4.1.3/src/curve_client.cpp:214: undefined reference to
中crypto_box_open_afternm' //usr/local/lib/libzmq.a(libzmq_la-curve_client.o):在函数zmq::curve_client_t::curve_client_t(zmq::options_t const&)': /usr/software/zeromq-4.1.3/src/curve_client.cpp:61: undefined reference to
sodium_init'中 /usr/software/zeromq-4.1.3/src/curve_client.cpp:65:对crypto_box_keypair' //usr/local/lib/libzmq.a(libzmq_la-curve_client.o): In function
zmq :: curve_client_t :: produce_hello(zmq :: msg_t *)'的未定义引用: /usr/software/zeromq-4.1.3/src/curve_client.cpp:265:未定义引用crypto_box' //usr/local/lib/libzmq.a(libzmq_la-curve_client.o): In function
zmq :: curve_client_t :: process_welcome(unsigned char const *,unsigned long)': /usr/software/zeromq-4.1.3/src/curve_client.cpp:310:对crypto_box_open' /usr/software/zeromq-4.1.3/src/curve_client.cpp:320: undefined reference to
crypto_box_beforenm'的未定义引用 //usr/local/lib/libzmq.a(libzmq_la-curve_client.o):在函数zmq::curve_client_t::produce_initiate(zmq::msg_t*)': /usr/software/zeromq-4.1.3/src/curve_client.cpp:340: undefined reference to
randombytes'中 /usr/software/zeromq-4.1.3/src/curve_client.cpp:344:对crypto_box' /usr/software/zeromq-4.1.3/src/curve_client.cpp:380: undefined reference to
crypto_box'的未定义引用 //usr/local/lib/libzmq.a(libzmq_la-curve_client.o):在函数zmq::curve_client_t::process_ready(unsigned char const*, unsigned long)': /usr/software/zeromq-4.1.3/src/curve_client.cpp:424: undefined reference to
中crypto_box_open_afternm' //usr/local/lib/libzmq.a(libzmq_la-curve_server.o):在函数zmq::curve_server_t::encode(zmq::msg_t*)': /usr/software/zeromq-4.1.3/src/curve_server.cpp:157: undefined reference to
crypto_box_afternm'中 //usr/local/lib/libzmq.a(libzmq_la-curve_server.o):在函数zmq::curve_server_t::decode(zmq::msg_t*)': /usr/software/zeromq-4.1.3/src/curve_server.cpp:223: undefined reference to
crypto_box_open_afternm'中 //usr/local/lib/libzmq.a(libzmq_la-curve_server.o):在函数zmq::curve_server_t::curve_server_t(zmq::session_base_t*, std::string const&, zmq::options_t const&)': /usr/software/zeromq-4.1.3/src/curve_server.cpp:64: undefined reference to
sodium_init'中 /usr/software/zeromq-4.1.3/src/curve_server.cpp:68:对crypto_box_keypair' //usr/local/lib/libzmq.a(libzmq_la-curve_server.o): In function
zmq :: curve_server_t :: process_hello(zmq :: msg_t *)'的未定义引用: /usr/software/zeromq-4.1.3/src/curve_server.cpp:319:对crypto_box_open' //usr/local/lib/libzmq.a(libzmq_la-curve_server.o): In function
zmq :: curve_server_t :: produce_welcome(zmq :: msg_t *)'的未定义引用: /usr/software/zeromq-4.1.3/src/curve_server.cpp:340:对randombytes' /usr/software/zeromq-4.1.3/src/curve_server.cpp:350: undefined reference to
randombytes'的未定义引用 /usr/software/zeromq-4.1.3/src/curve_server.cpp:355:对crypto_secretbox' /usr/software/zeromq-4.1.3/src/curve_server.cpp:365: undefined reference to
randombytes'的未定义引用 /usr/software/zeromq-4.1.3/src/curve_server.cpp:377:对crypto_box' //usr/local/lib/libzmq.a(libzmq_la-curve_server.o): In function
zmq :: curve_server_t :: produce_ready(zmq :: msg_t *)'的未定义引用: /usr/software/zeromq-4.1.3/src/curve_server.cpp:547:对crypto_box_afternm' //usr/local/lib/libzmq.a(libzmq_la-curve_server.o): In function
zmq :: curve_server_t :: process_initiate(zmq :: msg_t *)'的未定义引用: /usr/software/zeromq-4.1.3/src/curve_server.cpp:421:对crypto_secretbox_open' /usr/software/zeromq-4.1.3/src/curve_server.cpp:454: undefined reference to
crypto_box_open'的未定义引用 /usr/software/zeromq-4.1.3/src/curve_server.cpp:479:对crypto_box_open' /usr/software/zeromq-4.1.3/src/curve_server.cpp:496: undefined reference to
crypto_box_beforenm'的未定义引用 collect2:错误:ld返回1退出状态
我也使用“How to build a project (say zeromq) as static library and linked it into my project”中的方法:
./configure --enable-static --disable-shared --prefix=/home/gsp/zeromqworkspace/test
g++ -o client hwclient.o /home/gsp/zeromqworkspace/test/libzmq.a
原来是:“g ++:error:/home/gsp/zeromqworkspace/test/libzmq.a:没有这样的文件或目录”。
我不知道该怎么办。我期待着你的回答。谢谢!
答案 0 :(得分:0)
pthread
函数应通过将-lpthread
开关添加到g++
语句来链接。
如果新的链接器开关出现未找到库的错误,请尝试sudo apt-get install libpthread-stubs0-dev
答案 1 :(得分:0)
当我运行:g ++ -o client zmqclient.o -I / usr / local / include -L / usr / local / lib -lzmq -lpthread时,结果更改为以下内容:
gsp @ gsp-Lenovo:〜/ zeromqworkspace / test $ g ++ -o client zmqclient.o -I / usr / local / include -L / usr / local / lib -lzmq -lpthread
/usr/local/lib/libzmq.a(libzmq_la-ctx.o):在函数zmq::ctx_t::~ctx_t()':
/usr/software/zeromq-4.1.3/src/ctx.cpp:117: undefined reference to
randombytes_close'中
/usr/local/lib/libzmq.a(libzmq_la-zmq_utils.o):在函数zmq_curve_keypair':
/usr/software/zeromq-4.1.3/src/zmq_utils.cpp:202: undefined reference to
crypto_box_keypair'中
/usr/local/lib/libzmq.a(libzmq_la-curve_client.o):在函数zmq::curve_client_t::encode(zmq::msg_t*)':
/usr/software/zeromq-4.1.3/src/curve_client.cpp:151: undefined reference to
crypto_box_afternm'中
/usr/local/lib/libzmq.a(libzmq_la-curve_client.o):在函数zmq::curve_client_t::decode(zmq::msg_t*)':
/usr/software/zeromq-4.1.3/src/curve_client.cpp:214: undefined reference to
crypto_box_open_afternm'中
/usr/local/lib/libzmq.a(libzmq_la-curve_client.o):在函数zmq::curve_client_t::curve_client_t(zmq::options_t const&)':
/usr/software/zeromq-4.1.3/src/curve_client.cpp:61: undefined reference to
sodium_init'中
/usr/software/zeromq-4.1.3/src/curve_client.cpp:65:对crypto_box_keypair'
/usr/local/lib/libzmq.a(libzmq_la-curve_client.o): In function
zmq :: curve_client_t :: produce_hello(zmq :: msg_t *)'的未定义引用:
/usr/software/zeromq-4.1.3/src/curve_client.cpp:265:未定义引用crypto_box'
/usr/local/lib/libzmq.a(libzmq_la-curve_client.o): In function
zmq :: curve_client_t :: process_welcome(unsigned char const *,unsigned long)':
/usr/software/zeromq-4.1.3/src/curve_client.cpp:310:对crypto_box_open'
/usr/software/zeromq-4.1.3/src/curve_client.cpp:320: undefined reference to
crypto_box_beforenm'的未定义引用
/usr/local/lib/libzmq.a(libzmq_la-curve_client.o):在函数zmq::curve_client_t::produce_initiate(zmq::msg_t*)':
/usr/software/zeromq-4.1.3/src/curve_client.cpp:340: undefined reference to
randombytes'中
/usr/software/zeromq-4.1.3/src/curve_client.cpp:344:对crypto_box'
/usr/software/zeromq-4.1.3/src/curve_client.cpp:380: undefined reference to
crypto_box'的未定义引用
/usr/local/lib/libzmq.a(libzmq_la-curve_client.o):在函数zmq::curve_client_t::process_ready(unsigned char const*, unsigned long)':
/usr/software/zeromq-4.1.3/src/curve_client.cpp:424: undefined reference to
crypto_box_open_afternm'中
/usr/local/lib/libzmq.a(libzmq_la-curve_server.o):在函数zmq::curve_server_t::encode(zmq::msg_t*)':
/usr/software/zeromq-4.1.3/src/curve_server.cpp:157: undefined reference to
crypto_box_afternm'中
/usr/local/lib/libzmq.a(libzmq_la-curve_server.o):在函数zmq::curve_server_t::decode(zmq::msg_t*)':
/usr/software/zeromq-4.1.3/src/curve_server.cpp:223: undefined reference to
crypto_box_open_afternm'中
/usr/local/lib/libzmq.a(libzmq_la-curve_server.o):在函数zmq::curve_server_t::curve_server_t(zmq::session_base_t*, std::string const&, zmq::options_t const&)':
/usr/software/zeromq-4.1.3/src/curve_server.cpp:64: undefined reference to
sodium_init'中
/usr/software/zeromq-4.1.3/src/curve_server.cpp:68:对crypto_box_keypair'
/usr/local/lib/libzmq.a(libzmq_la-curve_server.o): In function
zmq :: curve_server_t :: process_hello(zmq :: msg_t *)'的未定义引用:
/usr/software/zeromq-4.1.3/src/curve_server.cpp:319:对crypto_box_open'
/usr/local/lib/libzmq.a(libzmq_la-curve_server.o): In function
zmq :: curve_server_t :: produce_welcome(zmq :: msg_t *)'的未定义引用:
/usr/software/zeromq-4.1.3/src/curve_server.cpp:340:对randombytes'
/usr/software/zeromq-4.1.3/src/curve_server.cpp:350: undefined reference to
randombytes'的未定义引用
/usr/software/zeromq-4.1.3/src/curve_server.cpp:355:对crypto_secretbox'
/usr/software/zeromq-4.1.3/src/curve_server.cpp:365: undefined reference to
randombytes'的未定义引用
/usr/software/zeromq-4.1.3/src/curve_server.cpp:377:对crypto_box'
/usr/local/lib/libzmq.a(libzmq_la-curve_server.o): In function
zmq :: curve_server_t :: produce_ready(zmq :: msg_t *)'的未定义引用:
/usr/software/zeromq-4.1.3/src/curve_server.cpp:547:对crypto_box_afternm'
/usr/local/lib/libzmq.a(libzmq_la-curve_server.o): In function
zmq :: curve_server_t :: process_initiate(zmq :: msg_t *)'的未定义引用:
/usr/software/zeromq-4.1.3/src/curve_server.cpp:421:对crypto_secretbox_open'
/usr/software/zeromq-4.1.3/src/curve_server.cpp:454: undefined reference to
crypto_box_open'的未定义引用
/usr/software/zeromq-4.1.3/src/curve_server.cpp:479:对crypto_box_open'
/usr/software/zeromq-4.1.3/src/curve_server.cpp:496: undefined reference to
crypto_box_beforenm'的未定义引用
collect2:错误:ld返回1退出状态
答案 2 :(得分:0)
undefined reference to
消息表示缺少一个或多个库。
基于对加密操作的所有引用,它看起来像lib sodium
,也可能pthread
。要确认这一点,您可以尝试使用
lib sodium
的直接库引用
-l/usr/local/lib/libsodium.a
也许
-lpthread
当然会改变路径
libsodium.a
实际安装了。