【linux基础】使用命令行编译运行c++程序

前言

在linux系统运行程序,小鹅知道的有3种编译方式,一种是直接命令行编译,一种是使用Cmake,一种是使用脚本文件(*.sh)。本文介绍的是使用命令行编译。

使用过程

注意不同系统的编译器版本可能有所不同,gcc是C语言的编译器,g++是c++的编译器。

1. 使用Jsoncpp开源库

g++ test.cpp -o test -ljsoncpp

2. 使用opencv开源库

 g++ test.cpp -o test `pkg-config --cflags --libs opencv` 

注意,标点符号是反单引号(TAB键上方最左边的按键)而不是单引号。

3.使用c++新特性

 g++ test.cpp -o test -std=c++11

或者

 g++ test.cpp -o test -ljsoncpp `pkg-config -std=gnu++11

4. 使用多个库

 g++ test.cpp -o test -ljsoncpp `pkg-config --cflags --libs opencv` -std=c++11

运行程序

./test

参考

1.c++新特性在linux终端中的编译运行

原文地址:https://www.cnblogs.com/happyamyhope/p/9922799.html