3 ms·
CPPFLAGS and CXXFLAGS are different. CPPFLAGS are for options for the C preprocessor, regardless of what language it is being used for. CXXFLAGS are for C++. T
by kazinator 1y ago
CPPFLAGS and CXXFLAGS are different. CPPFLAGS are for options for the C preprocessor, regardless of what language it is being used for. CXXFLAGS are for C++. The XX's are ++ rotated 45 degrees.
Don't be fooled by the convention used in some necks of the woods of a .cpp suffix for C++ files; CPPFLAGS have to do with the "cpp" program, not the .cpp suffix.
LDLIBS is sister to LDFLAGS. Both these variables hold options for the linker command line destructured into two groups: LDFLAGS are the early options that go before the object files. LDLIBS are the -l options that give libraries, like -lssl -ldl -lcrypto ... these go after the object files.
If you're writing a Makefile, with your own custom recipes for linking, be sure you interpolate both LDFLAGS and LDLIBS in the right places.
- zabzonk 1y agoA brief, simplified explanation of why the -l option order matters - the linker is only going to look for unresolved symbols in libraries after it has linked the object files and found that there actually _are_ unresolved symbols (hopefully provided by the libraries). Thus -l options placed before the linking of the object files are effectively ignored.
- wpollock 1y agoThis is only true when statically linking. Order does not matter when dynamically linking. (This was a surprise to me but I have tested it.)
- bluGill 1y agoOrder matters if you violating the one definiton rule - the first one wins one linux. This is illegal undefined behavior that doesn't work on windows and I don't know what mac does. hopefully this is useless trivia.
- o11c 1y agoI'm pretty sure distro-specific spec files can make it matter. But you really, really should be using `pkg-config` (and no other obsolete `foo-config`) so you don't have to worry about it regardless. (If you really want to do it yourself, learn about the `tsort` program first. Although allegedly obsolete for its original purpose, it is still useful to automate some sanity, and applies just as well between libraries as within them.)
- cozzyd 1y agoThis depends on the default value of the -as-needed linker options. Fedora/red hat and debian/Ubuntu diverge here
- wpollock 1y agoGood to know, thanks! I only tested on Fedora. If anyone cares, here's a link for a tarball for testing this; read the simple makefile for details: <https://wpollock.com/AUnix2/dll-demo.tgz https://wpollock.com/AUnix2/dll-demo.tgz> (I wrote this long ago, as a linking demo for system administration students.)
- hedora 1y agoThe GNU make manual is excellent. I wish more people would read it before writing makefile generators, make replacements, etc. Anywhere, here's the section on all the variables used by the implicit (built in) rules: https://www.gnu.org/software/make/manual/make.html#Implicit-Variables https://www.gnu.org/software/make/manual/make.html#Implicit-...
- emmelaich 1y agoMaybe it's upcoming, but Julia should mention `pkgconfig` to get the various options for compiling.