error: ld returned 1 exit status 和 error:undefined reference
undefined reference
往往是链接时出现错误,无法解析引用。这篇文章总结的很好undefined reference问题总结
error: ld returned 1 exit status
链接文件没有建立
案例
#include<vector>
#include<algorithm>
#include<iostream>
#include<cstdio>
using namespace std;
class Solution {
static int** nv;
static bool cmp(int x, int y){
int lenx = nv[x][];
int leny = nv[y][];
for(int xi = lenx-, yi = leny-; xi > , yi > ; xi--, yi--){
if(nv[x][xi] < nv[y][yi]) return true;
if(nv[x][xi] > nv[y][yi]) return false;
}
return false;
}
public:
vector<int> lexicalOrder(int n) {
nv = new int* [n+];
for(int i = ; i < n+; i++){
nv[i] = new int[];
}
for(int i = ; i <= n; i ++){
int y = i;
int yi = ;
while(y != ){
nv[i][yi++] = y % ;
y = y / ;
}
nv[i][] = yi;
}
vector<int> v;
for(int i = ; i <= n; i ++){
v.push_back(i);
}
sort(v.begin(), v.end(), cmp);
return v;
}
// vector<int> lexicalOrderList(int start, int last, int s, int n, vector<int>& v){ // } };
int main(){
Solution s;
vector<int> v = s.lexicalOrder();
for(int i = ; i < v.size(); i ++){
cout << v[i] << " ";
}
cout << endl;
return ;
}
编译:

错误在于没有对static成员变量在类外初始化,所以没有对static成员建立的链接文件。
ps:
之所以要把cmp函数写成static,是因为cmp函数如果作为普通成员函数,自带一个this指针作为类指针的隐含参数,不能用于std::sort()函数。
参考文献:
成员函数隐含的this指针
vector排序问题<unresolved overloaded function type>
undefined reference问题总结
error: ld returned 1 exit status 和 error:undefined reference的更多相关文章
- error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status
Windows服务器Azure云编译安装MariaDB教程 www.111cn.net 编辑:future 来源:转载 安装MariaDB数据库最多用于linux系统中了,下文给各位介绍在Window ...
- Arduino上“Collect2.exe: error: ld returned 5 exit status”错误的解决方法
1.运行环境 Windows xp; Arduino1.6.11 IDE. 2.问题 在Arduino编译时,经常出现如下的错误: collect2.exe: error: ld returned 5 ...
- moc_XXXX.o:(.data.rel.ro._ZTI12CalculatorUI[_ZTI12CalculatorUI]+0x10): undefined reference to `typeinfo for QWidget' collect2: error: ld returned 1 exit status make: *** [Makefile:144: myCalculator]
main.cpp:(.text.startup+0x22): undefined reference to `QApplication::QApplication(int&, char**, ...
- Dev C++编写C/C++程序 出现[Error] ld returned 1 exit status报错分析及解决
debug系列第一弹,不知道大家写程序的时候是不是都遇到过如题的报错. 我本人是经常遇到这行熟悉的令人不知所措的报错,可能是我太笨了 有时候百度无果也差不到原因,那就汇总一下目前我遇到的情况吧--持续 ...
- DevC++出现[Error] ld returned 1 exit status,如何解决才好呢?
回答: 代码在vc中没问题,虽然没用过DevC++. 可以把 ld returned 1 exit status前面的详细出错说出来程序是没有问题的,可能的问题最有可能是以下2个1.是你的程序已经在运 ...
- 【DEV C++】 Error: ld returned 1 exit status
一般出现“ld returned 1 exit status”错误都是由于函数名称拼写错误造成的,或者在一个工程中不同的函数使用了同一个函数名,暂时还未遇到其他情况.
- c编译错误[Error] ld returned 1 exit status 解决
[Error] ld returned exit status 编译的过程中出现这个错误极有可能是因为函数名错误引起的,因此回到源码中观察函数名,尤其是那些库函数中的函数.
- gcc/g++ 编译时出现:“对’xxxx’未定义的引用,collect2: error: ld returned 1 exit status” 的错误
出现的问题: 在使用 make 编译实现一个程序时,出现了下面的错误.查看程序源文件所在的目录时发现程序已经完成了编译,并生成了 list_repo.o 的文件,说明是在程序链接生成可执行文件时发生了 ...
- [Error] ld returned 1 exit status
试试重启你的编译器,不稳定的编译器可能会有这种情况.当然不排除其他原因,若是重启了还不好使,就要看代码哪写错喽!!
随机推荐
- 使用事件CreateEvent注意事项
HANDLECreateEvent( LPSECURITY_ATTRIBUTESlpEventAttributes,// 安全属性 BOOLbManualReset,// 复位方式 BOOLbInit ...
- 为什么开发人员对于PHP语言褒贬不一
PHP 语言,作为服务器端开发的脚本语言,在网站开发方面非常有名.从1995年 Rasmus Lerdorf 创建之后,W3Techs 的调查显示在已知的服务端编程语言中,PHP 占了82%.其中不乏 ...
- SQL Server 查看当前活动的锁
第一步: 要查看活动中的锁,如果日前根本就没有活动中的锁怎么办,还好我会自己做一把. begin tran select * from dbo.Nums with(ta ...
- C++模板类中使用静态成员变量(例如Singleton模式)
一个最简单Singleton的例子: ///////// Test.h /////////template <class _T>class CTest{private:_T n;stati ...
- wikioi1688 求逆序对
题目描述 Description 给定一个序列a1,a2,…,an,如果存在i<j并且ai>aj,那么我们称之为逆序对,求逆序对的数目 数据范围:N<=105.Ai<=105. ...
- CentOS bridge br0 kvm libvirt-xml
1,kvm bridge br0配置文件内容实例: ifcfg-em1配置文件内容Example: DEVICE=em1 Bridge=br0 TYPE=Ethernet onboot=yes NM_ ...
- Zepto,Zepto API 中文版,Zepto 中文手册,Zepto API,Zepto API 中文版,Zepto 中文手册,Zepto API 1.0, Zepto API 1.0 中文版,Zepto 1.0 中文手册,Zepto 1.0 API-translate by yaotaiyang
Zepto,Zepto API 中文版,Zepto 中文手册,Zepto API,Zepto API 中文版,Zepto 中文手册,Zepto API 1.0, Zepto API 1.0 中文版,Z ...
- 将常见对象转换成json字符串
public class JsonUtil { public static String objectTojson(Object obj) { StringBuilder json = new Str ...
- poj 2186 (强连通缩点)
题意:有N只奶牛,奶牛有自己认为最受欢迎的奶牛.奶牛们的这种“认为”是单向可传递的,当A认为B最受欢迎(B不一定认为A最受欢迎),且B认为C最受欢迎时,A一定也认为C最受欢迎.现在给出M对这样的“认为 ...
- 前端自动化学习笔记(一)——Yeoman,bower,Grunt的安装
最近看视频学习了前端自动化的一些知识,确实让我大开眼界.感觉前端越来越神器了.同时跟着视频自己也尝试运用了一些工具去构建前端项目,但是中间遇见了很多坑,磕磕绊绊的才实现了一点功能,所以打算记录一下学习 ...