Why am I getting a runtime error after I linked the shared library to a non-standard location?

I am new to Linux. I wrote an application that uses MySQL, and its Makefile is published as follows:

OBJ = main.o PeerDbOpMgr.o
MYSQL_INC = ./mysql/include
LNK_MYSQL = ./mysql/lib/ -lmysql

main : $(OBJ) 
    g++ -g -o main $(OBJ) -L$(LNK_MYSQL) -lpthread -lm

main.o : main.cpp
    g++ -g -c -I$(MYSQL_INC) main.cpp


PeerDbOpMgr.o : PeerDbOp.cpp PeerDbOp.h
    g++ -g -c -I$(MYSQL_INC) PeerDbOp.cpp -o PeerDbOpMgr.o

clean : 
    rm main $(OBJ) 

I compiled it successfully. But when I ran it, he found an error:

./main: error while loading shared libraries: libmysql.so.16: cannot open shared objects file: no such file or directory

The file libmysql.so.16is under ./mysql/lib/libmysql.so.16, but why does it say that there is no such file or directory?

+3
source share
1 answer

, . , , : env LD_LIBRARY_PATH=./mysql/lib ./main

: ld (1), ldconfig (8)

+7

All Articles