Makefile: Use pkg-config if available.#618
Conversation
Debian buster(testing) and presumably ubuntu 17.10 package all the dependencies required to build BESS (except dpdk). New versions of GRPC (packaged in debian) require libc-ares and if BESS is statically linked (by default it is), `-lcares` must be passed to the linker. Instead of forcing a new dependency for all users (even the ones that don't need it), this commit makes use of pkg-config, which will automatically include the indirect dependencies (such as libc-ares). For users that have an old grpc version (such as `container_build.py`), pkg-config is still optional. I'd like to make it required, but a new container image must be generated, and that's a decision we can make later.
`-ldl` is used by DPDK on some systems. Therefore it needs to be listed also after it on the LDFLAGS.
| NO_PKG_CONFIG_LIBS_INDIRECT := -lgrpc -lssl -lcrypto -llzma | ||
|
|
||
| ifeq ($(HAS_PKG_CONFIG), yes) | ||
| PKG_CFLAGS = $(shell $(PKG_CONFIG) --cflags $(PKG_CONFIG_DEPS)) |
There was a problem hiding this comment.
Can this be statically defined (with :=)?
There was a problem hiding this comment.
Thanks for the suggestion! I did that here and in the other places I was shelling out to call pkg-config
gflags on ubuntu 16.04 doesn't have a pkg-config file, so we have to list it manually. `-ldl` is used by DPDK and must be listed before and after to properly be dynamically linked.
Codecov Report
@@ Coverage Diff @@
## master #618 +/- ##
=========================================
- Coverage 69.33% 69.3% -0.03%
=========================================
Files 204 204
Lines 13037 13068 +31
=========================================
+ Hits 9039 9057 +18
- Misses 3998 4011 +13
Continue to review full report at Codecov.
|
| # user requests a static build. These needs to be listed first, so even | ||
| # if they're listed again in the static section, they will be dynamically | ||
| # linked. | ||
| ALWAYS_DYN_LIBS := -lpthread -ldl |
There was a problem hiding this comment.
Is it necessary to add -lpthread here? The -pthread option already implies this...
There was a problem hiding this comment.
I believe it's necessary.
grpc includes -lpthread in its statically required libraries. If we don't specify -lpthread before (in the dynamic section), -lpthread will be linked statically, and that's not well supported apparently
| $(PKG_LIBS) $(ALWAYS_LIBS) \ | ||
| $(LIBS_DL_SHARED) \ | ||
| -ldl | ||
| $(ALWAYS_DYN_LIBS) |
There was a problem hiding this comment.
Just checking: Adding $(ALWAYS_DYN_LIBS) twice was intended?
There was a problem hiding this comment.
It was intended.
DPDK depends on -ldl, so -ldl must be specified after DPDK.
But then again, we want to dynamically link with -ldl. If one of the other libs depend on -ldl it will be listed in the static section. We must make sure that we include it at the beginning of the cmdline, in the dynamic section
|
This pull request appears to have broken static builds for me on Ubuntu 16.04 LTS (kernel 4.4.0-93-generic): The full output is much longer, but are duplicates of this error on other files. The issue seems to be that An easy, but hacky, way to do this in the Makefile is to use |
|
Thanks for reporting this and sorry for the breakage. I wasn't able to reproduce it on ubuntu 16.04, but your suggestion makes sense to me (I like it better than listing twice the libraries). I submitted PR #626, I removes Thanks |

Debian buster(testing) and presumably ubuntu 17.10 package all the
dependencies required to build BESS (except dpdk).
New versions of GRPC (packaged in debian) require libc-ares and if BESS
is statically linked (by default it is),
-lcaresmust be passed to thelinker.
Instead of forcing a new dependency for all users (even the ones that don't
need it), this commit makes use of pkg-config, which will automatically
include the indirect dependencies (such as libc-ares).
For users that have an old grpc version (such as
container_build.py),pkg-config is still optional. I'd like to make it required, but a new
container image must be generated, and that's a decision we can make
later.