linux编程GCC、gdb、Makefile、make、

Linux系统中执行cmake ..命令时出现“arm linux ........ command not found“错误 CMake是一个跨平台的构建工具,它能够自动生成用于不同编译器、操作系统和构建系统的构建脚本。在Linux系统上,交叉编译是指在一个平台上开发和构建针对不同平台的应用程序。对于ARM架构的应用程序开发,需要使用ARM交叉编译工具链。通过安装适用于ARM架构的交叉编译工具链,并设置相应的环境变量,我们能够成功地进行ARM应用程序的开发和构建。需要注意的是,安装ARM交叉编译工具链的具体步骤可能因Linux发行版和版本而有所不同。为了解决这个错误,我们需要安装适用于ARM架构的交叉编译工具链。 阅读详情

GCC

gcc是GNU Compiler Collection

gcc [选项] 参数
-o 指定目标文件的名称
-g 使生成的可执行文件中包含debug信息
-c 只编译不连接
-E 只做预处理
-S 由C翻译成汇编
ouc-13@ouc-13:~/hanfeng$ vim main.c
#include<stdio.h>
int main(){
        printf("hello first\n");
        return 0;
}


ouc-13@ouc-13:~/hanfeng$ gcc main.c
#生成了个a.out
# 执行a.out
ouc-13@ouc-13:~/hanfeng$ ./a.out
hello first

ouc-13@ouc-13:~/hanfeng$ gcc -o first main.c
#生成了个first
gcc编译过程
ouc-13@ouc-13:~/hanfeng$ vim main.c
#include<stdio.h>
#define PI 3.14
int main(){
        printf("hello\n");
        return 0;
}
# ===========预编译========得到.i文件===
ouc-13@ouc-13:~/hanfeng$ gcc main.c -E -o main.i
ouc-13@ouc-13:~/hanfeng$ cat main.i | tail -15

extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
# 864 "/usr/include/stdio.h" 3 4
extern int __uflow (FILE *);
extern int __overflow (FILE *, int);
# 879 "/usr/include/stdio.h" 3 4

# 2 "main.c" 2


# 3 "main.c"
int main(){
 printf("hello2\n");
        return 0;
}

# ===========编译=============得到.s文件===
ouc-13@ouc-13:~/hanfeng$ gcc main.i -S
ouc-13@ouc-13:~/hanfeng$ cat main.s | head -15
        .file   "main.c"
        .text
        .section        .rodata
.LC0:
        .string "hello"
        .text
        .globl  main
        .type   main, @function
main:
.LFB0:
        .cfi_startproc
        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
        movq    %rsp, %rbp
# ==========汇编============得到main.o二进制文件=====
ouc-13@ouc-13:~/hanfeng$ gcc main.s -c
# ==========链接============默认得到a.out可执行文件===可以通过-o指定文件名
ouc-13@ouc-13:~/hanfeng$ gcc main.o -o second
ouc-13@ouc-13:~/hanfeng$ ./second
hello2

gcc编译多文件
ouc-13@ouc-13:~/hanfeng$ vim multi.c
#include <stdio.h>
#include "bank.h"
int main(){
        int a=5,b=18,c;
        c=max(a,b);
        printf("a与b的最大值为%d\n",c);
}


ouc-13@ouc-13:~/hanfeng$ vim m.c
int max(int a,int b){
        return a>b?a:b;
}


ouc-13@ouc-13:~/hanfeng$ vim bank.h
int max(int,int);
# 方法1=======多个文件一起编译===实际上上多个源文件分别编译后再链接成test可执行文件
ouc-13@ouc-13:~/hanfeng$ gcc  multi.c m.c -o test
ouc-13@ouc-13:~/hanfeng$ ./test
a与b的最大值为18
# 方法2====分别编译===
gcc -c multi.c # 编译得到multi.o
gcc -c m.c # 编译得到m.o
gcc multi.o m.o -o test # multi.o 和m.o 链接成可执行文件test
struct student{
	int id;
	char name[20];
	float score;
};//定义了一个结构体类型,类型名为struct student

typedef struct student{
	int id;
	char name[20];
	float score;
}STU;//定义了一个结构体类型,类型名为STU

用<>包含的,编译器会从系统目录中寻找头文件,系统目录指的是:
    /usr/lib/gcci686-linux-gnu/4.6/include
    /usr/local/include
    /usr/include/i386-linux-gnu/
    /usr/include/
    
    
用双引号""直接引起来的头文件和源文件在同一个目录下。这样,编译器就会先在该目录(当前工作目录)下搜索,如果找不到再去系统目录下搜索。
    可以写绝对路径,也可以在编译时指定相对路径 gcc -I 相对路径
    也可以将.h文件放到系统目录下,但不推荐

头文件重复包含

如果A.h中包含头文件C.h,B.h也包含了C.h,而源文件中包含了A.h和B.h。

编译时机会报错

  • 如果头文件中重复包含了一些函数的生, 那么在编译时不会出现错误

避免头文件重复包含的解决方法就是在头文件中使用条件编译进行控制:

#ifndef _MY_H//_MY_H_    通常用大写,并且加上适当的下划线;
#define _MY_H_


#endif

gdb

ouc-13@ouc-13:~/hanfeng$ vim gdbtest.c
#include <stdio.h>
int add(int start,int end){
        int i,sum;
        for(i=start;i<=end;i++){
                sum+=i;
        }
        return sum;
}
int main(){
        int result;
        result = add(1,10);
        printf("result=%d\n",result);
        return 0;
}


