1 Ubuntu下c
、cpp
文件
1.1 cmake
方式编译
cmake
通常建立CmakeLists.txt
,通过cmake命令生成makefile文件编译工程
文件内容:
1 CmakeLists.txt
2 demo.cpp
3 1.cpp
4 1.h
CmakeLists.txt
文件内容
cmake_minimum_required(VERSION 2.8)
project(hello)
set(CMAKE_BUILD_TYPE "Release")
add_library(fun SHARED fun.cpp)
add_executable(demo demo.cpp)
target_link_libraries(demo fun)
CmakeLists.txt
文件内容其他常用命令
include_directories(${
INCLUDE_PATH})
文件编译及运行
mkdir build
cd build
cmake ..
make
./demo
1.2 gcc编译.c文件
gedit demo.c
在终端中用命令gcc生成可执行文件.out文件,默认名为a.out,用选项-o可以生成其他名字的可执行文件。
gcc demo.c
如果要生成比如名为“demo.out”的可执行文件,用以下代码实现。
gcc demo.c -o demo
./demo
1.3 g++编译cpp文件
demo.cpp
g++ demo.cpp -o demo
./demo
1.4编译多文件
demo.cpp
demo.h
add.cpp
编译:
g++ demo.cpp add.cpp -o demo //不需要添加.h文件
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)