我正在尝试编译使用libwebsockets库的程序。
我已经在我的linux机器上下载并编译了libwebsockets,并且具有以下目录结构。
/libwebsockets/build/bin/ -> contains the compiled binaries (test-server,test-client etc)
/libwebsockets/build/lib/ -> contains the shared libraries. libwebsockets.so libwebsockets.a libwebsockets.so.5.0.0
/libwebsockets/lib/ -> contains all the header files. eg: libwebsockets.h libwebsockets.c
/libwebsockets/test-server -> contains application programs..(test-server.c test-client.c etc)
现在我创建了我的C程序文件simple-server.c in / libwebsockets / test-server目录。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <syslog.h>
#include <signal.h>
#include <libwebsockets.h>
&#13;
当我尝试编译这个程序时:
gcc -L/home/gadre/Desktop/Testing/libwebsockets/build/lib/ -lwebsockets simple-server.c -o s
我收到链接器错误:
simple-server.c:(.text+0x14c): undefined reference to `lwsl_emit_syslog'
simple-server.c:(.text+0x158): undefined reference to `lws_set_log_level'
simple-server.c:(.text+0x16d): undefined reference to `libwebsocket_get_internal_extensions'
simple-server.c:(.text+0x1a5): undefined reference to `libwebsocket_create_context'
simple-server.c:(.text+0x1c4): undefined reference to `_lws_log'
simple-server.c:(.text+0x1e9): undefined reference to `libwebsocket_service'
simple-server.c:(.text+0x209): undefined reference to `libwebsocket_context_destroy'
simple-server.c:(.text+0x21d): undefined reference to `_lws_log'
&#13;
如何解决这个问题。我尝试将路径放在LD_LIBRARY_PATH中。但是链接器仍无法找到共享库。
答案 0 :(得分:0)
我现在可以编译了......我使用了以下命令。带有运行时链接选项。
gcc -L/home/gadre/Desktop/Testing/libwebsockets/build/lib -Wl,-rpath=/home/gadre/Desktop/Testing/libwebsockets/build/lib -Wall -o server incr_server.c -lwebsockets
我不知道具体细节但现在适用