我正在尝试编译我的程序,它返回此错误:
usr/bin/ld: cannot find -l<nameOfTheLibrary>
Run Code Online (Sandbox Code Playgroud)
在我的makefile中,我使用命令g++
并链接到我的库,这是指向位于其他目录中的库的符号链接.
是否可以选择添加以使其正常工作?
我正在尝试将我的C++编译器更新为C++ 11.我已经搜索了一下,我得出的结论是我必须使用旗帜,-std=c++0x
或者-std=gnu++0x
我不知道很多关于旗帜的事情.谁能帮我?(我正在使用Ubuntu 12.04.)
这是我尝试使用C++ 11中包含的库(即数组)时从编译器获得的错误:
#include <array>
#include <iostream>
int main()
{
std::array<int, 3> arr = {2, 3, 5};
...
}
Run Code Online (Sandbox Code Playgroud)
此文件需要编译器和库支持即将推出的ISO C++标准C++ 0x.此支持目前是实验性的,必须使用-std = c ++ 0x或-std = gnu ++ 0x编译器选项启用.
所以,我变得臭名昭着
未定义的引用'vtable ...
以下代码的错误(有问题的类是CGameModule.)我不能为我的生活理解问题所在.起初,我认为这与忘记给虚拟功能一个身体有关,但据我所知,一切都在这里.继承链有点长,但这里是相关的源代码.我不确定我应该提供哪些其他信息.
注意:构造函数是发生此错误的地方,看起来如此.
我的代码:
class CGameModule : public CDasherModule {
public:
CGameModule(Dasher::CEventHandler *pEventHandler, CSettingsStore *pSettingsStore, CDasherInterfaceBase *pInterface, ModuleID_t iID, const char *szName)
: CDasherModule(pEventHandler, pSettingsStore, iID, 0, szName)
{
g_pLogger->Log("Inside game module constructor");
m_pInterface = pInterface;
}
virtual ~CGameModule() {};
std::string GetTypedTarget();
std::string GetUntypedTarget();
bool DecorateView(CDasherView *pView) {
//g_pLogger->Log("Decorating the view");
return false;
}
void SetDasherModel(CDasherModel *pModel) { m_pModel = pModel; }
virtual void HandleEvent(Dasher::CEvent *pEvent);
private:
CDasherNode *pLastTypedNode;
CDasherNode *pNextTargetNode;
std::string m_sTargetString;
size_t m_stCurrentStringPos;
CDasherModel *m_pModel;
CDasherInterfaceBase …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用自定义类作为关键字unordered_map
,如下所示:
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
class node;
class Solution;
class Node {
public:
int a;
int b;
int c;
Node(){}
Node(vector<int> v) {
sort(v.begin(), v.end());
a = v[0];
b = v[1];
c = v[2];
}
bool operator==(Node i) {
if ( i.a==this->a && i.b==this->b &&i.c==this->c ) {
return true;
} else {
return false;
}
}
};
int main() {
unordered_map<Node, int> m;
vector<int> v;
v.push_back(3);
v.push_back(8);
v.push_back(9);
Node n(v);
m[n] = 0; …
Run Code Online (Sandbox Code Playgroud) 我正在制作一个小词汇记忆程序,其中的单词将随机闪现在我的意思中.我想使用标准的C++库,就像Bjarne Stroustroup告诉我们的那样,但我遇到了一个看似奇怪的问题.
我想将long
整数更改std::string
为能够将其存储在文件中.我也受雇于to_string()
此.问题是,当我使用g ++(版本4.7.0,如其--version标志中所述)编译它时,它说:
PS C:\Users\Anurag\SkyDrive\College\Programs> g++ -std=c++0x ttd.cpp
ttd.cpp: In function 'int main()':
ttd.cpp:11:2: error: 'to_string' is not a member of 'std'
Run Code Online (Sandbox Code Playgroud)
我的程序给出了这个错误:
#include <string>
int main()
{
std::to_string(0);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是,我知道它不可能是因为msdn库清楚地说它存在并且早先关于Stack Overflow的问题(对于g ++版本4.5)说它可以用-std=c++0x
旗标打开.我究竟做错了什么?
有没有办法让gcc/g ++从命令行转储它的预处理器定义?我的意思是__GNUC__
,__STDC__
等等.
我从各种来源(虽然大多数来自我的同事)中听到过,-O3
用g ++ 的优化级别进行编译在某种程度上是"危险的",并且除非被证明是必要的,否则应该避免.
这是真的,如果是的话,为什么?我应该坚持-O2
吗?
我从第三方代码中得到了很多这些警告,我无法修改.有没有办法禁用此警告或至少禁用某些区域(如VC++中的#pragma push/pop)?
例:
list.h:1122: warning: `list<LogOutput*, allocator<LogOutput*> >::node_alloc_' will be initialized after
list.h:1117: warning: `allocator<LogOutput*> list<LogOutput*, allocator<LogOutput*> >::alloc_'
Run Code Online (Sandbox Code Playgroud) 我只是遇到了以下错误(并在线找到了解决方案,但它在Stack Overflow中不存在):
(.gnu.linkonce.[stuff]):对[方法] [目标文件]的未定义引用:(.gnu.linkonce.[stuff]):对[classname]的`typeinfo的未定义引用
为什么可能会得到这些"未定义的typeinfo引用"链接器错误之一?
(如果你能解释幕后发生的事情,可以给予奖励.)