构建用于检查测试C框架的库 [英] Building the library for check test C framework

查看:93
本文介绍了构建用于检查测试C框架的库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用 check 框架来测试C应用程序. 为了更好地理解,我在检查包中查看了该示例.它工作正常,但是我不需要自动制作工具-我想通过自己的Makefile对其进行编译(因为我想正确理解检查内容,并且需要将自己的最终应用程序作为OS的软件包使用).也许我可以在那里使用自动生成的Makefile,但是现在,这将是我必须学习的下一件事,而且我准备单元测试的时间受到限制. (然后,当然,我想学习并理解用于生成Makfile,使用configure等的工具).

I started to use check framework for testing C application. For better understanding I went across the example in check package. It is working fine, but I don't need the automake tools - I want to compile it by my own Makefile (since I want to understand the check properly and I need to use my final application as a package of an OS). Maybe I could use there the autogenerated Makefile, but for now, it would be next one new thing I have to learn and I have restricted time for preparing unit tests. (Then, of course, I want to study and understand the tools for generating Makfile, using configure, etc.)

使用我的Makefile构建应用程序时出现问题,我没有为检查功能链接对象:

There is a problem in building application with my Makefile, that I don't have linked the object for check functionality:

/tmp/ccm7cniy.o: In function `test_money_create':
check_money.c:(.text+0x1e): undefined reference to `tcase_fn_start'
check_money.c:(.text+0x79): undefined reference to `_fail_unless'
check_money.c:(.text+0xcc): undefined reference to `_fail_unless'

我发现,在示例应用程序中是带有obj的gcc.由gcc创建的文件check_money-check_money.o:

I found out, that in the example application is the gcc with obj. file check_money-check_money.o, which was created by gcc:

gcc -DHAVE_CONFIG_H -I. -I..     -g -O2 -MT check_money-check_money.o -MD -MP -MF .deps/check_money-check_money.Tpo -c -o check_money-check_money.o `test -f'check_money.c' || echo './'`check_money.c

这是我的问题:它使用依赖项check_money-check_money.Tpo.该文件是由命令./configure生成的,我没有使用.

And here is my problem: it uses the dependency check_money-check_money.Tpo. This file was generating by the command ./configure, which I don't use.

如何创建自己的.o文件以进行检查以成功构建?是否需要为每个应用程序创建此文件?共享库中的某个地方不能是一个吗?

How can I create my own .o file for check to build successfully? It is necessary to create this file for every application? Could not be one, somewhere in shared libraries?

(对不起,如果我的问题是愚蠢的",我在Linux上构建应用程序的经验还很少)

(I am sorry if my question is "stupid", I have small experience by building applications in linux yet)

推荐答案

添加注释作为响应:
请检查是否已安装check框架.如果是这样,您可以尝试使用pkg-config

Adding comment as response:
Please check if you have installed check framework. If so, you could try using pkg-config say

gcc check_money.c `pkg-config --cflags --libs check`

此处pkg-config实用程序将读取.pc文件(在check框架的情况下恰好是check.pc,因此命令中的最后一项表示check)&添加必要的编译器标志(--cflags选项)&库/链接器选项(--libs选项)

Here pkg-config utility will read the .pc file (which happens to be check.pc in case of check framework, thus the last entry in the command says check) & add the necessary compiler flags (--cflags option) & libraries/linker options (--libs option)

希望这会有所帮助!

这篇关于构建用于检查测试C框架的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