- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图弄清楚我在使用 make 时一直遇到的错误。我有几个源文件位于 assign1
目录以及一个 includes
目录(包含 bb.h
)。我想做的是在创建 gq.o
文件时包含 bb.h
头文件。由于此错误,除 gq.o
外,所有其他目标文件都可以正常编译:
z1755294@hopper:~/assign1/assign1$ make
g++ -c fr.cc
g++ -c vw.cc
g++ -c ac.cc
g++ -c pg.cc
g++ -c gq.cc -I./includes
g++ -o output fr.o gq.o vw.o ac.o pg.o
gq.o: In function `main':
gq.cc:(.text+0x0): multiple definition of `main'
fr.o:fr.cc:(.text+0x0): first defined here
vw.o: In function `main':
vw.cc:(.text+0x0): multiple definition of `main'
fr.o:fr.cc:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
Makefile:12: recipe for target 'output' failed
make: *** [output] Error 1
这是我的生成文件:
output: fr.o vw.o ac.o pg.o gq.o
g++ -o fr.o gq.o vw.o ac.o pg.o output
fr.o: fr.cc pg.h
g++ -c fr.cc
vw.o: vw.cc ac.h
g++ -c vw.cc
ac.o: ac.cc ac.h pg.h
g++ -c ac.cc
pg.o: pg.cc pg.h
g++ -c pg.cc
gq.o: gq.cc ac.h includes/bb.h
g++ -c gq.cc -I./includes/bb.h
clean:
-rm *.o
fr.cc, gq.cc and vw.cc all have main functions inside each of them.
ac.cc and fr.cc both have fl(); function they have in common.
gq.cc and vw.cc both have x2(); function they have in common.
我不允许编辑以下任何文件。目标是创建一个 makefile,这样如果 bb.h 文件被某人更改,makefile 仍然可以工作。
这是每个文件的文件结构:
ac.cc
#include "ac.h"
#include "pg.h"
#include <iostream>
using std::cout;
using std::endl;
void y7(void)
{
cout << "y7()" << endl;
}
void x2(void)
{
cout << "x2()" << endl;
f1();
}
交流
void y7(void);
void x2(void);
fr.cc
#include <iostream>
using std::cout;
using std::endl;
#include "pg.h"
int main()
{
cout << "program fr" << endl;
f1();
return 0;
}
gq.cc
#include <iostream>
using std::cout;
using std::endl;
#include "ac.h"
#include "bb.h"
int main()
{
cout << "program gq" << endl;
x2();
cout << "CONST111: " << CONST111 << endl;
cout << "CONST222: " << CONST222 << endl;
return 0;
}
pg.cc
#include "pg.h"
#include <iostream>
using std::cout;
using std::endl;
void f1(void)
{
cout << "f1()" << endl;
}
void g3(void)
{
cout << "g3()" << endl;
}
pg.h
void f1(void);
void g3(void);
大众汽车网
#include <iostream>
using std::cout;
using std::endl;
#include "ac.h"
int main()
{
cout << "program vw" << endl;
x2();
return 0;
}
包含/bb.h
define CONST111 42
#define CONST222 84
最佳答案
改变
gq.o: gq.cc ac.h bb.h
g++ -c gq.cc -I./includes/bb.h
到
gq.o: gq.cc ac.h
g++ -c gq.cc -I./includes
或
gq.o: gq.cc ac.h includes/bb.h
g++ -c gq.cc -I./includes
构建失败的原因是 bb.h 不在同一目录中。您将 bb.h
列为要求,但由于它不存在,因此尝试生成它但找不到合适的规则。您需要不将 bb.h
列为要求,或者指定文件及其路径,以便 make 看到它存在。您还需要仅使用 -I./includes
指定 g++ 将在其中查找 bb.h
的搜索目录。
你还需要改变这个:
output: fr.o vw.o ac.o pg.o gq.o
g++ -o fr.o gq.o vw.o ac.o pg.o output
问题很多。首先也是最重要的是,您试图将对象与冲突的符号链接(symbolic link)起来,并且您对 -o
标志的使用是错误的。根据评论和您的编辑,我认为您想要的是:
output: fr.o vw.o ac.o pg.o gq.o
g++ -o fr fr.o pg.o
g++ -o gq gq.o ac.o pq.o
g++ -o vw vw.o ac.o pg.o
这将产生三个二进制文件,fr
、gq
和 vw
,以 main()< 中的三个文件命名
符号。每个仅列出解析外部符号所需的对象。
关于c++ - Makefile 头目录错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32419413/
我有一个 Makefile,它针对特定目标调用另一个 Makefile。假设主 Makefile 包含 some_dir/some_target: cd some_dir && make so
这两个文件大多出现在开源项目中。 它们的用途是什么?它们如何工作? 最佳答案 Makefile.am 是程序员定义的文件,由 automake 使用来生成 Makefile.in 文件( .am 代表
我的源代码位于一堆子目录中,例如: src/widgets/apple.cpp src/widgets/knob.cpp src/tests/blend.cpp src/ui/flash.cpp 在项
这就是我所拥有的: SUBDIRS = src/lib/ResourceManager all: $(SUBDIRS) $(SUBDIRS): make install -C $@ 我正在尝试
我想写一个 Makefile 来执行来自两个不同数组的两个输入的命令例如 a = A B C b = 1 2 3 ./run A 1 ./run B 2 ./run C 3 我不知道怎么写,因为在Ma
在 GNU make 手册的早期部分之一,Section 3.7 , 有一个 makefile 配方的大纲 immediate : immediate ; deferred defer
是否存在将 gmake 的 GNU Makefile 转换为可用于 make (FreeBSD-make) 的 Makefile 的实用程序? 最佳答案 该实用程序称为开发人员(程序员,制作大师,..
所以我前段时间了解了什么是 Makefile,创建了一个模板 Makefile,我所做的就是为我正在执行的每个程序复制和更改相同的文件。我改了几次,但它仍然是一个非常粗糙的Makefile。我应该如何
我正在做一些 Makefile 重构,并试图找出最简洁的方法来实现一个 Makefile,它执行以下操作: 有一个变量列出了所有源文件(可以是 C 和 C++ 文件) 所有目标文件都在 OBJ_DIR
我正在尝试创建一个 Makefile,它将通过 tic 编译位于目录中的 terminfo 文件。 tic 还将它自动创建的 termcap 文件复制到系统或用户特定的目标文件夹。对于普通用户,如果
我想要类似的东西 BROKEN_THINGS = \ thing1 \ # thing1 is completely broken thing2 \ # thing2 is broken to
如果我的程序必须为不同的结果(主要是错误)返回不同的值(例如 0、1、2、3 等),则调用该程序的 makefile 将不得不停止执行其余的 makefile 命令。即使该命令产生错误(返回非零值),
我正在学习使用漂亮的 Linux 工具:make。还有一点我想了解的: 让我们看一下这个简单的例子: JADE = $(shell find pages/*.jade) HTML = $(JADE:.
假设您有一个包含两个伪目标“all”和“debug”的 Makefile。 'debug' 目标旨在构建与 'all' 相同的项目,除了一些不同的编译开关(例如 -ggdb)。由于目标使用不同的编译开
我有一个调用多个其他生成文件的生成文件。 我想将 -j 参数传递给其他 makefile 调用。 类似(make -j8): all: make -f libpng_linux.mk -j
我处理过的 Makefile 大部分都很复杂,并且隐藏了很多关系。我自己从来没有写过一个,想知道是否有人有一些关于编写易于阅读和可重用的 Makefile 的提示? 最佳答案 我通常使用这样的东西,在
嘿,我有一个简单的“主” Makefile,它只是调用其他 makefile。我正在尝试执行以下操作,以便以正确的顺序构建组件: LIB_A = folder_a LIB_B = folder_b L
生成文件: #there is a whitespace after "/my/path/to" FOO = "/my/path/to" BAR = "dir" INCLUDE_DIRS = $(FO
我正在学习 makefile,我知道如何创建一个简单的 makefile。我正在继续使用嵌套的 makefile。这是我的目录结构 /src ...makefile ...main.cpp ...fo
什么TEMP0_FILES下面计算到? SOURCE_FILES可以等于多个源文件。请告诉我以下语法 :.cpp=.o 的用途 SOURCE_FILES = main.cpp TEMP0_FILES
我是一名优秀的程序员,十分优秀!