- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在 Ubuntu 下使用 Eclipse。
我刚刚安装了 cmocka:
Install the project...
-- Install configuration: "Debug"
-- Installing: /usr/lib/pkgconfig/cmocka.pc
-- Installing: /usr/lib/cmake/cmocka/cmocka-config.cmake
-- Installing: /usr/lib/cmake/cmocka/cmocka-config-version.cmake
-- Installing: /usr/include/cmocka.h
-- Installing: /usr/include/cmocka_pbc.h
-- Installing: /usr/lib/libcmocka.so.0.3.1
-- Installing: /usr/lib/libcmocka.so.0
-- Installing: /usr/lib/libcmocka.so
当我构建一个简单的测试项目时,出现链接器错误。从这段代码
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "factorial.h"
static void test_factorial_zeo()
{
assert_int_equal(factorial(0), 1);
}
int main(int argc, char **argv)
{
const UnitTest tests[] =
{
unit_test(test_factorial_zeo),
};
return run_tests(tests);
}
我收到这些错误:
make all
Building target: unit_test_C_code_example_project
Invoking: GCC C Linker
gcc -o "unit_test_C_code_example_project" ./test_scripts/test_factorial.o ./software_under_test/factorial.o
./test_scripts/test_factorial.o: In function `test_factorial_zeo':
/home/me/workspace/unit_test_C_code_example_project/Debug/../test_scripts/test_factorial.c:10: undefined reference to `_assert_int_equal'
./test_scripts/test_factorial.o: In function `main':
/home/me/workspace/unit_test_C_code_example_project/Debug/../test_scripts/test_factorial.c:20: undefined reference to `_run_tests'
collect2: ld returned 1 exit status
make: *** [unit_test_C_code_example_project] Error 1
**** Build Finished ****
所以,看来我应该将 cmocka 库添加到链接器路径中。但后来我得到
make all
Building target: unit_test_C_code_example_project
Invoking: GCC C Linker
gcc -o "unit_test_C_code_example_project" ./test_scripts/test_factorial.o ./software_under_test/factorial.o -llibcmocka.so.0.3.1
/usr/bin/ld: cannot find -llibcmocka.so.0.3.1
collect2: ld returned 1 exit status
make: *** [unit_test_C_code_example_project] Error 1
**** Build Finished ****
我用 libcmocka.so.0.3.1、libcmocka.so.0 和 libcmocka.so 得到了相同的结果
显然,我在做一些非常基本的错误,但是什么?
ls -lAF /usr/lib/libcmocka.so*
lrwxrwxrwx 1 root root 14 Oct 21 15:03 /usr/lib/libcmocka.so -> libcmocka.so.0*
lrwxrwxrwx 1 root root 18 Oct 21 15:03 /usr/lib/libcmocka.so.0 -> libcmocka.so.0.3.1*
-rwxrwxrwx 1 root root 77216 Oct 21 15:02 /usr/lib/libcmocka.so.0.3.1*
最佳答案
好的,我找到了答案 here并将引用它:
The -L option works like a search path for libraries, just like $PATH in the shell is a search path for executable files.
And just like the shell has a default search path, the linker also has a default library search path, with should include /usr/lib. So you should not even need to have to use a -L/usr/lib option. The reason why that did not work for you is that you use a full path with the -l option.
Normally with the -l option the "extension" is left out from the file name, as well the lib prefix, and the directory.
因此,在我的例子中,我告诉 Eclipse 与 cmocka
链接,这导致使用此命令生成 makefile
gcc -L/usr/lib -o "unit_test_C_code_example_project" ./test_scripts/test_factorial.o ./software_under_test/factorial.o -lcmocka
链接成功
当然,我知道这个,但是忘记了。哦!
关于c - 我如何与 cmocka 链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33260973/
我在文档和服务员示例中进行了搜索,但找不到有关如何检查正确的函数指针是否作为参数传递给函数的示例。 这个示例代码应该详细说明我的意思: void func_A(); void func_B(); vo
我已经下载了 cmocka example files并按照所有说明进行操作。所有测试文件都已成功生成,我可以运行它们,但控制台中没有输出。我曾尝试更改 CMOCKA_MESSAGE_OUTPUT 环
假设我声明了一个名为 foo 的 C 结构,它有一个名为 bar 的 int 字段和一个名为 baz 的 char *。 我如何使用 Cmocka expect_ 和 check_expected 宏
我正在开发一个项目 using the cmocka framework 。 cmocka主页指出 Test fixtures are setup and teardown functions tha
我有一个包含两个数据成员的简单结构。 typedef struct { int32_t x; int32_t y; } MyStructType; 我有一个按值返回结构的函数。 MyS
我正在使用 cmocka用于测试一些嵌入式 C 代码的库。根据文档,我使用 __wrap_ 前缀来模拟函数,这样我就可以隔离我的单元测试。但是,一旦我这样做,所有对该函数的调用将永远转到包装函数。我如
一点背景知识:我希望对构建到共享对象文件中的代码进行单元测试,例如libabc。此代码还调用 libjson-c 和 libcurl 函数。 我计划为产品代码中的每个函数编写函数测试,模拟从 liba
我正在尝试使用 cmocka 对一些源代码进行单元测试。基本上(相关的)源代码看起来类似于 Source.c。 单元测试分别调用每个函数。在测试 Add() 函数时,此函数最终将调用 util_mal
我正在尝试使用 cmocka 库在 c 中编写一个测试用例。我的测试用例正在测试一个函数,然后在内部调用来自第 3 方库的函数(无法修改库)。当应用程序不是时,此函数返回 NULL 值启动并运行,所以
我在 Ubuntu 下使用 Eclipse。 我刚刚安装了 cmocka: Install the project... -- Install configuration: "Debug" -- In
我刚刚开始使用 Cmocka,我已经在这个问题上停留了一段时间。我有一个正在尝试构建的 cmocka 项目。当我尝试使用“make”时,我看到了错误。 [ ERROR ] --- No entries
我有一个小型静态库项目,我正在将其从使用 Makefile 构建改写为现代 CMake,我正在尝试学习它。我的项目大量使用断言来检查先决条件,因此我编写了一个非常简单的自定义断言宏,它有条件地扩展为一
我正在学习 cmocka 单元测试框架。我对 mock() 函数的使用有点困惑。有人可以用合适的例子清楚地解释为什么以及如何使用它吗?还请说明何时应该使用它。 最佳答案 你应该阅读 https://l
我最近遇到了'cmocka ' C 的模拟库。我能够模拟单个函数并成功测试调用函数。现在我需要它来将它用于我正在从事的项目,在该项目中需要模拟大量功能。如何将我想要模拟的所有函数传递给 Linker
我能够使用 cmocka 并在屏幕上获得默认结果。我想获得 JUnit 格式的单元测试结果。 CMocka 通过使用环境变量 CMOCKA_MESSAGE_OUTPUT 或使用 API cmocka_
我很难使用 cmocka、测试 malloc 的失败(模拟)和使用 gcov 来找到一个小问题的答案 关于 cmocka+gcov 的更新:我注意到在我的 cmocka 测试中模拟一个函数后,我得到了
我安装了 CMocka testing framework并尝试了 sample code : #include #include #include #include /* A test ca
因此,玩具程序复制了我使用 cmocka 为现有代码开发单元测试时遇到的问题。问题是嵌套函数调用不模拟,这使得单元测试依赖于嵌套函数调用的正确执行。请注意,使用“mockable_static”定义是
我正在尝试在 Mac OSX Yosemite 10.10.3 上安装并运行 cmocka 库进行单元测试,但是我在 RPATH 方面遇到了一些问题设置。 更新: 感谢@baf,我能够像这样手动将 c
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我是一名优秀的程序员,十分优秀!