`
test_angel
  • 浏览: 49982 次
  • 性别: Icon_minigender_2
  • 来自: 西安
社区版块
存档分类
最新评论

Makefile学习(13)

 
阅读更多

今天就实践一下目标文件依赖在不同文件夹中的文件:

 

 

VPATH的作用:是指定我们在当前目录中如果找不到依赖文件,则在VPATH所指定的文件中找。比如:

我们我们的文件目录结构如下:

make(文件夹)

|——makefile(里面的文件依赖于submake1  submake2文件夹中的文件)

|——submake1(文件夹)

|——submake2(文件夹)

 

则我们只需要在makefile文件开头指定:

VPATH=./submake1 ./submake2

 

例如:

#my first makefile
VPATH= ./submake1 ./submake2
$(warning finish include)
jar:= f10.o  f11.o
$(warning start gcc)
f:f10.o f11.o
	gcc -c $(jar) -o f
f10.o: f.o f1.o f2.o f3.o
	@echo "gcc"
	gcc -o f10.o  f.o f1.o f2.o f3.o
f11.o:f7.o f5.o f6.o f4.o
	@echo "gcc"
	gcc -o f11.o f7.o f5.o f6.o f4.o
$(warning finish gcc)
.PHONY:clean
clean:
	rm f  *.o

 

通过以上代码我们执行的结果如下:

写道
makefile:3: finish include
makefile:5: start gcc
makefile:14: finish gcc
cc -c -o f7.o ./submake2/f7.c
cc -c -o f5.o ./submake2/f5.c
cc -c -o f6.o ./submake2/f6.c
cc -c -o f4.o ./submake2/f4.c
gcc
gcc -o f11.o f7.o f5.o f6.o f4.o
gcc -c f10.o f11.o -o f
gcc: f10.o: linker input file unused because linking not done
gcc: f11.o: linker input file unused because linking not done

 

 

对于其中的" linker input file unused because linking not done"这个问题,造成的原因是因为发f10.o f11.o也是目标文件,所以gcc -c  $(jar) -o f应改为  gcc -o f $(jar)。

 

 

修改后执行上一段代码:

执行make,生成了相应的f10.o  f11.o ,但是还报以下错误:

写道
makefile:3: finish include
makefile:5: start gcc
makefile:14: finish gcc
cc -c -o f.o ./submake1/f.c
cc -c -o f1.o ./submake1/f1.c
cc -c -o f2.o ./submake1/f2.c
cc -c -o f3.o ./submake1/f3.c
gcc
gcc -o f10.o f.o f1.o f2.o f3.o
cc -c -o f7.o ./submake2/f7.c
cc -c -o f5.o ./submake2/f5.c
cc -c -o f6.o ./submake2/f6.c
cc -c -o f4.o ./submake2/f4.c
gcc
gcc -o f11.o f7.o f5.o f6.o f4.o
gcc -o f f10.o f11.o
f10.o: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.text+0x0): first defined here
f10.o:(.rodata+0x0): multiple definition of `_fp_hw'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.rodata+0x0): first defined here
f10.o: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crti.o:(.fini+0x0): first defined here
f10.o:(.rodata+0x4): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.rodata.cst4+0x0): first defined here
f10.o: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.data+0x0): first defined here
f10.o: In function `__data_start':
(.data+0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/i486-linux-gnu/4.4.3/crtbegin.o:(.data+0x0): first defined here
f10.o: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crti.o:(.init+0x0): first defined here
f11.o: In function `__libc_csu_fini':
(.text+0x130): multiple definition of `__libc_csu_fini'
f10.o:(.text+0x130): first defined here
f11.o: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.text+0x0): first defined here
f11.o:(.rodata+0x0): multiple definition of `_fp_hw'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.rodata+0x0): first defined here
f11.o: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crti.o:(.fini+0x0): first defined here
f11.o:(.rodata+0x4): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.rodata.cst4+0x0): first defined here
f11.o: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o:(.data+0x0): first defined here
f11.o: In function `__data_start':
(.data+0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/i486-linux-gnu/4.4.3/crtbegin.o:(.data+0x0): first defined here
f11.o:(.dtors+0x4): multiple definition of `__DTOR_END__'
f10.o:(.dtors+0x4): first defined here
f11.o: In function `__libc_csu_init':
(.text+0x140): multiple definition of `__libc_csu_init'
f10.o:(.text+0x140): first defined here
f11.o: In function `__i686.get_pc_thunk.bx':
(.text+0x19a): multiple definition of `__i686.get_pc_thunk.bx'
f10.o:(.text+0x19a): first defined here
f11.o: In function `main':
(.text+0xb4): multiple definition of `main'
f10.o:(.text+0xb4): first defined here
f11.o: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crti.o:(.init+0x0): first defined here
/usr/lib/gcc/i486-linux-gnu/4.4.3/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
f10.o:(.dtors+0x4): first defined here
collect2: ld returned 1 exit status
make: *** [f] 错误 1

