TelegramMessenger / MTProxy

4.97k stars 822 forks source link

Problems encountered in static compilation on debian9? #413

Open ellermister opened 4 years ago

ellermister commented 4 years ago

I want to static compilation MTPROXY, but I encountered some problems, please help me !

Error:

cc  -O3 -std=gnu11 -Wall -mpclmul -march=core2 -mfpmath=sse -mssse3 -fno-strict-aliasing -fno-strict-overflow -fwrapv -DAES=1 -DCOMMIT=\"dc0c7f3de40530053189c572936ae4fd1567269b\" -D_GNU_SOURCE=1 -D_FILE_OFFSET_BITS=64 -fpic -iquote common -iquote . -c -MP -MD -MF dep/common/server-functions.d -MQ objs/common/server-functions.o -o objs/common/server-functions.o common/server-functions.c
cc  -O3 -std=gnu11 -Wall -mpclmul -march=core2 -mfpmath=sse -mssse3 -fno-strict-aliasing -fno-strict-overflow -fwrapv -DAES=1 -DCOMMIT=\"dc0c7f3de40530053189c572936ae4fd1567269b\" -D_GNU_SOURCE=1 -D_FILE_OFFSET_BITS=64 -fpic -iquote common -iquote . -c -MP -MD -MF dep/common/crc32.d -MQ objs/common/crc32.o -o objs/common/crc32.o common/crc32.c
rm -f objs/lib/libkdb.a && ar rcs objs/lib/libkdb.a objs/common/crc32c.o objs/common/pid.o objs/common/sha1.o objs/common/sha256.o objs/common/md5.o objs/common/resolver.o objs/common/parse-config.o objs/crypto/aesni256.o objs/jobs/jobs.o objs/common/mp-queue.o objs/net/net-events.o objs/net/net-msg.o objs/net/net-msg-buffers.o objs/net/net-config.o objs/net/net-crypto-aes.o objs/net/net-crypto-dh.o objs/net/net-timers.o objs/net/net-connections.o objs/net/net-rpc-targets.o objs/net/net-tcp-connections.o objs/net/net-tcp-rpc-common.o objs/net/net-tcp-rpc-client.o objs/net/net-tcp-rpc-server.o objs/net/net-http-server.o objs/common/tl-parse.o objs/common/common-stats.o objs/engine/engine.o objs/engine/engine-signals.o objs/engine/engine-net.o objs/engine/engine-rpc.o objs/engine/engine-rpc-common.o objs/net/net-thread.o objs/net/net-stats.o objs/common/proc-stat.o objs/common/kprintf.o objs/common/precise-time.o objs/common/cpuid.o objs/common/server-functions.o objs/common/crc32.o
cc -o objs/bin/mtproto-proxy objs/mtproto/mtproto-proxy.o objs/mtproto/mtproto-config.o objs/net/net-tcp-rpc-ext-server.o objs/lib/libkdb.a objs/lib/libkdb.a  -ggdb -static  -static-libgcc -lm -lrt -lcrypto -lz -lpthread -lcrypto -ldl
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/libcrypto.a(dso_dlfcn.o): in function `dlfcn_globallookup':
(.text+0x11): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: objs/lib/libkdb.a(server-functions.o): in function `change_user':
server-functions.c:(.text+0x1a9): warning: Using 'initgroups' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: objs/lib/libkdb.a(server-functions.o): in function `change_user_group':
server-functions.c:(.text+0x81): warning: Using 'getgrnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: server-functions.c:(.text+0x46): warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/libcrypto.a(b_addr.o): in function `BIO_lookup_ex':
(.text+0xbf3): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: objs/lib/libkdb.a(resolver.o): in function `kdb_gethostbyname':
resolver.c:(.text+0x91c): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: resolver.c:(.text+0x92e): warning: Using 'gethostbyname2' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

OS: Debian9

Makefile

OBJ     =       objs
DEP     =       dep
EXE = ${OBJ}/bin

COMMIT := $(shell git log -1 --pretty=format:"%H")

ARCH =
ifeq ($m, 32)
ARCH = -m32
endif
ifeq ($m, 64)
ARCH = -m64
endif

CFLAGS = $(ARCH) -O3 -std=gnu11 -Wall -mpclmul -march=core2 -mfpmath=sse -mssse3 -fno-strict-aliasing -fno-strict-overflow -fwrapv -DAES=1 -DCOMMIT=\"${COMMIT}\" -D_GNU_SOURCE=1 -D_FILE_OFFSET_BITS=64
LDFLAGS = $(ARCH) -ggdb -static  -static-libgcc -lm -lrt -lcrypto -lz -lpthread -lcrypto -ldl

LIB = ${OBJ}/lib
CINCLUDE = -iquote common -iquote .

LIBLIST = ${LIB}/libkdb.a

PROJECTS = common jobs mtproto net  crypto engine

OBJDIRS := ${OBJ} $(addprefix ${OBJ}/,${PROJECTS}) ${EXE} ${LIB}
DEPDIRS := ${DEP} $(addprefix ${DEP}/,${PROJECTS})
ALLDIRS := ${DEPDIRS} ${OBJDIRS}

.PHONY: all clean

EXELIST := ${EXE}/mtproto-proxy

OBJECTS =       \
  ${OBJ}/mtproto/mtproto-proxy.o ${OBJ}/mtproto/mtproto-config.o ${OBJ}/net/net-tcp-rpc-ext-server.o

DEPENDENCE_CXX          :=      $(subst ${OBJ}/,${DEP}/,$(patsubst %.o,%.d,${OBJECTS_CXX}))
DEPENDENCE_STRANGE      :=      $(subst ${OBJ}/,${DEP}/,$(patsubst %.o,%.d,${OBJECTS_STRANGE}))
DEPENDENCE_NORM :=      $(subst ${OBJ}/,${DEP}/,$(patsubst %.o,%.d,${OBJECTS}))

LIB_OBJS_NORMAL := \
        ${OBJ}/common/crc32c.o \
        ${OBJ}/common/pid.o \
        ${OBJ}/common/sha1.o \
        ${OBJ}/common/sha256.o \
        ${OBJ}/common/md5.o \
        ${OBJ}/common/resolver.o \
        ${OBJ}/common/parse-config.o \
        ${OBJ}/crypto/aesni256.o \
        ${OBJ}/jobs/jobs.o ${OBJ}/common/mp-queue.o \
        ${OBJ}/net/net-events.o ${OBJ}/net/net-msg.o ${OBJ}/net/net-msg-buffers.o \
        ${OBJ}/net/net-config.o ${OBJ}/net/net-crypto-aes.o ${OBJ}/net/net-crypto-dh.o ${OBJ}/net/net-timers.o \
        ${OBJ}/net/net-connections.o \
        ${OBJ}/net/net-rpc-targets.o \
        ${OBJ}/net/net-tcp-connections.o ${OBJ}/net/net-tcp-rpc-common.o ${OBJ}/net/net-tcp-rpc-client.o ${OBJ}/net/net-tcp-rpc-server.o \
        ${OBJ}/net/net-http-server.o \
        ${OBJ}/common/tl-parse.o ${OBJ}/common/common-stats.o \
        ${OBJ}/engine/engine.o ${OBJ}/engine/engine-signals.o \
        ${OBJ}/engine/engine-net.o \
        ${OBJ}/engine/engine-rpc.o \
        ${OBJ}/engine/engine-rpc-common.o \
        ${OBJ}/crypto/aesni256.o \
        ${OBJ}/jobs/jobs.o ${OBJ}/common/mp-queue.o \
        ${OBJ}/net/net-events.o ${OBJ}/net/net-msg.o ${OBJ}/net/net-msg-buffers.o \
        ${OBJ}/net/net-config.o ${OBJ}/net/net-crypto-aes.o ${OBJ}/net/net-crypto-dh.o ${OBJ}/net/net-timers.o \
        ${OBJ}/net/net-connections.o \
        ${OBJ}/net/net-rpc-targets.o \
        ${OBJ}/net/net-tcp-connections.o ${OBJ}/net/net-tcp-rpc-common.o ${OBJ}/net/net-tcp-rpc-client.o ${OBJ}/net/net-tcp-rpc-server.o \
        ${OBJ}/net/net-http-server.o \
        ${OBJ}/common/tl-parse.o ${OBJ}/common/common-stats.o \
        ${OBJ}/engine/engine.o ${OBJ}/engine/engine-signals.o \
        ${OBJ}/engine/engine-net.o \
        ${OBJ}/engine/engine-rpc.o \
        ${OBJ}/engine/engine-rpc-common.o \
        ${OBJ}/net/net-thread.o ${OBJ}/net/net-stats.o ${OBJ}/common/proc-stat.o \
        ${OBJ}/common/kprintf.o \
        ${OBJ}/common/precise-time.o ${OBJ}/common/cpuid.o \
        ${OBJ}/common/server-functions.o ${OBJ}/common/crc32.o \

LIB_OBJS := ${LIB_OBJS_NORMAL}

DEPENDENCE_LIB  :=      $(subst ${OBJ}/,${DEP}/,$(patsubst %.o,%.d,${LIB_OBJS}))

DEPENDENCE_ALL          :=      ${DEPENDENCE_NORM} ${DEPENDENCE_STRANGE} ${DEPENDENCE_LIB}

OBJECTS_ALL             :=      ${OBJECTS} ${LIB_OBJS}

all:    ${ALLDIRS} ${EXELIST}
dirs: ${ALLDIRS}
create_dirs_and_headers: ${ALLDIRS}

${ALLDIRS}:
        @test -d $@ || mkdir -p $@

-include ${DEPENDENCE_ALL}

${OBJECTS}: ${OBJ}/%.o: %.c | create_dirs_and_headers
        ${CC} ${CFLAGS} ${CINCLUDE} -c -MP -MD -MF ${DEP}/$*.d -MQ ${OBJ}/$*.o -o $@ $<

${LIB_OBJS_NORMAL}: ${OBJ}/%.o: %.c | create_dirs_and_headers
        ${CC} ${CFLAGS} -fpic ${CINCLUDE} -c -MP -MD -MF ${DEP}/$*.d -MQ ${OBJ}/$*.o -o $@ $<

${EXELIST}: ${LIBLIST}

${EXE}/mtproto-proxy:   ${OBJ}/mtproto/mtproto-proxy.o ${OBJ}/mtproto/mtproto-config.o ${OBJ}/net/net-tcp-rpc-ext-server.o
        ${CC} -o $@ $^ ${LIB}/libkdb.a ${LDFLAGS}

${LIB}/libkdb.a: ${LIB_OBJS}
        rm -f $@ && ar rcs $@ $^

clean:
        rm -rf ${OBJ} ${DEP} ${EXE} || true

force-clean: clean