make说找不到makefile

squal171925 2005-07-19 09:19:30
怎么把多个文件连接成一个可执行文件???
我建了一个工程
有四个文件
编译后生成一个可执行文件
然后make makefile
make说找不到makefile
???????
不知道为什么
明明有makefile么
...全文
1278 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jagen在路上 2005-07-19
  • 打赏
  • 举报
回复
同意大家
LoveCreatesBeauty 2005-07-19
  • 打赏
  • 举报
回复
make -f filename

使用 -f 选项指定自己的make file文件名。如果没有该选项,它假定默认的文件名为 `makefile`
hzhxxx 2005-07-19
  • 打赏
  • 举报
回复
1. 说明
1.1 这里演示怎么去建立一个 GCC 的工程文件体系,并能使用 gcc autotools
工具编译对应的文件,形成可执行的文件。我们以工程 hello 为例子.

1.2 注意
1.2.1 目录和文件名都区分大小写,文件内容也区分.
1.2.2 每一个目录下面对应只要一个 Makefile.am 作为配置文件
1.2.3 全部配置只要一个 configure.in 文件

2. 目录和对应文件结构:
hello(dir)
|---src(dir)
|---hello.cpp(file)
|Makefile.am(file)
|---util(dir)
|str.cpp(file)
|str.h(file)
|Makefile.am
|configure.in(file)
|Makefile.am(file)


3. 配置文件内容解释
3.1 hello/src/hello.cpp 内容,实现了程序入口

#include <iostream>
//使用相对路径调用自定义头文件
#include "../util/str.h"
#include <iostream>
//使用相对路径调用自定义头文件
#include "../util/str.h"
using namespace std;

int
main (void)
{
std::cout << "Hello World !" << endl;
//调用其他文件类
CStr str;
for (int i = 0; i < 5; i++)
{
str.Insert ("Item");
}
str.Pop ();
std::cout << "Execute Successed !" << endl;
std::cout << "aaaaaaaa" << endl;
exit (EXIT_SUCCESS);
}

3.2 hello/src/Makefile.am 内容
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=hello
# 假如要使用多个文件,请使用空格隔开,一般头文件
# 不要写,但是假如头文件包含实现,就需要写入
hello_SOURCES=hello.cpp
# 假如包含多个库搜索路径,需要使用空格隔开.
# -L 是引入库的标志
LDFLAGS=-L../util
# 假如包含多个库,需要使用空格隔开.
# -L 是引入库的标志
LIBS=-lutil

3.3 hello/util/str.h 内容,主要定义了调用的 CStr 类
#include <string>
#include <vector>

class CStr
{
private:
std::vector<std::string> m_strs;
protected:
//
public:
void Insert(const std::string astr);
void Pop();
};

3.4 hello/util/str.cpp 内容,主要实现了 CStr 类

#include <iostream>
#include "str.h"

using namespace std;


void
CStr::Insert (const std::string astr)
{
m_strs.push_back (astr);
}


void
CStr::Pop ()
{
for (std::vector < std::string >::iterator it = m_strs.begin ();
it != m_strs.end (); it++)
{
std::cout<<*it<<endl;
}
}

3.5 hello/util/Makefile.am 文件,定义了生成对应的 Makefile.in 的基本配置
AUTOMAKE_OPTIONS=foreign
#编译为静态库文件
noinst_LIBRARIES=libutil.a
#需要的源文件
libutil_a_SOURCES=str.cpp
# 参数
CFLAGS=-O2
CXXFLAGS=-O2


3.6 hello/Makefile.am 文件
AUTOMAKE_OPTIONS=foreign
#定义需要两个目录
SUBDIRS=util src

3.7 hello/configure.in 文件
dnl Process this file with autoconf to produce a configure script.

AC_INIT(src/hello.cpp)
AM_INIT_AUTOMAKE(hello,1.0)

dnl Checks for programs.
AC_PROG_CC
AC_PROG_CXX

dnl Checks for libraries.
AC_PROG_RANLIB

dnl Checks for header files.

dnl Checks for typedefs, structures, and compiler characteristics.

dnl Checks for library functions.

dnl 定义需要检查两个子目录下面的 Makefile 文件
AC_OUTPUT(Makefile src/Makefile util/Makefile)

4. 生成执行文件 Makefile(全部命令在 hello 目录下执行)
4.1 acloacl
运行 aclocal,生成 aclocal.me 和 autom4te.cache
4.2 autoconf
运行 autoconf,生成 configure 可执行文件
4.3 automake
运行 automake --add-missing 生成 depcomp,install-sh,missing
4.4 configure
运行 ./configure ,自动生成 Makefile
4.5 make
执行 make ,得到对应的自定义库文件和可执行的程序

4.5 执行
src/hello,查看结果


5. 未了结问题
5.1 目标文件 .o 现在和源代码文件 .cpp 放在一起,考虑可以把所有的目标文件放在一个目录
5.2 可执行文件考虑也可以放在一个目录里面
5.3 其他目录的源文件是否可以不编译为库文件,比如 util 下面的所有文件
hilary0810 2005-07-19
  • 打赏
  • 举报
回复
man make 一下你就知道怎么回事了
hjf1010 2005-07-19
  • 打赏
  • 举报
回复
不是make makefile
是make prog(your program)
OpenHero 2005-07-19
  • 打赏
  • 举报
回复
1.你用什么方式生成的程序?
2.makefile可以自己写
3.看makefile里面的参数是否正确
okdavinci 2005-07-19
  • 打赏
  • 举报
回复
同意

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