在构建dll时可以设置很多选项,但是如果您从命令行执行此操作,则可以使用这个基本命令:
gcc -shared -o mydll.dll file1.o file2.o file3.o
这是一个makefile(通常称为 Makefile ),它将处理整个构建过程:
# You will have to modify this line to list the actual files you use.
# You could set it to use all the "fileN" files that you have,
# but that's dangerous for a beginner.
FILES = file1 file2 file3
OBJECTS = $(addsuffix .o,$(FILES)) # This is "file1.o file2.o..."
# This is the rule it uses to assemble file1.o, file2.o... into mydll.dll
mydll.dll: $(OBJECTS)
gcc -shared $^ -o $@ # The whitespace at the beginning of this line is a TAB.
# This is the rule it uses to compile fileN.cpp and fileN.h into fileN.o
$(OBJECTS): %.o : %.cpp %.h
g++ -c $< -o $@ # Again, a TAB at the beginning.
现在要构建 mydll.dll ,只需输入"make"即可 .
几个笔记 . 如果只键入"make"而不指定makefile或目标(要构建的东西),Make将尝试使用默认的makefile("GNUMakefile","makefile"或"Makefile")和默认目标(makefile中的第一个,在这种情况下) mydll.dll ) .