user188276
user188276

Reputation:

By default, does gcc link to static or dynamic standard library?

Ex:

gcc source-file

I think it is dynamic but I'm not sure. Is it system dependent?

Upvotes: 6

Views: 2532

Answers (2)

Nicholas Knight
Nicholas Knight

Reputation: 16045

It is technically system dependent, but on most systems you're likely to develop for, the answer is "dynamic".

A few systems (mostly very old, embedded, or otherwise specialized) do not support dynamic linking at all, but most developers are unlikely to care about those systems. On those systems, the linker will of course default to linking statically (unless whoever did the port screwed up :)).

Some systems also do not offer static versions of their standard libraries, so you can't statically link them.

On many systems (especially any typical Linux system), you probably have a utility called ldd. You can use ldd <file> to check if it's dynamically linked to the standard library (assuming you know for sure what the library is called, it's usually libc though).

Upvotes: 5

Carl Norum
Carl Norum

Reputation: 224904

Most linkers prefer dynamic libraries to static when linking, but normally they have flags to explicitly specify the behaviour. It's definitely system dependent - check your linker documentation for details.

Upvotes: 1

Related Questions