c - 未定义对 '<function>' 的引用

标签 c undefined-reference jam

我正在编写一大段代码。当我使用 jam 命令编译代码库时,出现很多错误,提示代码库中新添加的头文件中未定义对“some_function”的引用。该头文件包括所有其他相关的头文件。在编译代码库之前,我是否需要对 jam 文件进行更改?

bundlemgr_distrib_im.c:

#include "bundlemgr_distrib_config.h"
.
.
function{
.
.
retcode = bmd_cfg_init_active(bmd_im_evh);
.
.
}

bundlemgr_distrib_config.h:

cerrno bmd_cfg_init_active(event_mgr_p evh); //declaration

bundlemgr_distrib_config.c

#include "bundlemgr_distrib_config.h"
.
.
cerrno bmd_cfg_init_active(event_mgr_p evh)
{
//definition
}

构建日志:

...failed Link bundle/bundlemgr/test/obj-x86/bm_ut_distrib_attr ...
...skipped <installed!rp>bm_ut_distrib_attr for lack of <bundle!bundlemgr!test!obj-x86>bm_ut_distrib_attr...
.
.
bugfix/./bundle/bundlemgr/distrib/src/bundlemgr_distrib_im.c:269: undefined reference to `bmd_cfg_init_active'

另一个错误:

bundlemgr_distrib_acc_private.h(新添加的文件)

#include "bundlemgr_distrib_db_api.h"
#include "bundlemgr_distrib_db_private.h"
.
.
function{
.
.
rc = bmd_db_bdl_change_ifh(entry, ifhandle);
.
.
}

bundlemgr_distrib_db_private.h

cerrno bmd_db_bdl_change_ifh(bmd_db_bdl_h_type  entry,
                          ifhtype            ifhandle); //declaration

bundlemgr_distrib_db_api.c

#include "bundlemgr_distrib_db_private.h"
.
.
cerrno  
bmd_db_bdl_change_ifh (bmd_db_bdl_type *entry,                                                                                                                                                                                          
                    ifhtype          ifhandle)
{
//definition
}

构建日志:

...failed Link bundle/bundlemgr/test/obj-x86/bm_ut_distrib_attr ...
...skipped <installed!rp>bm_ut_distrib_attr for lack of <bundle!bundlemgr!test!obj-x86>bm_ut_distrib_attr...
Link bundle/bundlemgr/test/obj-x86/bm_ut_distrib_mbr_info
bundle/bundlemgr/test/obj-x86/bundlemgr_distrib_test_errdis_owner.o: In function `bmd_acc_bdl_set_ifhandle':
/nobackup/pzambad/ci-521-bugfix/./bundle/bundlemgr/distrib/src/bundlemgr_distrib_acc_private.h:3618: undefined reference to `bmd_db_bdl_change_ifh'

最佳答案

您需要告诉链接器在哪里可以找到与这些 header 相关的库文件。通常会有一个包含所需库的/lib 目录。随着Gnu toolchain使用 -l 包含特定库,或使用 -L 添加库路径。

关于c - 未定义对 '<function>' 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23687006/

相关文章:

c - 是否允许 C 编译器优化冗余语句?

c++ - 为什么模板只能在头文件中实现?

c++ - 为什么创建 friend 类的实例会导致 "undefined reference to"错误?

boost - 在 Boost Jam 文件中将多个静态库组合成单个共享库

cross-platform - 从 Jam 迁移到 CMake

permissions - C/Unix : How to extract the bits from st_mode?

C——汇编消息

将不带引号的斜杠转换为换行符,无需 strtok 或进一步分配内存

C++/Mysql 连接器 : undefined reference to `get_driver_instance'