简体   繁体   中英

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. 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).

I am trying to bring the library to work with my C code. I have included one of the headers n my C program like #include "kyber/kyber512_90s/api.h". The particular api.h header declares a function that I need to use in my C code. 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

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). There are 2 option.

  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. I dont know which build configuration are you using with make but if for Cmake but if for 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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