user1101096
user1101096

Reputation: 749

what's the difference between DLDFLAGS and LDFLAGS

A quick question. I found both "DLDFLAGS" and "LDFLAGS" in a sample Makefile. The compiler used is gcc. It looks like they are both used for linkers. I'm wondering what's the difference between them.

Upvotes: 8

Views: 16482

Answers (2)

Lewiatan
Lewiatan

Reputation: 21

Isn't DLDFLAGS just a precompiler flag that defines macro named "LDFLAGS"?

From gcc manual:

-D name

Predefine name as a macro, with definition 1

Upvotes: 0

Callie J
Callie J

Reputation: 31296

LDFLAGS is normally set to contain options that are passed through to the linker (so may include required libraries). Together with CFLAGS, these are often set as part of a developers environment variables and make will know about them so will actively look to see if they're set and pass them through to the compiler.

For example, if I set CFLAGS in my environment to -O2 -Wall, then if I type make hello with no Makefile, make will automatically invoke the compiler as gcc -O2 -Wall hello.c -o hello.o. Then it'll invoke the linker in a similar way, adding the flags in LDFLAGS to the command line.

Makefiles can explicitly override both LDFLAGS and CFLAGS.

DLDFLAGS on the other hand is not a well known/defined variable, so it's likely to be specific to that particular Makefile. You'd have to read the Makefile to find out how it's used. It may, for example, define linker flags to use if LDFLAGS is set - read the Makefile to find out for sure.

Upvotes: 10

Related Questions