17

what is the difference between linking against gcc_s and gcc by means of LDFLAGS?

Is gcc_s a static library and gcc shared library?

Because I was looking for a solution where it is mentioned to link against gcc whereas only gcc_s works in my case. I wish to know the real difference.

<<hidden symbol `__name_here' in /some/library/path.a(_filename.o) is referenced by DSO

In this case, the problem is usually solved by adding either "-l gcc" or "gcc -print-libgcc-file-name" to the linking flags (LDFLAGS). However, unlike my other regular platforms (i386, amd64, sparc64) here it wasn't enough. After a lot of head-banging (to be fair, it also comes from the music) I realized that this flag is necessary both when linking the libc and the final executable file. link: http://people.defora.org/~khorben/200903.html

Guillaume Jacquenot
  • 11,217
  • 6
  • 43
  • 49
kumar
  • 2,530
  • 6
  • 33
  • 57
  • 1
    There is also `libgcc_eh.a`, which gets used when `-static` used. http://stackoverflow.com/questions/10763394/how-to-build-a-c-program-using-a-custom-version-of-glibc-and-static-linking – Ciro Santilli OurBigBook.com Jun 09 '15 at 15:50

1 Answers1

18

libgcc_s.so is a shared library, libgcc.a is a static library. They are not equivalent; it may be necessary to link both. libgcc_s contains global variables which must not have multiple copies in a process; the code in libgcc is safe to link multiple times.

Martin v. Löwis
  • 124,830
  • 17
  • 198
  • 235
  • Hi, Thanks, < – kumar Dec 29 '10 at 06:15
  • 4
    @kumar: Some symbols (e.g. `__register_frame`) are only in libgcc_s, others (e.g. `__eprintf`) are only in libgcc. Use `nm -D --defined-only libgcc_s.so` resp. `nm --defined-only libgcc.a` to get full lists to compare. – Martin v. Löwis Dec 29 '10 at 08:29
  • 5
    Why do we need both? Why are they not the same, only one static and the other dynamic? – Ciro Santilli OurBigBook.com Jun 08 '15 at 11:24
  • I would assume its a question of size and portability with regards to distribution methods and compliance of code/execution. Whatever useless removed means lighter files, packages, execution (possibly?) and easier debugging/forensics (i assume, from past experiences) – OldFart Jun 09 '22 at 03:11