# -g 使生成的可执行文件中包含debug信息
ouc-13@ouc-13:~/hanfeng$ gcc -o gdbtest gdbtest.c -g
ouc-13@ouc-13:~/hanfeng$ ./gdbtest
result=55 # 不知道这么我正常计算出来了,按理说因为sum没有初始化,所以得不到正确的值。我们就暂且认识他没有得到正确值吧

ouc-13@ouc-13:~/hanfeng$ gdb gdbtest
GNU gdb (Ubuntu 8.2-0ubuntu1) 8.2
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from gdbtest...(no debugging symbols found)...done.
(gdb)
(gdb) run
Starting program: /home/ouc-13/hanfeng/gdbtest
result=55
[Inferior 1 (process 20984) exited normally]
(gdb) start
Temporary breakpoint 1 at 0x555555555166: file gdbtest.c, line 11.
Starting program: /home/ouc-13/hanfeng/gdbtest

Temporary breakpoint 1, main () at gdbtest.c:11
11              result = add(1,10);
(gdb) s # step的简写,执行一条源代码,如果有函数调用,则进入该函数
add (start=1, end=10) at gdbtest.c:4
4               for(i=start;i<=end;i++){
(gdb) bt # 查看栈帧
#0  add (start=1, end=10) at gdbtest.c:4
#1  0x0000555555555175 in main () at gdbtest.c:11

(gdb) i locals # 查看栈顶栈帧add中的局部变量中 # i是info的简写
i = 0
sum = 0
(gdb) frame 1 # 选择1号栈帧
#1  0x0000555555555175 in main () at gdbtest.c:11
11              result = add(1,10);
(gdb) i locals
result = 0

(gdb) frame 0 # 切换回0号栈帧
#0  add (start=1, end=10) at gdbtest.c:4
4               for(i=start;i<=end;i++){
(gdb) i locals
i = 0
sum = 0
(gdb) set var sum=100 # 设置变量sum为100
(gdb) p sum # p为print简写,打印sum的值
$1 = 100
(gdb) finish # 运行到当前函数返回
Run till exit from #0  add (start=1, end=10) at gdbtest.c:4
0x0000555555555175 in main () at gdbtest.c:11
11              result = add(1,10);
Value returned is $2 = 155

# finishi为让程序一直运行到当前函数返回
# continue简写c,为运行到程序结束

设置断点

break <function> 运行到指定函数时停住
break <linenum> 运行到指定行号
break breakpoint [n] 删除某个断点
delete 删除所有断点

可以按照CodeBlocks可视化界面

apt-get install codeblocks
codeblocks

动态库和静态库

链接结点除了会将汇编阶段生成的多个目标文件(.o文件)链接成一个可执行文件,还包括目标文件与库文件进行链接生成可执行文件。

库文件跟.o文件格式类似,因此是一种可执行代码的二进制形式,可以被操作系统载入内存执行。

在linux下,.o文件、可执行文件、库文件都属于一种ELF的文件格式。

使用静态库时,连接器会找出程序锁需要的函数,然后将他们复制到执行文件,由于这种复制是完整的,所以一旦链接成功,静态库在不存在的情况下课执行文件能够正常执行。然后,动态库与静态库截然不同,动态库会在执行文件内留下一个标记指明当程序执行时必须载入的库文件,所以当执行文件指向时才动态加载库文件,而使用动态库必然会节省时间。

同时存在相同库名的静态库和动态库的话,默认将与动态库链接。

静态库是在编译过程中被加载的,锁调用的库函数代码段会成为程序组成部分链接到可执行文件中,并在执行时随可执行程序一起运行

ouc-13@ouc-13:~/hanfeng/clib$ vim bank.h
struct student{
	int id;
	char name[10];
	float score;
};

ouc-13@ouc-13:~/hanfeng/clib$ vim sort.c
#include "bank.h"
void sortaz(struct student stu[], int n){
	int i,j;
	struct student t;
	for(i=0;i<n-1;i++)
		for(j=0;j<n-1;j++){
			if(stu[j].score>stu[j+1].score){
				t=stu[j];
				stu[j]=stu[j+1];
				stu[j+1]=t;
			}
		}
}

ouc-13@ouc-13:~/hanfeng/clib$ gcc sort.c -c
# 或gcc -c sort.c
# 生成.o文件
创建静态库
# 创建静态库并将目标文件加入库中
ar -r 目标库文件名称 目标文件列表
ar -r libmath.a sort.o

ar是创建或操作静态库的命令,选项-r表示将目标文件加入到静态库中,
目标库文件名有个不成文的规定,一般以lib开头,以.a结尾,目标文件列表中的目标文件之间用空格隔开。
-r 将目标文件加入到静态库中
-t 显示静态库中内容
-a 将目标文件追加到静态库文件现有文件之后
-b 将目标文件追加到静态库文件现有文件之前
-d 删除目标文件
-x 提取目标文件
-p 指定文件输出到标准输出
-q 快速地把文件追击到静态库中
使用静态库
方法1:参数法
gcc 主程序 -l 静态库名(去掉lib和.a) -L 静态库存放位置

方法2:直接法
gcc 主程序 静态库全名
# 我们之前已经把排序函数写到了静态库中,我们接下来要使用他

ouc-13@ouc-13:~/hanfeng/clib$ vim main.c
#include <stdio.h>
#include "bank.h" //main.c和bank.h在同一目录中
void main(){
	struct student stu1[5];
	int i;
	for(i=0;i<5;i++){
		printf("请输入第%d和学生学号",i+1);
		scanf("%d",&stu1[i].id);
		printf("请输入第%d和学生名字",i+1);
		scanf("%s",stu1[i].name);//注意没有&
		printf("请输入第%d和学生得分",i+1);
		scanf("%f",&stu1[i].score);
	}
	sortaz(stu1,5);
	for(i=0;i<5;i++){
		printf("姓名:%s,成绩%f\n",stu1[i].name,stu1[i].score);
	}
}


ouc-13@ouc-13:~/hanfeng/clib$ 
gcc main.c -l math -L .   # 静态库全名libmath.a,静态库在当前目录下,生成了a.out的可执行文件
gcc main.c -lmath -L ./ # 这么写也对
gcc main.c libmath.a
gcc main.c -o main libmath.a

动态库

动态库又称共享库,编译时链接动态库,但不加载目标代码,只有在运行时加载相关的目标代码(所调用的库函数)到内容,进程结束时自动施法其所占内存空间。

动态库的创建

仍以sort.c和bank.h为例

# 编辑sort.c bank.h文件

# 生成.o文件
gcc -c -fpic sort.c
-fpic 是将源文件编译成带有PIC标志的目标文件,对于某些版本,C语言编译器可以缺省PIC标志

# 创建动态库
gcc -shared xxxx.o yyyy.o -o libxxx.so
# 也可以合并上面2步
gcc -shared -fpic xxxx.c yyy.c libxxx.so
动态库的使用
方法1:参数法
gcc 主程序 -l 动态库名(去掉lib和.so) -L 动态库存放位置

方法2:直接法
gcc 主程序 动态库全名
# 编译
gcc -c -fpic sort.c
# 生成动态链接库
gcc -shared sort.o -o libmath.so
# 编译主程序
gcc main.c -lmath -L ./
# 执行
./a.out
此时会报错linux动态加载器找不到libmath.so文件
我们知道动态库是在程序运行阶段进行链接,一般情况下,加载器会自动再/lib目录下搜寻动态链接库进行链接,所以一旦要将生成的动态链接库文件移动到/lib目录下
# 移动
sudo mv libmath.so /lib
./a.out
静态库和动态库的区别
我们注意到编译主程序时,静态和动态库的方式都是一样的
gcc main.c -lmath -L ./
那么我们就无法知道我们编译进去的是静态还是动态库了。

我们可以指定使用静态库
gcc main.c -static -lmath -L /lib -o a1.out
此外也可以通过文件大小看

make

make是什么

所谓工程管理,其实就是管理工程项目中的多个文件。前几章编译的文件个数最多不超过5个,即便是有几个文件进行了更改,再对其进行编译即可。但工程若是由成百上千个文件构成的,而只有其中一个或少数几个文件进行了修改,如果此时不知道哪些文件被更改了,就只能使用gcc编译工具把所有文件重新编译一遍,这样会大大降低工程文件编译的效率。所以,人们就希望有一个工程管理器能够自动识别更新了的文件代码,只对更新的文件进行编译,因此make工程管理器便应运而生了。

实际上,make工程管理器起到了自动编译的作用,这里的“自动”是指它能够根据文件时间戳自动发现哪个文件更新过,这样便大大减少了编译工作量。

1 make命令和Makefile文件

make工程管理器主要是通过一个叫作Makefile的文件进行工作的。MakefiIe文件类似于一个脚本文件,make工程管理器根据里面的一些规则实现对工程的管理。其中的规则描述了软件包中各个文件之间的关系,也提供了对每个文件进行更新的命令。在一个软件包里,通常情况下可执行文件由链接目标文件和库文件更新,目标文件由源文件更新。

当存在一个MakefiIe文件时,如果要对某几个源文件进行改变,只需要使用简单的make命令就能够自动完成所有必要的重新编译。

2 MakefiIe文件编写

既然MakefiIe文件是make工程管理的核心,那么如何编写MakefiIe文件,规则的格式又是什么?

1.Makefile文件的编写
在MakefiIe中,规则的顺序是很重要的,因为,MakefiIe中只有一个最终目标,其他目标都是被这个目标所连带出来的,所以一定要让make知道你的最终目标是什么。一般来说,定义在Makefile中的目标可能会有很多,但是第一条规则中的目标将被确立为最终目标。

下面举例说明Makefile文件编写的具体步骤。

(])使用vi编辑器创建一个任意名字的文件(也可命名为Makefile)

(2)规则语法:

目标:目标所依赖文件1 目标所依赖文件2.
	TAB键 产生目标的命令

可见,规则包含两个部分内容,一个是依赖关系,另一个是生成目标的方法即命令。如果上述规则语法中的命令过长,可以使用“\”作为换行符。

每个Makefile文件必须严格按照上面的语法进行编写,在文件中要说明如何编译各个源文件并链接生成可执行文件,并要求定义源文件之间的依赖关系。Makefile的每一组规则说明了一个目标所依赖的文件以及生成或更新目标所需要的命令。

例:假设项目由源文件main.c、m.c、bank.h组成,为其编写Makefile规则。

# 项目的最终目标是可执行文件a.out,该目标依赖的文件有main.o和mo.o
# main.o和m.o也属于目标文件,main.o所依赖的文件是main.c和bank.h,main.o所依赖的文件是m.c和bank.h
a.out:main.o m.o
	gcc main.o m.o
main.o:main.c bank.h
	gcc -c main.c
mo.o:m.c bank.h
	gcc -c m.c
makefile抒写规则
make [选项] [参数] [目标]
make -f Makefile文件
make -f Makefile文件 目标文件.o
ouc-13@ouc-13:~/hanfeng/clib$ vim myMakefile
a.out:main.o sort.o
	gcc main.o sort.o
main.o:main.c bank.h
	gcc -c main.c
sort.o:sort.c bank.h
	gcc -c sort.c
	
	

ouc-13@ouc-13:~/hanfeng/clib$ make -f myMakefile
gcc -c sort.c
gcc main.o sort.o
ouc-13@ouc-13:~/hanfeng/clib$ ls # 之前编译过的.o文件都删掉后makefile又全有了
a.out  bank.h  main.c  main.o  myMakefile  sort.c  sort.o

ouc-13@ouc-13:~/hanfeng/clib$ make -f myMakefile main.o
make: 'main.o' is up to date.

make

默认在当前目录下依次查找名字为GNUMakefile、Makefile和makefile的规则文件。

Makefile文件中的变量

可以在makefile中定义一个变量,在makefile内可以引用

变量名可以包含字符、数字、下划线,但不能包含:#=回车空格,区分大小写。

传统makefile变量是全大写的命名方式,建议由大小写组成,避免和系统变量冲突。

使用能力时,在前面加上$即可,建议用{}()括起来

ouc-13@ouc-13:~/hanfeng/clib$ vim myMakefile
OBJC=main.o sort.o
C=-c
a.out:$(OBJC)
	gcc $(OBJC)
main.o:main.c bank.h
	gcc $(C) main.c
sort.o:sort.c bank.h
	gcc $(C) sort.c

还有些默认的变量

RM 删除文件的目录,默认值为rm -f
$+ 所有的依赖文件,不去除重复的依赖目标
$^ 所有的依赖文件,去除重复的依赖目标
$< 表示第一个依赖文件
$? 所有的依赖文件,以空格隔开,这些依赖文件比模板还要新(即更新时间比模板晚)
$@ 表示目标文件
$% 仅当目标是函数库文件中,表示规则中的目标成员名
Makefile通配符
&
?
[]
通配符只能用在以下两个位置:
可以用在规则的目标、依赖中,make在读取makefile时会自动对其进行匹配处理(通配符展开)
可以出现在规则的命令中,通配符的通配处理是在shell执行命令时完成的。

makefile的条件执行

ifeq(,)
	gcc -o ex1 model
else
	gcc -o ex2 model
endif
automake

automake可以让我们免于手写Makefile文件

我们使用autoconf和automake两个工具来帮助我们自动地生成符合自由软件惯例的makefile,这样就可以像常见的GNU程序一样,只要使用./configure、make、make install就可以把程序安装到linux系统中去了

automake是什么?

automake是一个从文件Makefile.am自动生成Makefile.in的工具。每个Makefile.am基本上是一系列make的宏定义或make规则。由automake生成的MakefiIe.in遵循GNUMakefiIe标准。GNUMakefiIe标准文档长、复杂,而且会发生改变。automake的目的就是减轻维护MakefiIe的负担。典型的automake输入文件是一系列简单的宏定义,处理所有这样的文件以创建MakefiIe.in。在一个项目(project)的每个目录中通常包含一个Makefile.amoautomake生成MakefiIe的主要步骤如下。

  • 1)创建源代码文件,使用"autoscan”生成configurescan文件,将其重命名为configure.ac,并做适当修改。
  • 2)使用"aclocal"命令生成aclocal.m4文件。
  • 3)使用"autoconf,命令由configure、ac和aclocal.m4文件生成configure文件。
  • 4)手工编辑Makefile.am文件,使用"automake”命令生成configure.in文件。
  • 5)手工编辑或由系统给定acconfig.h文件,使用"autoheader”命令生成config.h.tn文件。
  • 6)使用"configure”命令由configure、configure.in和config.h.in文件生成Makefile文件,从而完成MakefiIe文件的创建过程。
