Visual studio 2015程序转Eclipse gun编译出现的问题总结

1C++11支持

1)Project
settings

project右键->
c/c++
build ->Settings -> GCC C++ Compiler -> Miscellaneous ->
Other flags后面加上
-std=c++11

2)Workspace
settings

Window->
Preference -> Build -> Settings ->Discovery -> CDT GCC
Built-in Compiler Settings MinGW(shared) ->(command to get
compiler specs) ${COMMAND} -E -P -v -dD "${INPUTS}"
-std=c++11

2Ubuntuboost库的编译安装步骤及卸载方法详解

最近由于编译一个程序用到了C++的boost库,所以便安装了这个库。但是,其中遇到了一些小问题。所以记录下来,以供别人参考。

首先说一下我的环境:Ubuntu
14.04 64bit, gcc (Ubuntu 4.8.4-2ubuntu1~14.04.1) 4.8.4

其实在ubuntu下,可以用一下命令直接安装

sudo apt-get install
libboost-all-dev //完全安装所有boost库

sudo apt-get install
aptitude

aptitude search
boost

apt-get install
PACKAGE_NAME

Is the command
used to install any package you know the name for, like aptitude.

sudo is used to
earn root access and be able to install and remove software. sudo is
always required if you do system wide changes like installing,
removing, updating and upgrading packages.

apt-get

Is the command
used to manage any software and software sources. install is an extra
command that tells the computer that you want to install software
with the package name as follows. It will then check the software
sources for a download link with the same name and then download and
install the latest version (or specified version).

update

will update the
sofware sources with new versions of the software listed (not
installing anything)

upgrade

upgrades the
software if new versions are available in the software sources.

remove

removes the
package name specified after (like install).

there are more
useful commands, but these are necessary for getting started with
managing software from the terminal.

Aptitude

The command
apt-get install aptitude
will install a graphical package
manager called aptitude.

Aptitude is a
famous package manager with a ncurses GUI.
I prefer it
over the other package managers, since it is faster(IMHO) and the
conflict management system works very well.

After more
research on aptitude i found out that it's already installed. So
installing aptitude wouldn't resolve in anything besides errors in
the conosle. Start aptitude by:

sudo aptitude

The aptitude
package is a GUI version of the apt-get command,
it hasn't
got the full set of features as apt-get
but you have the
basics like, remove, update, upgrade, install, etc. More information
about aptitude and it features can be found here.

Also search in
the software center if you want o use a GUI to find and
install/uninstall applications.

安装后查看libboost-dev版本

root@ubuntu:~# dpkg
-s libboost-dev | grep 'Version'

Version:
1.54.0.1ubuntu1

root@ubuntu:~#

安装后的目录:

1)include

2)lib(so动态链接库文件所在目录)

3)需要包含libboost_system.so和libboost_serialization.so

Add的时候,要去掉前缀“lib”和扩展名“.so”

boost安装常用的几个依赖文件(完全安装时,这些依赖库应该可以自动被安装):

apt-get install
mpi-default-dev  #安装mpi库

apt-get install
libicu-dev     #支持正则表达式的UNICODE字符集

apt-get install
python-dev     #需要python的话

apt-get install
libbz2-dev

下载特定版本手动安装:

1.下载boost1.53源文件http://sourceforge.net/projects/boost/files/latest/download?source=dlp

2.解压后,进入boost_1_53_0目录,执行:

./bootstrap.sh

3.(重点)修改
tools/build/v2/user-config.jam文件,在最后面加上一行“using
mpi ;”(注意mpi后面有个空格,然后一个分号
)

4. 执行:

./b2

