生成文件创建(的.so)从现有的文件的文件 [英] makefile for creating (.so) file from existing files

查看:179
本文介绍了生成文件创建(的.so)从现有的文件的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4个文件: 1.C 1.H 2.C 2.H
我需要一个makefile,这将创造不同于4个文件一个动态库(的.so)。
我试图写一个makefile是这样的:

I have 4 files: 1.c, 1.h, 2.c, 2.h. I need a makefile, which will create a dynamic library (.so) from those 4 files. I have tried to write a makefile like this:

library.so:1.C 2.C 1.H 2.H

library.so : 1.c 1.h 2.c 2.h

但它没有工作。这将是巨大的,如果有人可以帮助我,谢谢。

but it did not work. It would be great, if someone helps me, thanks.

推荐答案

类似

 CC=gcc
 CFLAGS= -Wall -g -O -fPIC
 RM= rm -f
 .PHONY: all clean

 all: library.so
 clean:
      $(RM) *.o *.so

 library.so: 1.o 2.o
      $(LINK.c) -shared $< -o $@

 1.o: 1.c 1.h 2.h

 2.o: 2.c 1.h 2.h

但是,这是未经测试!我假设的Linux与 GNU使,并且只包含源$ C ​​$ C目录您的库(与上面的的Makefile ),这可能是不好的做法 - 你可能想测试病例(你可以有一个特殊的的Makefile %的规定。pic.o 根据。%,C ,等...)

But this is untested! I am assuming Linux with GNU make, and a directory containing only the source code of your library (with the above Makefile), which might be bad practice -you might want a test case- (you could have a special Makefile rule for %.pic.o depending on %.c, etc...)

提示:使用使-p 来理解内置规则。然后使--trace 或(与翻拍重拍-x 来了解多一点什么制作正在做什么。

Hints: use make -p to understand the builtin rules. Then make --trace or (with remake) remake -x to understand a bit more what make is doing.

阅读也 Drepper的文章:如何写共享库,的 GNU的文档使,的程序库方法文档这个答案, ...

Read also Drepper's paper: How to Write Shared Libraries, documentation of GNU make, Program Library HowTo, this answer, ...

这篇关于生成文件创建(的.so)从现有的文件的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