ouc-13@ouc-13:~/hanfeng/clib$ mkdir automake
ouc-13@ouc-13:~/hanfeng/clib$ cd automake/
ouc-13@ouc-13:~/hanfeng/clib/automake$ vim main.c
#include<stdio.h>
int main(){
        printf("auto makefile\n");
        return 0;
}
ouc-13@ouc-13:~/hanfeng/clib/automake$ autoscan
Command 'autoscan' not found, but can be installed with:
sudo apt install autoconf

ouc-13@ouc-13:~/hanfeng/clib/automake$ sudo apt install autoconf
ouc-13@ouc-13:~/hanfeng/clib/automake$ ls
main.c
ouc-13@ouc-13:~/hanfeng/clib/automake$ autoscan
ouc-13@ouc-13:~/hanfeng/clib/automake$ ll
-rw-rw-r-- 1 ouc-13 ouc-13    0 9月  27 01:12 autoscan.log # 新生成的
-rw-rw-r-- 1 ouc-13 ouc-13  466 9月  27 01:12 configure.scan # 新生成的
-rw-rw-r-- 1 ouc-13 ouc-13   71 9月  27 00:40 main.c

ouc-13@ouc-13:~/hanfeng/clib/automake$ mv configure.scan configure.in

ouc-13@ouc-13:~/hanfeng/clib/automake$ vim configure.in
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
AC_CONFIG_SRCDIR([main.c])
AC_CONFIG_HEADERS([config.h])

