1

I'd to compiling my application with using the libwebsockets.a instead of the libwebsocket.so but i have some problems. i think there is a lack of link but i don't find what library lacking.

My code compile and works on the Raspberry Pi with Raspian Jessie, but i'd like my code works on others distribution. To do that I want integrate libwebsocket in my application. Switch the libwebsocket.so i use to the libwebsocket.a (switch to the static library)

I add the libwebsockets.h and .a in folders. Add link to that folders (for library -L../FW_Shared/lib/libwebsockets and for includes -I../FW_Shared/websockets/include)

Sorry my Raspbien is in french

EX :    ../FW_Shared/lib/libwebsockets/libwebsockets.a(libwebsockets_la-libwebsockets.o) : In function « libwebsocket_context_destroy » :
    (.text+0x1414) :undefined reference to « ERR_free_strings »

    ../FW_Shared/lib/libwebsockets/libwebsockets.a(libwebsockets_la-libwebsockets.o) : Dans la fonction « libwebsocket_context_destroy » :
    (.text+0x1414) : référence indéfinie vers « ERR_free_strings »
    ../FW_Shared/lib/libwebsockets/libwebsockets.a(libwebsockets_la-libwebsockets.o) : Dans la fonction « libwebsocket_context_destroy » :
    (.text+0x1418) : référence indéfinie vers « EVP_cleanup »
    ../FW_Shared/lib/libwebsockets/libwebsockets.a(libwebsockets_la-libwebsockets.o) : Dans la fonction « libwebsocket_context_destroy » :
    (.text+0x141c) : référence indéfinie vers « CRYPTO_cleanup_all_ex_data »
    ../FW_Shared/lib/libwebsockets/libwebsockets.a(libwebsockets_la-libwebsockets.o) : Dans la fonction « libwebsocket_create_context » :
    (.text+0x1f30) : référence indéfinie vers « SSL_library_init »
    ../FW_Shared/lib/libwebsockets/libwebsockets.a(libwebsockets_la-libwebsockets.o) : Dans la fonction « libwebsocket_create_context » :
    (.text+0x1f34) : référence indéfinie vers « OPENSSL_add_all_algorithms_noconf »
    ../FW_Shared/lib/libwebsockets/libwebsockets.a(libwebsockets_la-libwebsockets.o) : Dans la fonction « libwebsocket_create_context » :
    (.text+0x1f38) : référence indéfinie vers « SSL_load_error_strings »
    ../FW_Shared/lib/libwebsockets/libwebsockets.a(libwebsockets_la-libwebsockets.o) : Dans la fonction « libwebsocket_create_context » :
    (.text+0x1f58) : référence indéfinie vers « SSL_get_ex_new_index »
    ../FW_Shared/lib/libwebsockets/libwebsockets.a(libwebsockets_la-libwebsockets.o) : Dans la fonction « libwebsocket_create_context » :
    (.text+0x1f68) : référence indéfinie vers « SSLv23_server_method »
    ../FW_Shared/lib/libwebsockets/libwebsockets.a(libwebsockets_la-libwebsockets.o) : Dans la fonction « libwebsocket_create_context » :
    (.text+0x2208) : référence indéfinie vers « SSLv23_client_method »

My Makefile :

READER =        Reader
ROOT_DIR =      .
PROJ_DIR =      $(ROOT_DIR)/src
LIB_DIR =       $(ROOT_DIR)/lib
INC_DIR =       $(ROOT_DIR)/include
OUT_DIR =       $(ROOT_DIR)/bin

NAME = TestServer
# CC = arm-linux-gnueabi-gcc
CC = arm-linux-gnueabihf-gcc

CFLAGS =  -DNUR_EXPOSE_WIN32API -std=gnu99 -DNUR_MODULE -pedantic -W -Wall

SRC =   $(PROJ_DIR)/testServer.c    \
    $(PROJ_DIR)/mtTestVersion.c \
    $(PROJ_DIR)/mtTestQueue.c   \
    $(PROJ_DIR)/mtTestJsonFormat.c  \
    $(PROJ_DIR)/mtTestWebSocket.c

OBJ= $(SRC:.c=.o)


LIBS = -L../FW_Shared/tools/lib/ -L../FW_Shared/lib/liblog4c/ -L../FW_Shared/lib/libjansson -L../FW_Shared/lib/libwebsockets -L/usr/lib/arm-linux-gnueabihf/ -L../HW_Reader/bin/NordicID/ -L../HW_Reader/lib/NordicID/ -L../FW_TestCtrl/bin/ -L$(LIB_DIR) -lmtTestCtrl -lmtTools -lNurApiRasPi -lrt -lm -lpthread -ljansson -llog4c -lwebsockets -lcrypto -lssl -lz 
INCLUDES = -I./include -I/usr/include/ -I../FW_Shared/log4c-1.2.4/src -I../FW_TestCtrl/include -I../HW_Reader/include/$(READER) -I../FW_Shared/jansson/include -I../FW_Shared/websockets/include -I../FW_Shared/tools/inc

TARGET = 0.0.0.0
TARGET_PATH = test/

all: $(NAME)

$(NAME): $(OBJ)
    $(CC) -o $(OUT_DIR)/$(NAME) $(INCLUDES) $(CFLAGS) $(OBJ) $(LIBS)

clean:
    rm -rf $(OBJ) *~ \#*\# src/*~ src/\#*\# include/*~ include/\#*\#

fclean: clean
    rm -rf $(OUT_DIR)/$(NAME)

re : fclean all

%.o:%.c
    $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) $(LIBS)

.PHONY: clean fclean push

I find some links to add (like -lz -lssl), to reduce undefined references, but i can't find what link is lacking for this last error lines. Maybe it's another way to correct this problem ?

Thanks

meso
  • 21
  • 3
  • Could you please add the `gcc` command to show how you are linking and compiling your code? Or if you are using a makefile, then please add a makefile. – Duck Dodgers May 23 '19 at 10:21
  • Indeed `SSLv23_server_method`, `SSLv23_client_method`, `SSL_load_error_strings`, `OPENSSL_add_all_algorithms_noconf`, `SSL_library_init`, `SSL_library_init`, `CRYPTO_cleanup_all_ex_data`, `ERR_free_strings` are all indicating that the linker errors would go away if you link to **openssl**. – Duck Dodgers May 23 '19 at 10:23
  • As per this [answer](https://stackoverflow.com/questions/4352573/linking-openssl-libraries-to-a-program) try something like this to compile and link with openssl -> `gcc -Wall -Wextra -Werror -static -o myApp source1.o source2.o common.o -Lopenssl/openssl-0.9.8k/ -lssl -lcrypto -Iopenssl/openssl-0.9.8k/include` – Duck Dodgers May 23 '19 at 10:26
  • Possible duplicate of [Linking OpenSSL libraries to a program](https://stackoverflow.com/questions/4352573/linking-openssl-libraries-to-a-program) – Duck Dodgers May 23 '19 at 10:26
  • 1
    Thanks for your help Normally the -lssl must remove all the errors, but i wanted to make too much things in one time. – meso May 24 '19 at 09:51
  • So, I get it that you managed to fix the problem? – Duck Dodgers May 25 '19 at 09:04

1 Answers1

1

Normally the -lssl must remove all the errors, but there is a problem of the version of libraries i use. (I tried compile my program for RaspBian Jessie and Raspbian Stretch and some librarie's version are change and not compatible). Thanks

meso
  • 21
  • 3