Linux C++ 开发简介
2016-04-25 00:09
555 查看
主要介绍将Windows程序迁移到Linux系统相关知识
既需要了解Linux平台的开发知识,
也需要了解Windows平台代码如何迁移到Linux平台,
下面分享一下我所掌握的相关开发经验,
如果有不对的地方,请立即指出。
主流linux发行版的概述+比较+推荐
Emacs
gedit
Atom
Visual Studio Code
...
Clang
CMake
qmake
automake
...
lldb
...
CodeBlocks
Clion
通过VS创建一个Windows服务程序看一个参考创建Windows服务。
通过VS生成的服务,注册比较简单,详情可以参考注册Windows服务。
自定义Linux守护进程的开机启动
Linux的daemon进程详解
systemd详解
使用Boost.Application可以很方便的编写跨平台的服务代码,具体请参考使用Boost.Application快速构建Windows服务
数据库自己封装了一个date_time
Linux C编程一站式学习
UNIX环境高级编程
简介
Windows程序迁移到Linux系统可能需要修改很多代码,既需要了解Linux平台的开发知识,
也需要了解Windows平台代码如何迁移到Linux平台,
下面分享一下我所掌握的相关开发经验,
如果有不对的地方,请立即指出。
操作系统
Linux操作系统都是使用Linux内核,比较常见的Linux发行版有 CentOS、RedHat、Debain、openSUSE等。主流linux发行版的概述+比较+推荐
编辑器
VimEmacs
gedit
Atom
Visual Studio Code
...
编译器
GCCClang
构建系统
makeCMake
qmake
automake
...
调试
gdblldb
...
IDE
EclipseCodeBlocks
Clion
可执行程序、动态库、静态库
类型 | Windows | Linux |
---|---|---|
执行程序 | .exe | 具有执行权限的文件,可以无扩展名 |
动态库 | .dll | .so |
静态库 | .lib | .a |
批处理 | .bat/.cmd | Shell脚本,一般为.sh |
服务
Windows服务是Windows下特有的一种服务模型,一个Windows服务程序不能直接运行在Linux上,需要对这个Windows服务进行一些修改才能运行到Linux上。Windows服务简介
Windows服务的运行需要一个Windows服务以及一个服务管理程序。创建Windows服务
构建一个Windows服务可能有几种方式,比较常见的有,直接使用Windows服务API,另外一种方式,使用VS的服务模板,生成一个服务程序,而这个程序使用atl框架,而这个ATL框架实际就是对Windows服务API的封装。通过VS创建一个Windows服务程序看一个参考创建Windows服务。
注册Windows服务
创建了Windows服务后,在运行服务前,需要先向系统注册一下。通过VS生成的服务,注册比较简单,详情可以参考注册Windows服务。
管理Windows服务
可以通过Windows服务管理器services.msc,net命令、sc命令管理Windows服务,详情可以参考命令行管理Windows服务Linux守护进程简介
Linux服务,又称为守护进程,或则daemons,与Windows服务类似,也需要一个服务程序以及一个管理程序。创建Linux守护进程
创建守护进程程序要比创建Windows服务程序简单很多,详情可以参考守护进程详解及创建。管理Linux守护进程
Linux守护进程原理及创建详解自定义Linux守护进程的开机启动
Linux的daemon进程详解
systemd详解
跨平台服务框架——Boost.Application
Boost.Application是一个开源的C++库,主要用于构建跨平台的服务,包括Windows、Unix、Linux、MaxOS等。没错,这个库可以用来做跨平台的服务。Boost.Application 使用开源协议 Boost Software License, Version 1.0。使用Boost.Application可以很方便的编写跨平台的服务代码,具体请参考使用Boost.Application快速构建Windows服务
日期和时间
boost::posix_time数据库自己封装了一个date_time
多线程
Windows | Linux | 跨平台 |
---|---|---|
CreateThread | pthread库 | std::thread |
GetCurrentThreadId | pthread库 | std::this_thread::get_id |
Sleep | usleep | std::this_thread_sleep_for(std::chrono::second(1)) |
同步
Windows | Linux | 跨平台 |
---|---|---|
CRITICAL_SECTION | pthread库 | std::mutex |
递归锁 | pthread库 | std::recursive_mutex |
读写锁 | pthread库 | boost::shared_mutex |
CreateMutex | pthread库 | boost::interprocess::named_mutex |
InterlockedCompareExchange | pthread库 | std::atomic |
CreateEvent(not named) | pthread库 | std::condition_variable |
CreateEvent(named) | System V signal | boost::interprocess::named_condition |
文件和目录
boost::filesystemIO
Windows | Linux | 跨平台 |
---|---|---|
Create/Open/Read/WriteFile | create/open/read/write | 标准C(fopen)/标准C++(fstream/filebuf) |
IPC
Windows | Linux | 跨平台 |
---|---|---|
CreateFileMapping/MapViewOfFile/FlushOfView | mmap | boost::interprocess库 |
SEH
Windows | Linux | 跨平台 |
---|---|---|
__try/__except | signal | 自定义跨平台宏 |
dump
Windows | Linux | 跨平台 |
---|---|---|
MiniDump | - | - |
VisualGDB
VisualGDB是一个VS插件,通过此插件,可以实现VS编辑、编译、调试Linux程序。开发Linux程序
Using Visual Studio to develop Linux apps支持CMake
Creating CMake Linux projects with Visual Studio调试
10 Powerful Debugging Tricks with Visual Studio附加调试
Attaching to remote Linux applications with VisualGDB分析崩溃转储
Debugging Linux Core Dumps with VisualGDB从Windows迁移到Linux
Porting a Windows App to Linux with Visual Studio学习资料
鸟哥的Linux私房菜 基础学习篇Linux C编程一站式学习
UNIX环境高级编程
相关文章推荐
- Linux查看物理CPU个数、核数、逻辑CPU个数
- linux解压zip、bz、bz2、z、gz、tar(解包)
- CentOS 6.5下安装字体
- win7下easybcd安装centos
- linux下导入、导出mysql数据库命令
- Hey 老司机,知道eventfd吗?
- Linux常用命令(二)
- Linux常用命令(一)
- linux expect 自动登录交换机保存配置
- linux磁盘管理及文件系统介绍
- Linux内核学习总结
- Linux系统时间和硬件时间设置
- linux 标准输入输出
- Linux nmap
- linux、mac 安装mysql
- ArchLinux上使用Python
- linux解压缩命令
- Linux spi驱动框架之执行流程
- Linux绚丽屏保xscreensaver安装
- Centos6.5编译php报错:configure: error: mcrypt.h not found. Please reinstall libmcrypt.