# Checks for programs.
AC_PROG_CC

# Checks for libraries.

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.

AC_OUTPUT
~
#======================修改为=====================
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
# 修改
AC_INIT([main], [1.0], [hhh@qq.com])
AC_CONFIG_SRCDIR([main.c])
AC_CONFIG_HEADERS([config.h])
#新增宏AC_INIT_AUTOMAKE,这个是automake所必备的宏
AM_INIT_AUTOMAKE(make,1.0)
# Checks for programs.
AC_PROG_CC

# Checks for libraries.

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.
# 修改,添加输出文件Makefile
AC_OUTPUT([Makefile])

ouc-13@ouc-13:~/hanfeng/clib/automake$ aclocal
ouc-13@ouc-13:~/hanfeng/clib/automake$ ls
drwxr-xr-x 2 ouc-13 ouc-13   4096 9月  27 01:21 autom4te.cache/ # 新生成,主要处理本地的宏定义
-rw-rw-r-- 1 ouc-13 ouc-13      0 9月  27 01:12 autoscan.log
-rw-rw-r-- 1 ouc-13 ouc-13    504 9月  27 01:17 configure.in
-rw-rw-r-- 1 ouc-13 ouc-13     71 9月  27 00:40 main.c
ouc-13@ouc-13:~/hanfeng/clib/automake$ autoconf
configure.in:10: error: possibly undefined macro: AC_INIT_AUTOMAKE
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
ouc-13@ouc-13:~/hanfeng/clib/automake$ sudo apt-get install libtool
ouc-13@ouc-13:~/hanfeng/clib/automake$ autoconf
ouc-13@ouc-13:~/hanfeng/clib/automake$ ll
drwxr-xr-x 2 ouc-13 ouc-13   4096 9月  27 01:21 autom4te.cache/
-rw-rw-r-- 1 ouc-13 ouc-13      0 9月  27 01:12 autoscan.log
-rwxrwxr-x 1 ouc-13 ouc-13 111849 9月  27 01:21 configure* # 新生成
-rw-rw-r-- 1 ouc-13 ouc-13    504 9月  27 01:17 configure.in
-rw-rw-r-- 1 ouc-13 ouc-13     71 9月  27 00:40 main.c

