Linking libraries containing circular references in GCC

I am trying to link an application with several static libraries in GCC.

There are two libraries that cause problems. Libsupport provides a terminal for the application. It relies on libcpu to provide serial communications, synchronization, and synchronization. Libcpu relies on libsupport to provide queues for serial data, etc.

If I first tell libsupport when the libcpu link cannot be associated with the queue functions. I point out that libcpu first lib support cannot bind serial communication functions (or more).

It seems that GCC parses the library only once and discards any unused objects.

Can I ask gcc to parse libraries multiple times or include all objects?

+4
source share
3 answers
gcc ... -lsupport -lcpu -lsupport -lcpu 

-> Each mention of the library will lead to the resolution of the libraries that were in front of it (but not necessarily to them indicated later), so you may need to specify more "-support -lcpu" in the future.

Alternatively, try --start-group -lsupport -lcpu --end-group once.

+8
source

You can usually specify a library several times to work around this problem, for example.

 $ gcc ... -lsupport -lcpu -lsupport ... 
+2
source

Source: https://habr.com/ru/post/1337107/


All Articles