码迷,mamicode.com
首页 > 其他好文 > 详细

gcc/g++ 编译时出现:“对’xxxx’未定义的引用,collect2: error: ld returned 1 exit status” 的错误

时间:2017-04-12 21:32:58      阅读:4444      评论:0      收藏:0      [点我收藏+]

标签:init   cal   span   x11   tor   错误   air   lis   开心   

出现的问题:

在使用 make 编译实现一个程序时,出现了下面的错误。查看程序源文件所在的目录时发现程序已经完成了编译,并生成了 list_repo.o 的文件,说明是在程序链接生成可执行文件时发生了问题。

storages/local.o:在函数‘LocalStorage::init(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&)’中:
local.cc:(.text+0x2dae):对‘Getload::get_load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)’未定义的引用
collect2: error: ld returned 1 exit status
Makefile:32: recipe for target bin/list_repo failed
make: *** [bin/list_repo] Error 1

出错原因及解决过程:

1、出错原因:在要编译链接的源文件 list_repo.cc 中缺少了一个需要引用的头文件 getload.h 的声明;

     解决过程:在要实现的源文件中添加所要用到的所有的头文件。在本例中添加 getload.h 的头文件后再次尝试编译,发现错误并没有消失,23333,好气呀,还以为解决的思路有问题。。。。。走了半天弯路,发现了下面的错误。

2、出错原因:在 Makefile 文件的编辑时没有将关联引用的文件 getload.cc 添加上。。。。。好蠢啊。。。。。

     解决过程:

LS_SRCS=list_repo.cc xxxxx.cc xxxxx.cc getload.cc xxxxx.cc xxxxx.cc 

    在 Makefile 文件中添加引用文件 getload.cc 后,再次编译终于通过,开心!!!!!

g++ -o bin/list_repo list_repo.o xxxxxx.o xxxxx.o getload.o xxxxx.o xxxxx.o -O3 -Wall -L../xxxxx/lib -L../xxxxx/lib -lpthread

 

gcc/g++ 编译时出现:“对’xxxx’未定义的引用,collect2: error: ld returned 1 exit status” 的错误

标签:init   cal   span   x11   tor   错误   air   lis   开心   

原文地址:http://www.cnblogs.com/sylar5/p/6701318.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!