简体   繁体   English

将库链接到 C 代码会在生成过程中出错

[英]Linking of a Library into C code gives error during make

I have a C program (test.c) and I have a library that I want to bring into the code.我有一个 C 程序(test.c),我有一个库,我想将其引入代码中。 In this library, there are many headers and functions.在这个库中,有很多头文件和函数。 I can build this library and test the examples.我可以构建这个库并测试示例。 using the make command included into it.( It works well).使用其中包含的 make 命令。(效果很好)。

I am trying to bring the library to work with my C code.我正在尝试使该库与我的 C 代码一起使用。 I have included one of the headers n my C program like #include "kyber/kyber512_90s/api.h".我在我的 C 程序中包含了一个标题,例如#include“kyber/kyber512_90s/api.h”。 The particular api.h header declares a function that I need to use in my C code.特定的 api.h header 声明了一个 function ,我需要在我的 Z0D61F8370CAD1D4E125D 代码中使用它。 When I compile this project, I get an error which says "compiler cannot locate the source of pairs()" where pairs() is a function well declared in api.h当我编译这个项目时,我收到一条错误消息,提示“编译器无法找到pairs() 的源”,其中pairs() 是在api.h 中声明的function

I feel like I need to link the library to compile with my Code as one but I do not know how to do it.我觉得我需要链接库以与我的代码一起编译,但我不知道该怎么做。 Any help on this will be greatly appreciated对此的任何帮助将不胜感激

You said you already have a library including source code.c file and.h file and if it is official lib as usual you will have a binaries file of lib let said... api.a, api.so or api.dll (window). You said you already have a library including source code.c file and.h file and if it is official lib as usual you will have a binaries file of lib let said... api.a, api.so or api.dll (窗户)。 There are 2 option.有2个选项。

  1. Link that lib in Linker Options( Recommended) Now you need to link the lib api.so which tell compiler where to look for symbol when linking.在 Linker 选项中链接该库(推荐) 现在您需要链接库 api.so,它告诉编译器在链接时在哪里寻找符号。 I dont know which build configuration are you using with make but if for Cmake but if for CmakeList我不知道您使用的是哪个构建配置,但如果用于 Cmake 但如果用于 CmakeList

    target_link_libraries(your_exe_name,api_lib_name)

  2. Rebuild lib and add directly it executable, that way you need api.c so you need to add api.c to your source project, but you might need many dependencies as api required. Rebuild lib and add directly it executable, that way you need api.c so you need to add api.c to your source project, but you might need many dependencies as api required.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM