0

Fist, sorry you guys my English is bad, so I hope you guys understand for me. My problem look like Use both static and dynamically linked libraries in gcc Im using Ubuntu 18 and visual code, i want link libudev library to my project as dynamic library so I add -ludev of my makefile and here is my makefile:

CC       = g++
CFLAGS   = -Wall -g

LINKER   = g++
LDFLAGS  = -Wall -static -L./libs/curl/lib -lcurl -lssl -lcrypto -lsqlite3 -lpthread -ldl -lz -static-libstdc++ -static-libgcc -ludev

but this don't work, then i follow this post Use both static and dynamically linked libraries in gcc and fix makefile like this:

CC       = g++
CFLAGS   = -Wall -g

LINKER   = g++

LDFLAGS += -L./libs/curl/lib

LDFLAGS += -Wl,-Bstatic
LDFLAGS += -lcurl
LDFLAGS += -lssl
LDFLAGS += -lcrypto
LDFLAGS += -lsqlite3
LDFLAGS += -lpthread
LDFLAGS += -ldl
LDFLAGS += -lz
LDFLAGS += -static-libstdc++
LDFLAGS += -static-libgcc

LDFLAGS += -Wl,-Bdynamic
LDFLAGS += -ludev

but this still don't work

/usr/lib/gcc/x86_64-linux-gnu/7/../../../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/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libpthread.a(pthread_create.o): In function `allocate_stack':
/build/glibc-2ORdQG/glibc-2.27/nptl/allocatestack.c:526: undefined reference to `_dl_stack_flags'
/build/glibc-2ORdQG/glibc-2.27/nptl/allocatestack.c:652: undefined reference to `_dl_stack_flags'

So how do I do to use both static and dynamic link libraries in my project

Luong Viet
  • 13
  • 2
  • You should in the first place be mindful of the linker warning: "**Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking**". That approximately means *there is no point* to statically linking `libgcc` or (probably) `libstdc++` into this particular application. Because it uses the `dlopen()` function, dynamic versions of at least the former, and probably both, will be required at runtime. If you succeed, you'll have an *extra-large* binary that is *even more sensitive* to local libraries than usual. – John Bollinger Oct 29 '20 at 11:42
  • I find the (hidden) syntax `l:libcrypto.a` simpler when I want to link a library as static or not at all. https://stackoverflow.com/questions/6578484/telling-gcc-directly-to-link-a-library-statically – Andreas Oct 29 '20 at 14:59
  • Does this answer your question? [Undefined reference error \_dl\_stack\_flags with gcc and pthreads](https://stackoverflow.com/questions/5738000/undefined-reference-error-dl-stack-flags-with-gcc-and-pthreads) –  Oct 29 '20 at 21:16

0 Answers0