add shared lib as CXX_BINARY dep

39 views
Skip to first unread message

Ale Bzk

unread,
Apr 29, 2022, 10:12:37 AM4/29/22
to Chromium OS Development
Hi everyone,

I'm adding a new unit test file named webrtc_apm_unittest.cc under src/third_party/webrtc-apm.
I managed to run a simple test, but as soon as the I include the relevant library to test, I get a linker error.
Sharing what I did and the error I get in case someone knows how to solve.

Changes

1. I added a src_test() entry in webrtc-apm-9999.ebuild
2. I added the lines below in https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/third_party/webrtc-apm/Makefile

webrtc_apm_unittest_DEPS = libchrome
webrtc_apm_unittest_CFLAGS := \
    $(shell $(PKG_CONFIG) --cflags $(webrtc_apm_unittest_DEPS))
webrtc_apm_unittest_LIBS := \
    $(shell $(PKG_CONFIG) --libs $(webrtc_apm_unittest_DEPS))
webrtc_apm_unittest_LIBS += -lgtest
CXX_BINARY(webrtc_apm_unittest): CPPFLAGS += $(webrtc_apm_unittest_CFLAGS)
CXX_BINARY(webrtc_apm_unittest): LDLIBS += $(webrtc_apm_unittest_LIBS)
CXX_BINARY(webrtc_apm_unittest): \
    webrtc_apm_unittest.o \
    CXX_LIBRARY(libwebrtc_apm.so) \
    testrunner.o
TEST(CXX_BINARY(webrtc_apm_unittest)): CXX_LIBRARY(libwebrtc_apm.so)


Note that CXX_LIBRARY(libwebrtc_apm.so) is defined in the same file and, as far as I understand, to add it as a dependency of CXX_BINARY(webrtc_apm_unittest) one must list it together with the .o files and also as a dep of TEST(CXX_BINARY(webrtc_apm_unittest)).

Below you can see part of webrtc_apm_unittest.cc:

#include "webrtc_apm.h"

...

TEST(WebRtcApm, CreateApm) {
  webrtc_apm apm = webrtc_apm_create_with_enforced_effects(...);
  ...
}


As I said, if webrtc_apm_unittest.cc doesn't call any function from webrtc_apm.h, the unit test binary is compiled and it runs. However, when I switched to the code above, I started to get this error:

LDCXX        webrtc_apm_unittest
ld.lld: error: undefined symbol: webrtc_apm_create_with_enforced_effects(unsigned int, unsigned int, _dictionary_*, _dictionary_*, unsigned int, unsigned int, unsigned int)
>>> referenced by webrtc_apm_unittest.cc:42 (/build/celes/tmp/portage/media-libs/webrtc-apm-9999/work/webrtc-apm-9999/webrtc_apm_unittest.cc:42)
>>>               webrtc_apm_unittest.pie.o:((anonymous namespace)::WebRtcApmParametrizedTest_CreateApm_Test::TestBody())
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [common.mk:476: CXX_BINARY(webrtc_apm_unittest)] Error 1


Not sure how to tell Makefile that libwebrtc_apm.so is a shared lib dependency for the binary I'm adding. Any suggestion?

Cheers,
Alessio

Ale Bzk

unread,
May 2, 2022, 9:39:49 AM5/2/22
to Chromium OS Development, Ale Bzk
Solved by enclosing #include "webrtc_apm.h" with extern "C" {} in webrtc_apm_unittest.cc.

Mike Frysinger

unread,
May 2, 2022, 9:41:55 AM5/2/22
to Ale Bzk, Chromium OS Development
you should never wrap includes like that. extern markings only go inside the headers themselves.
-mike

--
--
Chromium OS Developers mailing list: chromiu...@chromium.org
View archives, change email options, or unsubscribe:
https://groups.google.com/a/chromium.org/group/chromium-os-dev

Ale Bzk

unread,
May 2, 2022, 9:59:32 AM5/2/22
to Chromium OS Development, Mike Frysinger, Chromium OS Development, Ale Bzk
Thanks Mike! Right, in this way the caller only needs to include the library, no need to repeat extern every time the library is included. Will fix as you suggested.

Reply all
Reply to author
Forward
0 new messages