Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 Oct 2019 13:44:25 +0200
From:      David Demelier <markand@malikania.fr>
To:        freebsd-questions@freebsd.org
Subject:   Re: Problems with ld, libc, and "struct stat"
Message-ID:  <0f1c70a0-c99a-e494-cf63-d214301f24a1@malikania.fr>
In-Reply-To: <20191016131552.6fda34292987e22ae78072cc@magnetkern.de>
References:  <20191015204400.e33c8f62af711e829288ddae@magnetkern.de> <47c27361-4e74-05d1-3343-e39526730d85@malikania.fr> <20191016131552.6fda34292987e22ae78072cc@magnetkern.de>

next in thread | previous in thread | raw e-mail | index | archive | help
Le 16/10/2019 à 13:15, Jan Behrens a écrit :
> Do you know any link where I find a more detailed explanation about why
> I need to use "cc" instead of "ld" to create shared libraries? I assume
> that "cc" adds the necessary options to "ld" that are otherwise
> missing. But I don't see where this is documented.

Yes, many :-)

See output of clang -v when creating your shared library:

  "/usr/bin/ld" --eh-frame-hdr -Bshareable --hash-style=both 
--enable-new-dtags -o libfoo.so /usr/lib/crti.o /usr/lib/crtbeginS.o 
-L/usr/lib test.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc 
--as-needed -lgcc_s --no-as-needed /usr/lib/crtendS.o /usr/lib/crtn.o

> When I search the man page for "cc" (clang - the Clang C, C++, and
> Objective-C compiler), I even do not find any "-shared" option at all.

-shared is a linker option, it's documented in gcc but basically clang 
is usually retro-compatible with most of the GCC option. In fact, 
-shared is just a shortcut to pass the appropriate shared arguments to 
the underlying linker in that case -Bshareable (but may add additional 
options as well).

Clang's manual page is not as full as gcc, that's true though.

Regards,

-- 
David




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?0f1c70a0-c99a-e494-cf63-d214301f24a1>