ouc-13@ouc-13:~/hanfeng/clib/automake$ autoheader
ouc-13@ouc-13:~/hanfeng/clib/automake$ ll
drwxr-xr-x 2 ouc-13 ouc-13   4096 9月  27 01:21 autom4te.cache/
-rw-rw-r-- 1 ouc-13 ouc-13      0 9月  27 01:12 autoscan.log
-rw-rw-r-- 1 ouc-13 ouc-13    539 9月  27 01:26 config.h.in # 新生成。该工具通常会从acconfig.h文件中复制用户附加的符号定义,因此此处没有附加符号定义,所以不需要创建acconfig.h文件
-rwxrwxr-x 1 ouc-13 ouc-13 111849 9月  27 01:21 configure*
-rw-rw-r-- 1 ouc-13 ouc-13    504 9月  27 01:17 configure.in
-rw-rw-r-- 1 ouc-13 ouc-13     71 9月  27 00:40 main.c

# 新建Makefile.am,这是创建Makefile的重要一步。其使用automake对其生成configure.in文件,在这里使用-add-missing可以让automake添加一些必须的脚本文件
ouc-13@ouc-13:~/hanfeng/clib/automake$ vim Makefile.am
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=main
main_SOURCES=main.c

# 其中的AUTOMAKEOPTIONS为设置automake的选项。由于GNU(在第]章中已经有所介绍)对自己发布的软件有严格的规范,比如必须附带许可证声明文件COPYING等,否则automake执行时会报错。automake提供了三种软件等级:foreign、gnu和gnits,供用户选择,默认等级为gnuo在本例使用foreign等级,它只检测必需的文件。
#bin_PROGRAMS定义要产生的执行文件名。如果要产生多个执行文件,每个文件名用空格隔开巴
#mainSOURCES定义"main”这个执行程序所需要的原始文件。如果"main”这个程序是由多个原始文件所组成的,则必须把它所用到的所有原始文件都列出来,并用空格隔开。例如:若目标体"main"需要"main.c","sunq.c".main.h”三个依赖文件,则定义mainSOURCES=main.c sunq.c main.h,要注意的是,如果要定义多个执行文件,则对每个执行程序都要定义相应的fiIe_SOURCES。

ouc-13@ouc-13:~/hanfeng/clib/automake$ automake --add-missing
automake: warning: autoconf input should be named 'configure.ac', not 'configure.in'
configure.in:10: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated.  For more info, see:
configure.in:10: https://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
configure.in:12: installing './compile'
configure.in:10: installing './install-sh'
configure.in:10: installing './missing'
automake: warning: autoconf input should be named 'configure.ac', not 'configure.in'

ouc-13@ouc-13:~/hanfeng/clib/automake$ ls
aclocal.m4      autoscan.log  config.h.in   configure     depcomp     main.c       Makefile.in
autom4te.cache  compile       config.h.in~  configure.in  install-sh  Makefile.am  missing

