Tag: g ++

如何加快g ++编译时间(使用大量模板时)

这个问题可能有点奇怪,但是我怎样才能加快编译时间? 我的C ++代码大量使用boost和模板。 我已经尽可能多地从头文件中移出并使用了-j选项,但编译(和链接)仍然需要相当长的一段时间。 有没有分析我的代码的工具,并指出了编译器的瓶颈? 或者可以以某种方式configuration运行在我的代码上的编译器? 这将是非常好的,因为有时我有印象,我花了太多的时间凝视编译器控制台日志…

“g ++ -Wall test.cpp -o test”中的“-Wall”是干什么用的?

-o更改输出文件名(我发现使用–help) 但我找不到什么 – -Wall ?

cc1plus:错误:无法识别的命令行选项“-std = c ++ 11”与g ++

我正在尝试使用g++和-std=c++11或c++0x标志进行编译。 但是,我得到这个错误 cc1plus: error: unrecognized command line option "-std=c++11" g ++ –version g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-54) Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

如何判断头文件包含在哪里?

我怎么知道g ++能够find包含文件? 基本上如果我 #include <foo.h> g ++将扫描searchpath,使用任何包含选项来添加或改变path。 但是,在几天结束的时候,有没有一种方法可以告诉g ++select编译的foo.h的绝对path? 特别相关的是,如果在无数的searchpath中有多个foo.h。 有没有办法完成这个…有没有办法让g ++告诉我它的最终searchpath是什么,包括默认和所有包含选项?

链接错误“未定义的引用`__gxx_personality_v0'”和g ++

可能重复: 链接上的未定义符号___gxx_personality_v0 我遇到以下程序的问题。 // fkt.cpp #include "fkt.h" int add2(int a, int b) { return a+b; } 和标题: // fkt.h int add2(int a, int b); 现在我编译这个: g++ -c fkt.cpp 现在我运行nm并得到: 00000000 T _Z6add2ii U __gxx_personality_v0 当我想在任何地方使用该function时: (.eh_frame+0x12): undefined reference to `__gxx_personality_v0' 我怎么解决这个问题? (我正在使用Ubuntu Linux。)

链接器返回“重定位在符号索引处具有无效符号…”

我正在尝试在Ubuntu上的一些代码。 我试图运行下面的代码 #include <cstdlib> #include <cmath> #include <ctime> #include "random.h" using namespace std; /* Function prototype! */ void initRandomSeed(); int randomInteger(int low,int high){ initRandomSeed(); double d= rand()/(double(RAND_MAX)+1); double s= d*(double(high)-low+1); return int(floor(low)+s); } double randomReal(int low,int high){ initRandomSeed(); double d=rand()/(double(RAND_MAX)+1); double s=d*(double(high)-low+1); return low+s; } bool randomChance(double p){ initRandomSeed(); return randomReal(0,1)<p; } void setRandomSeed(int seed){ […]

错误:使用删除的function

我一直在编写朋友编写的一些C ++代码,并且在编译gcc4.6时遇到了以前从未见过的错误: error: use of deleted function 'GameFSM_<std::array<C, 2ul> >::hdealt::hdealt()' is implicitly deleted because the default definition would be ill-formed: uninitialized non-static const member 'const h_t FlopPokerGameFSM_<std::array<C, 2ul> >::hdealt::h' 编辑:这来自使用boost MSM: Boost网页的代码的一部分 Edit2:在源代码中的任何地方都没有= delete() 。 一般来说,这个错误是什么意思? 发生这种types的错误时,我应该寻找什么?

具有指定模板参数的C ++ 11 make_pair不能编译

我正在玩g ++ 4.7(以后的快照之一),启用了-std = c ++ 11。 我试图编译一些我现有的代码库和一个失败的混淆我的案例。 如果有人能解释发生了什么,我将不胜感激。 这是代码 #include <utility> #include <iostream> #include <vector> #include <string> int main ( ) { std::string s = "abc"; // 1 ok std::pair < std::string, int > a = std::make_pair ( s, 7 ); // 2 error on the next line std::pair < std::string, int > b […]

与g ++编译的奇怪代码

下面的代码用g ++ 4.8.1编译成功: int main() { int(*)(); } 它看起来像一个函数指针的简单声明: int(*f)(); 它不能用clang 3.4和vc ++ 2013进行编译。 这是一个编译器错误还是标准的一个黑暗的地方? 用g ++编译的类似奇怪代码片断列表4.8.1(已更新): int(*)(); int(*); int(*){}; int(*()); 这些奇怪的代码片段的生动的例子 。 更新1: @Ali在评论中增加了一些有趣的信息: 所有4种情况都给出了一个编译错误,使用3.5中继(202594),并使用gcc 4.9中继(20140302)进行编译。 行为与-std=c++98 -pedantic ,除了int(*){}; 这是可以理解的; 扩展的初始化程序列表仅在-std=c++11可用-std=c++11 。 更新2:由于@CantChooseUsernames在他的答案中指出,即使在初始化时它们仍然可以很好地编译,而且即使没有任何启用的优化,g ++也不会为它们生成汇编(既不带有也不带有初始化) int(*)() = 0; int(*) = 0; int(*){} = 0; int(*()) = 0; 现场示例初始化 。 更新3:我真的很惊讶,发现int(*)() = "Hello, world!"; 编译也很好(而int(*p)() = […]

C ++中额外的限定错误

我有一个成员函数,定义如下: Value JSONDeserializer::ParseValue(TDR type, const json_string& valueString); 当我编译源代码时,我得到: 错误:额外资格'JSONDeserializer ::'在成员'ParseValue' 这是什么? 我如何删除这个错误?