I have to include '-rpath' flag with a specified directory in the command above so the directory will be searched at the runtime.
search the same dir as executable dir: -Wl,-rpath,.
search "libs" directory inside directory where is located executable: -Wl,-rpath,libs/
So now my command looks like this:
g++ *.cpp -I/my_include_dir/ -L/my_lib_dir/ -lSDL_image -lSDL_ttf -lSDL_mixer -lSDL -lpthread -ldl -lfreetype -lz -Wl,-rpath,. -o build/tictactoe32 -m32
Check which libraries will be loaded by the executable at runtime:
ldd <binary>Check which directories will be searched for libraries:
readelf -d <binary> | grep RPATH
http://www.techytalk.info/c-cplusplus-library-programming-on-linux-part-one-static-libraries/ (3 parts)
in terminal: man ld