-rw-rw-r-- 1 ouc-13 ouc-13  41888 9月  27 01:34 aclocal.m4
drwxr-xr-x 2 ouc-13 ouc-13   4096 9月  27 01:36 autom4te.cache/
-rw-rw-r-- 1 ouc-13 ouc-13      0 9月  27 01:12 autoscan.log
lrwxrwxrwx 1 ouc-13 ouc-13     32 9月  27 01:36 compile -> /usr/share/automake-1.16/compile*
-rw-rw-r-- 1 ouc-13 ouc-13    625 9月  27 01:35 config.h.in
-rw-rw-r-- 1 ouc-13 ouc-13    539 9月  27 01:26 config.h.in~
-rwxrwxr-x 1 ouc-13 ouc-13 146208 9月  27 01:34 configure*
-rw-rw-r-- 1 ouc-13 ouc-13    504 9月  27 01:33 configure.in
lrwxrwxrwx 1 ouc-13 ouc-13     32 9月  27 01:30 depcomp -> /usr/share/automake-1.16/depcomp*
lrwxrwxrwx 1 ouc-13 ouc-13     35 9月  27 01:36 install-sh -> /usr/share/automake-1.16/install-sh*
-rw-rw-r-- 1 ouc-13 ouc-13     71 9月  27 00:40 main.c
-rw-rw-r-- 1 ouc-13 ouc-13     63 9月  27 01:30 Makefile.am
-rw-rw-r-- 1 ouc-13 ouc-13  24161 9月  27 01:36 Makefile.in
lrwxrwxrwx 1 ouc-13 ouc-13     32 9月  27 01:36 missing -> /usr/share/automake-1.16/missing*

# 运行configure,通过运行自动配置文件configure,吧Makefile.in变成了Makefile文件
ouc-13@ouc-13:~/hanfeng/clib/automake$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking whether make supports the include directive... yes (GNU style)
checking dependency style of gcc... gcc3
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: executing depfiles commands

ouc-13@ouc-13:~/hanfeng/clib/automake$ ll
-rw-rw-r-- 1 ouc-13 ouc-13  41888 9月  27 01:34 aclocal.m4
drwxr-xr-x 2 ouc-13 ouc-13   4096 9月  27 01:36 autom4te.cache/
-rw-rw-r-- 1 ouc-13 ouc-13      0 9月  27 01:12 autoscan.log
lrwxrwxrwx 1 ouc-13 ouc-13     32 9月  27 01:36 compile -> /usr/share/automake-1.16/compile*
-rw-rw-r-- 1 ouc-13 ouc-13    752 9月  27 01:38 config.h
-rw-rw-r-- 1 ouc-13 ouc-13    625 9月  27 01:35 config.h.in
-rw-rw-r-- 1 ouc-13 ouc-13    539 9月  27 01:26 config.h.in~
-rw-rw-r-- 1 ouc-13 ouc-13   9629 9月  27 01:38 config.log
-rwxrwxr-x 1 ouc-13 ouc-13  32502 9月  27 01:38 config.status*
-rwxrwxr-x 1 ouc-13 ouc-13 146208 9月  27 01:34 configure*
-rw-rw-r-- 1 ouc-13 ouc-13    504 9月  27 01:33 configure.in
lrwxrwxrwx 1 ouc-13 ouc-13     32 9月  27 01:30 depcomp -> /usr/share/automake-1.16/depcomp*
drwxrwxr-x 2 ouc-13 ouc-13   4096 9月  27 01:38 .deps/
lrwxrwxrwx 1 ouc-13 ouc-13     35 9月  27 01:36 install-sh -> /usr/share/automake-1.16/install-sh*
-rw-rw-r-- 1 ouc-13 ouc-13     71 9月  27 00:40 main.c
-rw-rw-r-- 1 ouc-13 ouc-13  23961 9月  27 01:38 Makefile
-rw-rw-r-- 1 ouc-13 ouc-13     63 9月  27 01:30 Makefile.am
-rw-rw-r-- 1 ouc-13 ouc-13  24161 9月  27 01:36 Makefile.in
lrwxrwxrwx 1 ouc-13 ouc-13     32 9月  27 01:36 missing -> /usr/share/automake-1.16/missing*
-rw-rw-r-- 1 ouc-13 ouc-13     23 9月  27 01:38 stamp-h1

# 运行make,对配置文件Makefile进行测试
ouc-13@ouc-13:~/hanfeng/clib/automake$ make
make  all-am
make[1]: Entering directory '/home/ouc-13/hanfeng/clib/automake'
gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.c
mv -f .deps/main.Tpo .deps/main.Po
gcc  -g -O2   -o main main.o
make[1]: Leaving directory '/home/ouc-13/hanfeng/clib/automake'
ouc-13@ouc-13:~/hanfeng/clib/automake$ ll
total 352
drwxrwxr-x 4 ouc-13 ouc-13   4096 9月  27 01:39 ./
drwxrwxr-x 3 ouc-13 ouc-13   4096 9月  27 00:39 ../
-rw-rw-r-- 1 ouc-13 ouc-13  41888 9月  27 01:34 aclocal.m4
drwxr-xr-x 2 ouc-13 ouc-13   4096 9月  27 01:36 autom4te.cache/
-rw-rw-r-- 1 ouc-13 ouc-13      0 9月  27 01:12 autoscan.log
lrwxrwxrwx 1 ouc-13 ouc-13     32 9月  27 01:36 compile -> /usr/share/automake-1.16/compile*
-rw-rw-r-- 1 ouc-13 ouc-13    752 9月  27 01:38 config.h
-rw-rw-r-- 1 ouc-13 ouc-13    625 9月  27 01:35 config.h.in
-rw-rw-r-- 1 ouc-13 ouc-13    539 9月  27 01:26 config.h.in~
-rw-rw-r-- 1 ouc-13 ouc-13   9629 9月  27 01:38 config.log
-rwxrwxr-x 1 ouc-13 ouc-13  32502 9月  27 01:38 config.status*
-rwxrwxr-x 1 ouc-13 ouc-13 146208 9月  27 01:34 configure*
-rw-rw-r-- 1 ouc-13 ouc-13    504 9月  27 01:33 configure.in
lrwxrwxrwx 1 ouc-13 ouc-13     32 9月  27 01:30 depcomp -> /usr/share/automake-1.16/depcomp*
drwxrwxr-x 2 ouc-13 ouc-13   4096 9月  27 01:39 .deps/
lrwxrwxrwx 1 ouc-13 ouc-13     35 9月  27 01:36 install-sh -> /usr/share/automake-1.16/install-sh*
-rwxrwxr-x 1 ouc-13 ouc-13  19576 9月  27 01:39 main*
-rw-rw-r-- 1 ouc-13 ouc-13     71 9月  27 00:40 main.c
-rw-rw-r-- 1 ouc-13 ouc-13   7112 9月  27 01:39 main.o
-rw-rw-r-- 1 ouc-13 ouc-13  23961 9月  27 01:38 Makefile
-rw-rw-r-- 1 ouc-13 ouc-13     63 9月  27 01:30 Makefile.am
-rw-rw-r-- 1 ouc-13 ouc-13  24161 9月  27 01:36 Makefile.in
lrwxrwxrwx 1 ouc-13 ouc-13     32 9月  27 01:36 missing -> /usr/share/automake-1.16/missing*
-rw-rw-r-- 1 ouc-13 ouc-13     23 9月  27 01:38 stamp-h1

