零基础学习Linux编程之Ubuntu下编译C++
下面是使用gcc、g、cmake、clang生成可执行文件的指令g hello.cpp ./a.out g hello.cpp -o hello.out //指定out文件的名字 gcc hello.cpp -lstdc gcc hello.cpp -lstdc -o hello //指定out文件名字 clang hello.cpp -lstdc clang hello.cpp -lstdc -o 666 ./666 //指定out文件名字 clang hello.cpp ./a.out clang hello.cpp -o hello.out //指定out文件名字 前提是hello_Project文件夹下要有CMakeLists.txt和hello.cpp然后执行下面 1.通过cmake .生成Makefile文件然后执行make生成out文件 2.或者通过cmake-gui界面实现shuerubuntu:~/Desktop/hello_project/build$ cd ./ ./ 一个.是回退到当前目录 shuerubuntu:~/Desktop/hello_project/build$ cd ../ ../两个.是回退到上层目录 shuerubuntu:~/Desktop/hello_project$ cd - cd-是回退到上次进来时的目录 /home/shuer/Desktop/hello_project/build shuerubuntu:~/Desktop/hello_project/build$ cd - cd-是回退到上次进来时的目录 /home/shuer/Desktop/hello_project shuerubuntu:~/Desktop/hello_project$shuerubuntu:~/Desktop/hello_project/build$ cmake ../ 代表是在上层目录hello_project文件夹中查找CMakeLists.txt文件但在build中生成的makefile文件以及.txt中执行生成的文件 -- Configuring done -- Generating done -- Build files have been written to: /home/shuer/Desktop/hello_project/build#CmakeLists.txt aux_source_directory(.SRCS) 搜索当前下面的所有cpp文件保存到SRCS ADD_EXECUTABLE(hello.out ${SRCS})