Linux 用于编译共享对象库文件的简单 makefile
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10803109/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Simple makefile for compiling a shared object library file
提问by pythonic
I need a very simple makefile to compile a shared object library file (*.so). I also need to know how to pass optimization parameters like -O2 and -O3. I tried to search for simple examples using google, but all examples are twisted.
我需要一个非常简单的 makefile 来编译共享对象库文件 (*.so)。我还需要知道如何传递优化参数,如 -O2 和 -O3。我试图用谷歌搜索简单的例子,但所有的例子都是扭曲的。
I don't need to create any version like *.so.1.0 but only a simple *.so file. My project would have multiple files, so I need an example which compiles multiple files.
我不需要创建像 *.so.1.0 这样的任何版本,而只需要创建一个简单的 *.so 文件。我的项目会有多个文件,所以我需要一个编译多个文件的例子。
采纳答案by Rob?
The simplest makefile that I can think of that does what you want:
我能想到的最简单的 makefile 可以满足您的需求:
CXXFLAGS += -fPIC
CXXFLAGS += -O3
x.so: x.o y.o
g++ -shared $^ -o $@
In the alternative, you may want to use more of make's built-in rules and variables:
或者,您可能希望使用更多 make 的内置规则和变量:
CXXFLAGS += -fPIC
CXXFLAGS += -O3
x.so: x.o y.o
$(LINK.cc) -shared $^ $(LOADLIBES) $(LDLIBS) -o $@