# 再执行可执行文件main
ouc-13@ouc-13:~/hanfeng/clib/automake$ ./main
auto makefile

43、Linux 编程指南 本文是一篇Linux编程指南,详细介绍了如何在Linux环境下编译与链接程序,探索GCC常用选项的使用,利用GNU make工具管理多文件项目构建,以及使用GNU调试器gdb进行程序调试。通过实例和makefile示例,帮助开发者掌握高效的Linux开发与调试技巧。 阅读详情

相关推荐

DFT与机器学习协同设计高效光催化剂:从电子结构到性能预测

密度泛函理论(DFT)作为计算材料学的基石,通过求解Kohn-Sham方程,能够在原子尺度精确预测材料的电子结构、能带和光学性质,为理解光催化等能源材料的微观机理提供了关键视角。其核心价值在于替代传统试错法,实现材料性能的理性设计与机理揭示。在工程实践中,面对高通量筛选的需求,机器学习(ML)技术,特别是长短期记忆网络(LSTM)这类擅长处理序列数据的模型,能够学习从材料描述符到复杂性能(如光谱)的映射关系,实现快速性能预测与优化。这种DFT与ML的结合范式,正广泛应用于新能源材料、半导体器件等领域,用于高

weixin_30662937的博客 661

Linux使用make命令时常见的几种错误及其解决方法(Ubuntu适用)

Linux使用make命令时常见的几种错误及其解决方法(Ubuntu适用)

m0_75155538的博客 8338

分享一下如何使用labelimg制作自己的YOLO数据集

首先准备一下自己的下准备一个空文件夹用于保存标签文件,如下图所示。

skywalkerxhx的博客 830

linux 下编译提示报错 make:command not found

问题:运行 build.sh之后报错,make:command not found 安装 make 时发现 make 已经安装成功了 解决办法: 原来是没有安装gcc 导致的,安装 gcc之后就不再报错了。 apt-get install gcc

weixin_42623551的博客 9043

【Unity动画系统】详解Root Motion动画在Unity中的应用(一)

什么时候勾选Bake into pose,当不希望动画带动游戏对象旋转时。在旋转的动画中一般是不用勾选的,因为就需要用它来带动我们的角色对象旋转。但在比如前进、后退、待机等动画来说,我们就可以勾选这里,以避免因动画文件本身的瑕疵而给我们带来的旋转。loop match:代表了这个动画在角度上的吻合度。如果这个动画在播放中转角过大,那么就会显示红色,告诉我们如果勾选bake into pose,则会带来不好的效果。

weixin_60154963的博客 6802

Android双目摄像头(RGB+IR)实时预览与人脸活体检测实战指南

本文详细介绍了Android双目摄像头(RGB+IR)实时预览与人脸活体检测的实战指南。通过双摄同步预览、人脸检测与活体判断等技术实现,提升安全认证的准确性和鲁棒性。文章还提供了开发环境搭建、常见问题解决方案及性能优化建议,帮助开发者快速掌握双目摄像头在Android平台的应用。

vulkan6gpu的博客 686

make:command not found

今天在安装nginx时候,执行编译时报错,make:command not found。本来只需要安装make命令即可,但是百度了一下,需要安装gcc等。安装之后执行make以及make install就没有问题了。原因就是Linux系统是纯净版,或者没有预安装一些环境。

TS_forever007的博客 2366

