在对共享库进行单元测试时,如何通过模拟实现替换功能?

问题描述 投票:0回答:1

我遇到Can you compile a shared object to prefer local symbols even if it's being loaded by a program compiled with -rdynamic?正在解决的相反问题。

[使用链接问题的命名,我有一个动态库,其中baz调用了bar,并且我有一个测试二进制文件对该库进行了练习,该库将其自己的bar伪造实现用于测试目的。这在Linux上可以正常使用,因为使用-rdynamic进行链接。

测试的来源是https://github.com/apache/qpid-dispatch/blob/b172f501028b36d786b4c83bcee1e195cd17fcf2/tests/timer_test.c。被模拟的函数包括qd_server_timeoutqd_timer_now(即内联函数,请参见注释)。

我不知如何在macOS上实现相同的目标。那里有正确的链接器选项?

macos unit-testing mocking dynamic-linking linker-flags
1个回答
0
投票

[目前,通过将resolved添加到__attribute__((noinline))bar),并与commit-Wl,-flat_namespace)链接为commit。实际上不需要-export_dynamic

© www.soinside.com 2019 - 2024. All rights reserved.