(或者:

./bjam -a
-sHAVE_ICU=1  #-a参数,代表重新编译,-sHAVE_ICU=1代表支持Unicode/ICU

5. 执行:

sudo ./b2 install

以上便是全部安装过程,因为网上提到的比较多,所以此处从略。重点想提的是第三步,务必记得。不过,如果你的程序不需要mpi这个功能,那也就不重要了。
应用默认设置即可。而且,第四步,执行时可以在后面加prefix参数,如果不加,装好后,默认的头文件在/usr/local/include
/boost目录下。库文件在/usr/local/lib/目录下。默认不用修改。

如果编译好程序后,在运行时提示无法加载某个库文件,则把/usr/local/lib下的所有boost的库文件mv到/usr/lib目录下就可以了。

默认安装头文件在目录/usr/local/include,而库文件在目录/usr/local/lib。卸载也很简单,直接将以上两个目录中有关boost的内容删除就可以了。

更多详情可参考boost官方网站:http://www.boost.org/

3localtimelocaltime_slocaltime_r

(1)、localtime用来获取系统时间,精度为秒

#include <stdio.h>

#include <time.h>

int main(){

time_t time_seconds = time(0);

struct tm* now_time = localtime(&time_seconds);

printf("%d-%d-%d %d:%d:%d/n", now_time->tm_year + 1900,
now_time->tm_mon + 1, now_time->tm_mday,
now_time->tm_hour, now_time->tm_min, now_time->tm_sec);

}

函数原型为struct
tm *localtime(const time_t * timep)

需要包含头文件:#include
<time.h>

struct tm的结构为

int tm_sec;
/* 秒 –
取值区间为[0,59] */

int tm_min;
/* 分 -
取值区间为[0,59]
*/

int tm_hour;
/* 时 -
取值区间为[0,23]
*/

int tm_mday;
/* 一个月中的日期
- 取值区间为[1,31]
*/

int tm_mon;
/* 月份(从一月开始,0代表一月)
- 取值区间为[0,11]
*/

int tm_year;
/* 年份,其值等于实际年份减去1900
*/

int tm_wday;
/* 星期 –
取值区间为[0,6],其中0代表星期天,1代表星期一,以此类推
*/

int tm_yday;
/* 从每年的1月1日开始的天数
– 取值区间为[0,365],其中0代表1月1日,1代表1月2日,以此类推
*/

int tm_isdst;
/*
夏令时标识符,实行夏令时的时候,tm_isdst为正。不实行夏令时的进候,tm_isdst为0;不了解情况时,tm_isdst()为负。*/

(2)localtime_r也是用来获取系统时间,运行于linux平台下

函数原型为struct
tm *localtime_r(const time_t *timep, struct tm *result);

#include <stdio.h>

#include <time.h>

int main(){

time_t time_seconds = time(0);

struct tm now_time;

localtime_r(&time_seconds, &now_time);

printf("%d-%d-%d %d:%d:%d/n", now_time.tm_year + 1900,
now_time.tm_mon + 1, now_time.tm_mday, now_time.tm_hour,
now_time.tm_min, now_time.tm_sec);

}

(3)localtime_s也是用来获取系统时间,运行于windows平台下,localtime_r只有参数顺序不一样

#include <iostream>

#include <time.h>

int main(){

time_t time_seconds = time(0);

struct tm now_time;

localtime_s(&now_time,&time_seconds);

printf("%d-%d-%d %d:%d:%d/n", now_time.tm_year + 1900,
now_time.tm_mon + 1, now_time.tm_mday, now_time.tm_hour,
now_time.tm_min, now_time.tm_sec);

}

为什么有了localtime还要有其他两个函数呢,因为localtime并不是线程安全的,观察localtime和localtime_r的调用发现,localtime在使用时,我们只需定义一个指针,并不需要为指针申请空间,而指针必须要指向内存空间才可以使用,其实申请空间的动作由函数自己完成,这样在多线程的情况下,如果有另一个线程调用了这个函数,那么指针指向的struct
tm结构体的数据就会改变。

在localtime_s与localtime_r调用时,定义的是struct
tm的结构体,获取到的时间已经保存在struct
tm中,并不会受其他线程的影响。

4noexcept(true)

在c++11标准之前,c++在函数声明中有exception
specification(异常声明)的功能,用来指定函数可能抛出的异常类型。

voidFunc0()
throw(runtime_error);

voidFunc1() throw();

voidFunc2();

函数Func0可能抛出runtime_error类型的异常;函数Func1不会抛出任何异常;函数Func2没有异常说明,则该函数可以抛出任何类型的异常。

如果函数抛出了没有在异常说明中列出的异常,则编译器会调用标准库函数unexpected。默认情况下,unexpected函数会调用terminate函数终止程序。

这种异常声明的功能很少使用,因此在c++11中被弃用。c++11引入noexcept,具体用法如下。

voidFunc3()
noexcept;

noexcept的功能相当于上面的throw(),表示函数不会抛出异常。如果noexcept修饰的函数抛出了异常,编译器可以选择直接调用std::terminate()终止程序运行。noexcept比throw()效率高一些。

voidFunc4()
noexcept(
常量表达式);

如果常量表达式的结果为true,表示该函数不会抛出异常,反之则有可能抛出异常。不带常量表达式的noexcept相当于noexcept(true)。

上面noexcept的用法是其作为修饰符时的用法,实际上noexcept还可以作为操作符,常用于模板中。

template <typename
T>

voidfunc5()
noexcept( noexcept(T()) ) {}

第2个noexcept就是一个操作符,如果其参数是一个有可能抛出异常的表达式,则返回值为false(func5为noexcept(false),有可能会抛出异常),否则返回值为true(func5为noexcept(true),不会抛出异常)。

这样函数是否会抛出异常,可以由表达式进行推导,使得c++11更好的支持泛型编程。

noexcept被大量的使用在c++11的标准库中,用于提高标准库的性能,以及满足一些阻止异常扩散的需求。随便在c++11标准文档中搜索一下noexcept关键字,就知道它的应用有多广泛了。

c++11默认将delete设置成noexcept,这样可以提高应用程序的安全性,因为在析构函数中不应该抛出异常,而析构函数中经常会调用delete。

voidoperator
delete(void* ptr) noexcept;

voidoperator
delete(void* ptr, const std::nothrow_t&) noexcept;

voidoperator
delete[](void* ptr) noexcept;

voidoperator
delete[](void* ptr, const std::nothrow_t&) noexcept;

voidoperator
delete(void* ptr, void*) noexcept;

voidoperator
delete[](void* ptr, void*) noexcept;

同样出于安全因素考虑,c++11将类的析构函数默认为noexcept(true)。但如果程序员显示的为析构函数指定noexcept(false),或者类的基类或成员有noexcept(false)的析构函数,则析构函数不会再保持默认值。

Visual studio 2015程序转Eclipse gun编译出现的问题总结的更多相关文章

  1. [No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)

    1.7-ZIP简介 7-zip 是一款免费的压缩解压软件.ZIP格式的文件默认被苹果和微软支持,完全不需要额外安装其他软件就可以解压.但对于非US-ASCII编码的文件名和大于2GB的ZIP文件,可能 ...

  2. [No0000AD]7z源码完全移植至Visual Studio 2015

    今天在上次的基础上(原文地址:[No0000AB]用Visual Studio 2015在 WIN10 64bit 上编译7-zip (32 bit)),将7Z的源码完全移植到了vs2015开发环境下 ...

  3. Grunt和Gulp构建工具在Visual Studio 2015中的高效的应用

    Grunt和Gulp构建工具在Visual Studio 2015中的高效的应用 Grunt和Gulp是Javascript世界里的用来做自动压缩.Typescript编译.代码质量lint工具.cs ...

  4. ASP.NET5之客户端开发:Grunt和Gulp构建工具在Visual Studio 2015中的高效的应用

    Grunt和Gulp是Javascript世界里的用来做自动压缩.Typescript编译.代码质量lint工具.css预处理器的构建工具,它帮助开发者处理客户端开发中的一些烦操重复性的工作.Grun ...

  5. 新手,Visual Studio 2015 配置Boost库,如何编译和选择,遇到无法打开文件“libboost_thread-vc140-mt-gd-1_63.lib“的解决办法

    1,到官网下载最新的boost,www.boost.org 这里我下载的1-63版本. 2,安装,解压后运行bootstrap.bat文件.稍等一小会就OK. 3,编译boost库.注意一定要使用VS ...

  6. Visual Studio 2015的坑:中文字符串编译后成乱码

    (2015年8月5日更新:微软已经修复了Roslyn的这个bug,详见 https://github.com/dotnet/roslyn/pull/4303 ) 昨天,我们用VS2015编译了博客程序 ...

  7. ASP.NET 5系列教程 (五):在Visual Studio 2015中使用Grunt、Bower开发Web程序

    基于Visual Studio 2015,你可以: 方便的管理前端包,如jQuery, Bootstrap, 或Angular. 自动运行任务,如LESS.JavaScript压缩.JSLint.Ja ...

  8. 体验Visual Studio 2015 Windows Forms应用程序开发与维护

    昨天到半夜还没有等到Visual Studio 2015的下载地址,实在熬不住就先休息了.北美地区的时区比北京时间要晚一些,今天早上到公司就看到Visual Studio 2015的下载地址,迅速的将 ...

  9. Visual Studio 2015编译wxWidgets

    宫指导说,换帅如换刀 程序员的编译器一换,基本套路必须都重练几次 使用wxWidgets并不难,但不能使用现有的库和工程配置文件,细节就必须理清楚 获取wxWidgets 官方的下载页面,下7z或zi ...

随机推荐

  1. Unity 中关于 BuildSetting 中 “Optimize Mesh Data” 选项的“坑”

    Unity 在底层默认希望为你做尽可能多的优化,降低使用门槛,比如 BuildSetting 中的 Optimize Mesh Data 选项就是一个典型的例子. 这个选项到底有什么用呢?文档描述为: ...

  2. 你需要知道的10位Java开发牛人

    1.James Gosling 1983 年,Gosling 获得了加州大学的计算机科学学士学位.1990 年,他获得了卡内基梅隆大学的计算机科学博士学位,师从 BobSproull.在攻读博士期间, ...

  3. poj 1265 Area(Pick定理)

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5666   Accepted: 2533 Description ...

  4. Bzoj 2763: [JLOI2011]飞行路线 dijkstra,堆,最短路,分层图

    2763: [JLOI2011]飞行路线 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1728  Solved: 649[Submit][Statu ...

  5. 鸟哥的Linux私房菜 第十八章、认识系统服务 (daemons)

    什么是 daemon 与服务 (service) Linux Daemon (守护进程)是运行在后台的一种特殊进程.它独立于控制终端并且周期性地执行某种任务或等待处理某些事件.它不需要用户输入就能运行 ...

  6. VS2013/2012 下无法打开 源 文件“stdafx.h”的解决方法

    VS2013/2012下代码一写上去保存就报错了,下方提示无法打开 源 文件“stdafx.h” 如图: 百度了一下,对于VS2010有这样的方法可以解决: 在项目属性中展开C/C++,选择常规,在附 ...

  7. 一次mysql瘫痪解救

    最近手机app项目访问流量逐步的增加,对服务端webapi考验极大,是在一次新的业务消息推送后,极光推送给手机接受到的客户端达到19万个,此时app立马开始访问速度变慢了,用户体验相当差 客服接到的问 ...

  8. Foundation与coreFoundation的相互转换

    今天在整理以前的一些琐碎知识,今天就分享一个Foundation与coreFoundation的相互转换细节问题,其中的引用计数器是需要考虑的方面.   ARC 环境下,CoreFoundation框 ...

  9. 【转】android多分辨率适配

    前一阶段开发android项目,由于客户要求进行多分辨率适配,能够支持国内主流的分辨率手机.因此经过了几次开发走了很多弯路,目前刚刚领略了android多分辨率适配的一些方法. 先介绍一下所走的弯路, ...

  10. eclipse package,source folder,folder区别及相互转换

    今天遇到一个问题:在com.a.b.c这个包路径下建一个package,但是不知为什么就会自动编程folder,而且在这个“package”下的所有property文件读不到.所以看了一下文章:在ec ...