重复定义,可是目前还是不知道怎么改!!!!


对几个依赖文件的说明:

f10.o依赖的文件中f.c包含main方法

f11.o依赖的文件中f7.c包含main方法

其他的文件中都是各自的方法

 

最终目标f依赖于f10.o  f11.0

 

 

 

网上找了找,说可能是我的c文件有问题,可是我不知道怎么改???

 

 

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

    跟我一起写 Makefile 作者:陈皓 整理:祝冬华

    第四部分、Makefile 总述 (13) 一、Makefile里有什么? (13) 1、显式规则。 (14) 2、隐晦规则。 (14) 3、变量的定义。 (14) 4、文件指示。 (14) 5、注释。 (14) 二、Makefile的文件名 (15) 三、引用其它的Makefile &#...

    cc2420*atmega128 看门狗实验

    学习使用AVR单片机的看门狗操作 开发平台 atmega128+cc2420 程序清单 │Makefile 13.78 KB │test4.c 1.23 KB │test4.eep 13 bytes │test4.elf 4.14 KB │test4.hex 811 bytes │test4.lss 5.65 KB ...

    cc2420+atmega128串口通信实验2

    学习使用AVR单片机中断方式实验串口通信 开发平台 atmega128 包含程序 │Makefile 13.78 KB │test6.c 977 bytes │test6.eep 13 bytes │test6.elf 3.93 KB │test6.hex 750 bytes │test6.lss 5.06 ...

    linux驱动学习去开发入门

    我对Makefile不是很了解,是该好好学习学习了! 然后就是make modules 、 make modules_install 。 [root@Tekkaman-Ninja Helloworld]# make modules make -C /home/tekkaman/working/SBC2440/linux-2.6.22.2 M=/...

    cc2420+atmega128定时器实验2

    学习使用AVR单片机的定时器计数器0中断工作方式的基本设置和应用 开发平台 atmega128 程序清单 │Makefile 10.65 KB │test2.c 1.36 KB │test2.eep 13 bytes │test2.elf 4.94 KB │test2.hex 848 bytes...

    Linux应用系统开发及系统调试.txt

    linux系统入门学习 教程简介 Linux应用系统开发及系统调试视频教程共75讲,主要讲解了GNU开发环境基础、Linux高级程序、Linux进程管理、进程间通信、线程、网络编程、HTTP原理、Socket内 核跟踪等内容,全套教程...

    cc2420+atmega128微操作系统实验

    学习使用AVR单片机上运行的一个微操作系统实现走马灯实验 开发平台 atmega128 包含程序 │fun.lst 64.26 KB │fun.o 11.05 KB │main.c 2.04 KB │main.eep 13 bytes │main.elf 8.63 KB │main.hex ...

    cc2420+atmega128 AD转换实验2(中断方式)

    学习使用AVR单片机中断方式实现AD转换 平台 atmega128 使用其自带的10位精度AD 也可用于其他atmega单片机参考 包含程序 │Makefile 13.78 KB │test8.c 2.38 KB │test8.eep 13 bytes │test8.elf 8.38 KB ...

    国嵌笔记。全集全集

    本人学习的国嵌笔记。操作详细! 第一季 精通嵌入式 4 一. 安装tftp服务器 4 二. Samba服务器安装 4 三. NFS服务器 5 四. 安装vsftpd FTP服务器 5 第2季-裸奔吧-ARM 6 一. 安装交叉编译器 6 二. 安装驱动 6 三...

    Vxworks学习笔记

    个人前几年学习Vxworks时,整理的笔记,总给大家了。 1 基于硬盘启动的Vxworks环境搭建 3 2 Vxworks引导盘制作 6 2.1 通过DOS加载VxWorks方法 6 2.2 Bootrom三种类型 7 2.3 VxWorks映象 7 2.4 Bootrom.sys最快制作...

    郭天祥ARM9视频教程(第13和20讲均可观看).docx

    郭天祥ARM9视频教程(第13讲和第20讲均可观看) ARM9视频教程清单: 第一部分 嵌入式系统开发流程概述 第一讲 嵌入式基础知识 1. 嵌入式的定义、特点、应用 2. 嵌入式硬件结构 3. 嵌入式软件结构 第二讲 如何学习...

    learn_c_the_hard_way:《艰难的学习c》中文翻译

    练习 13: Switch语句 练习 14: 函数的编写与使用 练习 15: 指向指针的指针 练习 16: 结构体和结构体指针 练习 17: 堆栈内存分配 练习 18: 指向函数的指针 练习 19: C面向对象的简单实现 练习 20: 非常好用的Debug宏 ...

    unix大全(涵盖了UNIX学习的方方面面)

    3.Makefile工具的使用 4.vi用法集锦 5.SCO核心参数详细说明 6.SCO Unix 制作系统应急盘“Out of inodes”错误的处理 7.SCO TCP/IP网络管理---TCP/IP的启动 8.SCO TCP/IP网络管理---工具介绍 9.SCO TCP/IP网络管理---...

    驱动编程+驱动逆向+驱动保护

    C、书写makefile文件 D、用DDK-Build环境编译 1.3.2为DDK_HelloWorld添加卸载例程-10课 A、输出调试信息-KdPrint B、认识PDRIVER_OBJECT结构 C、注册驱动卸载例程 D、卸载例程回调函数构建 E、查看驱动调试...

    Linux程序设计 第4版.haozip01

    第13章 进程间通信:管道 443 13.1 什么是管道 443 13.2 进程管道 444 13.3 将输出送往popen 445 13.3.1 传递更多的数据 446 13.3.2 如何实现popen 447 13.4 pipe调用 449 13.5 父进程和子进程 451 13.5.1 ...

    Linux程序设计 第4版.haozip02

    第13章 进程间通信:管道 443 13.1 什么是管道 443 13.2 进程管道 444 13.3 将输出送往popen 445 13.3.1 传递更多的数据 446 13.3.2 如何实现popen 447 13.4 pipe调用 449 13.5 父进程和子进程 451 13.5.1 ...

    后台开发核心技术与应用实践

    第二部分(第4~5章)介绍了编译原理和调试方法相关的知识,编译原理包括编译与链接的具体过程、Makefile的编写、目标文件的内容与处理目标文件相关工具的使用,调试方法主要介绍了strace、gdb、top、ps与valgrind...

    后台开发的一些源代码

    第二部分(第4~5章)介绍了编译原理和调试方法相关的知识,编译原理包括编译与链接的具体过程、Makefile的编写、目标文件的内容与处理目标文件相关工具的使用,调试方法主要介绍了strace、gdb、top、ps与valgrind...

    徐晓鑫后台开发技术实践——腾讯

    第二部分(第4~5章)介绍了编译原理和调试方法相关的知识,编译原理包括编译与链接的具体过程、Makefile的编写、目标文件的内容与处理目标文件相关工具的使用,调试方法主要介绍了strace、gdb、top、ps与valgrind...

    后台开发 核心技术与应用实践

    第二部分(第4~5章)介绍了编译原理和调试方法相关的知识,编译原理包括编译与链接的具体过程、Makefile的编写、目标文件的内容与处理目标文件相关工具的使用,调试方法主要介绍了strace、gdb、top、ps与valgrind...

Global site tag (gtag.js) - Google Analytics