[英]makefile : How to link object files
I have makefile and I need to link two objects into "main" object我有 makefile,我需要将两个对象链接到“主”对象
They are -> oglinet.o and libshape.o它们是 -> oglinet.o 和 libshape.o
their path in system -> home/pi/openvg/他们在系统中的路径 -> home/pi/openvg/
Problem :I need to write full path and objects name(home/pi/openvg/libshapes.o) is possible to "make" them as Makefile variable for example home/pi/openvg/libshape.o into $(OBJ1) in makefile rule ?问题:我需要写入完整路径和对象名称(home/pi/openvg/libshapes.o)可以将它们“制作”为 Makefile 变量,例如 home/pi/openvg/libshape.o 到 $(OBJ1) 中的 makefile规则 ?
Tried to make them as variable for example Obj1= /home/pi/openvg/oglinit.o if I compile that the compilator freeks out.试图将它们作为变量,例如 Obj1= /home/pi/openvg/oglinit.o 如果我编译编译器释放出来。
Working Makefile工作生成文件
#NOT IDEAL MAKEFILE BUT WORKING!!!!!
INCLUDEFLAGS = -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -I/home/pi/openvg
LIBFLAGS = -L/opt/vc/lib -lbrcmEGL -lbrcmGLESv2 -lbcm_host -lpthread -ljpeg
main:main.cpp
g++ -Wall $(INCLUDEFLAGS) -o main main.cpp $(LIBFLAGS) home/pi/openvg/libshapes.o /home/pi/openvg/oglinit.o
Expectations: what libshape.o and oglinit.o objects and thei path in system are "stored" in some kind of variable/variables and if I need I can easily make changes in makefile /期望:系统中的 libshape.o 和 oglinit.o 对象及其路径“存储”在某种变量/变量中,如果我需要,我可以轻松地在 makefile /
After help of Chriss Dodd (not ideal?) makefile looks like this在 Chriss Dodd(不理想?)的帮助下,makefile 看起来像这样
INCLUDEFLAGS = -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads -I/home/pi/openvg
LIBFLAGS = -L/opt/vc/lib -lbrcmEGL -lbrcmGLESv2 -lbcm_host -lpthread -ljpeg
OPENVG=/home/pi/openvg
App: main.cpp $(OPENVG)/libshapes.o $(OPENVG)/oglinit.o
g++ -Wall -o $@ $^ $(LIBFLAGS) $(INCLUDEFLAGS)
You usually want to make all the object files you're linking dependencies of the target.您通常希望将所有目标文件链接到目标的依赖项。 Then you can just use
$^
.然后你可以使用
$^
。 You also usually want all the libraries after all the object files on the linker command line.您通常还需要链接器命令行上所有目标文件之后的所有库。 With both of those you end up with something like:
有了这两个,你最终会得到类似的东西:
OPENVG=/home/pi/openvg
main: main.o $(OPENVG)/libshape.o $(OPENVG)/objinit.o
g++ -Wall -o $@ $^ $(LIBFLAGS)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.