linux 命令
1 19
pwd # Present Working Directory
tar
chmod 777 -R
cd - # 上次目录 head # 查看文件开头 file # 查看文件属性 ${var#week} # 将var头部的week删掉,$会去除末尾的字符 lsof -i:9008 # 检查9008端口是否开放
—– g++ ——-
- 这样做的好处是当某一个链接文件改动的时候,不需要重新编译所有的文件
g++ filename.cpp -c # 只编译不运行 g++ *.o -o main # 将编译的文件链接
Makefile
1 35
make -f fileName # fileName 你指定的makefile文件
make通过修改文件的时间戳来判断文件是否被更新
—————一个编译实例———-
增量编译(只重新编译修改过的文件)
CXX = g++ TARGET = hello OBJ = main.o printhello.o factorial.o # 声明依赖
设置编译模式
$(TARGET) : $(OBJ) $(CXX) -o $(TARGET) $(OBJ)
依赖项的来源,通过g++编译而来
main.o: main.cpp $(CXX) -c main.cpp
———-第三个版本—–
CXXFLAGS = -c -Wall # Wall: warning all
$(TARGET) : $(OBJ) $(CXX) -o $@ $^ # @: TARGET, ^:OBJ
———-统一的规则————
$<: 表示依赖中的第一个, $^: 代表所有的依赖
%.o: %.cpp $(CXX) $(CXXFLAGS) $< -o $@
.PHONY: clean # 防止出现文件叫clean。这里生成一个依赖于clean的项目,但是什么都不做 clean: rm -f *.o $(TARGET)
———–版本4———-
SRC = $(wildcard *.cpp) # 当前目录下的所有.cpp文件都放到变量SRC中 OBJ = $(patsubst %.cpp, %.o, $(SRC)) # 把SRC中的.cpp文件替换成.o然后存储到OBJ中
CMake
文件名:CMakeLists.txt
1 61
由于cmake会生成大量的临时文件,所以最好将cmake的过程放在build
文件下,这样清除的时候会比较方便
cmake_minimum_required(VERSION 3.10) # 需要的cmake的最低版本
project(hello VERSION 1.0) # 项目名称以及对应的版本号
配置头文件将版本号传递给源代码
configure_file(TutorialConfig.h.in TutorialConfig.h)
TutorialConfig.h 文件会被自动写入 build 目录,需要将目录加入到搜索头文件的路径列表中(以下添加到CMakeList.txt文件末尾)
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_BINARY_DIR} )# PROJECT_BINARY_DIR 表示当前工程的二进制路径,即编译产物会存放到该路径,此时PROJECT_BINARY_DIR 就是 build 所在路径。
————-TutorialConfig.h.in —————-
// the configured options and settings for Tutorial #define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@ #define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@
————-TutorialConfig.h.in —————-
#—————————————–
以后可以通过这个头文件查看版本信息,MAJOR.MINOR
cmake 构建之后,会在build中生成一个TutorialConfig.h文件
// the configured options and settings for Tutorial #define Tutorial_VERSION_MAJOR 1 #define Tutorial_VERSION_MINOR 0
————TutorialConfig.h—————
生成hello程序,后面的是依赖的文件
add_executable(hello main.cpp factorial.cpp printhello.cpp)
——– 外部构建 ——–
–build 指定编译生成的文件存放目录,其中就包括可执行文件,. 表示存放到当前目录
cmake –build . cmake .. # .. 是CMakeLists.txt的存放路径
——- 使用变量 ——–
set(SRC_LIST a.cpp b.cpp c.cpp) # 将多个文件用一个变量保存 set(CMAKE_CXX_STANDARD 11) # 设置c++11标准 set(CMAKE_CXX_STANDARD_REQUIRED True) add_executable(${PROJECT_NAME} ${SRC_LIST})
————-添加库—————
MathFunctions/CMakeLists.txt
add_library(MathFunctions mysqrt.cpp) # 添加一个叫 MathFunctions 的库文件
顶级CMakeLists.txt
# add the MathFunctions library
add_subdirectory(MathFunctions)
# add the executable
add_executable(${PROJECT_NAME} tutorial.cpp)
target_link_libraries(${PROJECT_NAME} PUBLIC MathFunctions)
# add the binary tree to the search path for include files
# so that we will find TutorialConfig.h
target_include_directories(${PROJECT_NAME} PUBLIC
${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/MathFunctions
)
gdb
1 13
info s # 查看栈信息 info r # 查看寄存器信息 info local # 查看局部变量 bt # 查看调用栈 disas # 查看汇编代码, 可以指定函数 x/[count][format] [address] # 打印内存值
- x/s 0x402400 # 打印在地址0x402400中的值,转换成string run res.txt # 后面可以加上传入的参数 stepi # 二进制中的一步 fs next # 切换关注的窗口,gdb或者命令行窗口
condition 1 item_to_remove==1 # 为断点添加一个条件 backtrace # 查看错误栈
快捷键
1
ctrl + L: 刷新gdb页面
快捷键(Linux)
1
ctrl + D: 结束当前任务
docker 命令
1 8
开启docker
docker start user_name
进入docker
docker attach user_name
打开ssh服务(进入对应的docker之后)
service ssh start
Git
\text{工作区}\stackrel{add}{\rightarrow}\text{暂存区}\stackrel{commit}{\rightarrow}\text{本地仓库}\stackrel{push}{\rightarrow}\text{远程仓库}\stackrel{pull}{\rightarrow}\text{本地}
1 58
In the work directory
git config –global user.name “yourName” git config –global user.email yourEmail
git init # initialize the repository git status # repository information git add fileName git commit -m “commit msg”EADADWE git log # 查看以前的版本
touch .gitignore # 不追踪的文件
创建新分支
git branch branchName
两种切换分支的命令
git checkout branchName - git checkout -d branchName # 删除分支 - git checkout -b temp # 创建并切换到新建的分支 git switch branchName
合并分支
git merge temp
add 和 commit合在一起写
git commit -a -m “msg” # 或者-am
提交
git push -u
添加远程分支(命名为origin)
git remote add origin https:**.git
下载远程内容
直接下载zip是不会下载版本信息的,所以需要使用以下命令
git clone
总结
echo “# learningGit” » README.md git init git add README.md git commit -m “first commit” git branch -M main git remote add origin https://github.com/Baymine/learningGit.git git push -u origin main
解决冲突
## 建立分支 git checkout -b my_feature
检查差异(与main branch之间的差异)
git diff
git merge
不同分支中保存不同的内容,可以从远端pull最新的内容到本地
ESDAW