详细解读文字识别工具———Tesseract-OCR

   在尝试破解12306验证码的时候,提前了解了一下应对各种验证码的解决方案,这里主要是学习到了面对文字图片验证码,例如亚马逊、豆瓣等平台的登录时会遇到的情况,效果还不错。 一、工具介绍 ​    Tesseract-OCR 是一款由HP实验室开发由Google维护的开源OCR(Optical Character Recognition...

别看我只是一只羊 2万+

Linux “make“ command Error 127

Linux "make" command Error 127

weixin_44195230的博客 1万+

CentOS 7下rsyslog日志服务器搭建全攻略:从安装到避坑

本文详细介绍了在CentOS 7系统上搭建rsyslog日志服务器的完整流程,从基础安装到高级配置,包括协议设置、日志模板设计、安全加固和性能优化。特别分享了生产环境中的实战技巧和常见问题解决方案,帮助用户高效构建可靠的日志管理系统。

happy2的博客 687

Spark中Application、Job、Stage和Task区别详解

在Spark中,有一些关键的概念,如Application、Job、Stage和Task,它们描述了Spark作业的不同层次和组成部分。下面我将详细介绍每个概念,并通过示例说明它们之间的区别。

优快云 精品推荐 899

Linux系统编程—第二节—(Centos 7)开发工具等(yum vim gcc g++ gdb make Makefile )

jxwd的博客 1万+

lammps模拟石墨烯吸附水分子(gcmc)

本文分享lammps gcmc吸附的一个案例代码,上下壁面的通道材料为石墨烯,吸附的分子为tip4p水分子。大家好,我是小马老师。

lammps_jiayou的博客 2590

Linux常用编程工具

文章目录前言一、yum ——*软件包管理工具,完成第三方工具软件的安装与卸载功能*二、vim ——*编辑器,linux写代码的工具*三、g++/gcc ——*编译器,即将高级语言编译成为机器指令*四、gdb ——调试器,调试程序运行过程**静态链接:****动态链接:**五、make/makefile ——*项目的自动化构建工具*make六、git —— *项目的版本管理工具*总结 前言 本片文章主要介绍Linux编程中,我们这些新手小白常用的,编程工具,调试工具…等等,具体内容将于下面进行详细的说明 一

stromSLR的博客 6299

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

Linux——编译器gcc/g++、调试器gdb以及自动化构建工具makefile&&make详解

我们可以用。

Forward♞的博客 1402

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

Linux下的C编程实战之开发平台搭建

 1.引言  Linux操作系统在服务器领域的应用和普及已经有较长的历史,这源于它的开源特点以及其超越Windows的安全性和稳定性。而近年来,Linux操作系统在嵌入式系统领域的延伸也可谓是如日中天,许多版本的嵌入式Linux系统被开发出来,如ucLinux、RTLinux、ARM-Linux等等。在嵌入式操作系统方面,Linux的地位是不容怀疑的,它开源、它包含TCP/IP协议栈、它易集成GU

boy8239的专栏 794

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Linux 编程环境

GCC 原名为 GNU C语言编译器,因为它原本只能处理 C 语言,但如今的 GCC ,不仅可以编译 C、C++ 和 Objective-C,还可以通过不同的前端模块支持各种语言,包括 Java、Fortran、Ada、Pascal、Go 和 D 语言等等。Makefile 是描述程序的编译规则的文本文件,执行 make 命令的时候,make 命令会在当前目录下寻找 Makefile 文件,根据Makefile文件里的规则,编译程序。此外,GCC是按模块化设计的,可以加入新语言和新CPU架构的支持。

爱思考的小伙 1217

一起学习gcc gdb makefile

Linux下C语言编程常用的编辑器是vim,编译器一般用gcc,编译链接程序用make,跟踪调试一般使用gdb,项目管理用makefile。 GCC GCC(GNU Compiler Collection,GNU编译器套件)是由GNU开发的编程语言译器。GNU编译器套件包括C、C++、 Objective-C、 Fortran、Java、Ada和Go语言前端,也包括了这些语言的库。(如libstdc++,libgcj等。) GCC的初衷是为GNU操作系统专门编写的一款编译器。GNU系统是彻底的自由软件

qq_42741249的博客 335

分文件编程——Makefile

makefile

ka1es的博客 1122

Linux编程环境(vi gcc gdb Makefile)

Linux 编程环境 1.编辑器 vi (1)编辑器 vi 简介 编辑器 vi 最初是由 Sun Microsystrms 公司的 Bill Joy 在1976 年开发的。启初,开发出了 Ex 编辑器,也称为行编辑器,后来开发了vi作为Ex的可视接口,一次能看到一屏的文本而不仅仅是一行,vi因此得名。vi在通过命令操作,界面不友好,对普通人不容易掌握。但是,其丰富的命令和强大的功能,

W77_20的博客 809

Linux 编程基础

Linux 编程基础 1. GCC编译器 https://blog.youkuaiyun.com/guo1988kui/article/details/81076252 2. gdb调试器 GUN priject debugger 命令 含义缩写 命令说明 quit / Ctrl + D q 退出 break b 断点 info i 描述程序的状态 run r 开始运行程序 ...

GOD_胖慧的博客 429

Linux上的C/C++编程

vim,gcc,make/makefile,gdb

遥逖的博客 1324

基于Linux下的C语言编程

Linux

weixin_50784807的博客 803

gcc、gdb、make的使用——Linux

文章目录gcc/g++:编译器功能编译过程gdb:调试器功能使用make/Makefile:项目自动化构建工编写规则执行规则预定义变量 gcc/g++:编译器 功能 ​ 将C/C++高级语言代码翻译成机器可识别的代码 编译过程 预处理(进行宏替换) 宏定义展开,头文件展开、条件编译等,同时将代码中的注释删除 eg:gcc -E hello.c -o hello.i 编译(生成汇编) 检查代码的规范性、是否有语法错误等,以确定代码的实际要做的工作,在检查无误后,把代码翻译成汇编语言 eg:gcc -

YOLO的博客 2261
上一篇: 【操作系统】
下一篇: 【网络通信】详解NIO、select
hancoder
博客等级 码龄9年 4135粉丝 167原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值