简体   繁体   English

如何将库添加到生成文件

[英]how to add libraries to a make file

I'm editing an example file already in a library. 我正在编辑库中已经存在的示例文件。 Inside the directory of the example, there is a Makefile that I have been using to compile and run the example. 在示例的目录内,有一个Makefile用于编译和运行示例。 I now want to add an additional library to this make file, I have tried copy and pasting the header and .c file into the library folder specified in the Makefile, but it is not finding it. 我现在想向此生成文件添加一个附加库,我尝试将头文件和.c文件复制并粘贴到Makefile中指定的库文件夹中,但找不到它。 Here is the Makefile code: 这是Makefile代码:

CPPFLAGS = -I../../include
CFLAGS = 
LDFLAGS = -L../../lib -L../../lib64
LIBS = -lbsapi

Biometry: main.c
    $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) main.c -o Biometry $(LIBS)

The library that I wanted to add came with a .h file and a .c file. 我要添加的库带有.h文件和.c文件。 I have added those to the ../../include directory and made sure to add this to my code right below the previous #include 我已将它们添加到../../include目录中,并确保将其添加到我的代码中,在先前的#include下方

#include <tpl.h>

I am not sure what I am missing? 我不确定我缺少什么? The program ran properly before the addition of this library. 在添加该库之前,程序可以正常运行。

Libraries are usually first built and installed to your system, so you can later add them to what seems to be LIBS in your Makefile (let's say your library's called "foo", -lfoo ). 库通常是首先构建并安装到系统中的,因此您可以稍后将它们添加到Makefile中看起来像LIBS的库中(假设您的库称为“ foo”,- -lfoo )。

So you've got two options: 因此,您有两种选择:

  1. The "this actually deserves the name library" path: Find or write a Makefile to turn foo.c into a libfoo.so, install that, and then use LIBS= -lbsapi -lfoo , or “这实际上值得名称库”路径:查找或编写一个Makefile将foo.c转换为libfoo.so,进行安装,然后使用LIBS= -lbsapi -lfoo ,或
  2. The "I'm including the source code in my source code and hope that everything builds correctly" path: add foo.o to the things that Biometry needs, and add a recipe on how to build foo.o from foo.c , and add foo.c to your sources: “我将源代码包含在我的源代码中,希望所有东西都能正确构建”路径:将foo.o添加到Biometry需要的东西中,并添加关于如何从foo.c构建foo.o ,以及将foo.c添加到您的源:
CPPFLAGS = -I../../include
CFLAGS = 
LDFLAGS = -L../../lib -L../../lib64
LIBS = -lbsapi

Biometry: main.c foo.o
    $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) main.c foo.o -o Biometry $(LIBS)

foo.o: foo.c
     $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) foo.c -o foo.o $(LIBS)

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

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