簡體   English   中英

將庫鏈接到 C 代碼會在生成過程中出錯

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

我有一個 C 程序(test.c),我有一個庫,我想將其引入代碼中。 在這個庫中,有很多頭文件和函數。 我可以構建這個庫並測試示例。 使用其中包含的 make 命令。(效果很好)。

我正在嘗試使該庫與我的 C 代碼一起使用。 我在我的 C 程序中包含了一個標題,例如#include“kyber/kyber512_90s/api.h”。 特定的 api.h header 聲明了一個 function ,我需要在我的 Z0D61F8370CAD1D4E125D 代碼中使用它。 當我編譯這個項目時,我收到一條錯誤消息,提示“編譯器無法找到pairs() 的源”,其中pairs() 是在api.h 中聲明的function

我覺得我需要鏈接庫以與我的代碼一起編譯,但我不知道該怎么做。 對此的任何幫助將不勝感激

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 (窗戶)。 有2個選項。

  1. 在 Linker 選項中鏈接該庫(推薦) 現在您需要鏈接庫 api.so,它告訴編譯器在鏈接時在哪里尋找符號。 我不知道您使用的是哪個構建配置,但如果用於 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.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM