我只是遇到了以下错误(并在线找到了解决方案,但它在Stack Overflow中不存在):
(.gnu.linkonce.[stuff]):对[方法] [目标文件]的未定义引用:(.gnu.linkonce.[stuff]):对[classname]的`typeinfo的未定义引用
为什么可能会得到这些"未定义的typeinfo引用"链接器错误之一?
(如果你能解释幕后发生的事情,可以给予奖励.)
这些命令行选项的目的是什么?请帮助破译以下命令行的含义:
-Wl,--start-group -lmy_lib -lyour_lib -lhis_lib -Wl,--end-group -ltheir_lib
Run Code Online (Sandbox Code Playgroud)
显然它与链接有关,但GNU手册很安静,究竟是分组的意思.
我正在使用Eclipse-CDT在Ubuntu x64上设置一个C++项目.我基本上是在打招呼世界并链接到商业第三方图书馆.
我已经包含了链接到其库的头文件,但我仍然遇到链接器错误.除了明显的问题之外,这里是否存在一些可能的问题(例如我99%肯定我正在链接到正确的库).
Eclipse说:
Building target: LinkProblem Invoking: GCC C++ Linker g++ -L/home/notroot/workspace/somelib-3/somelib/target/bin -o"LinkProblem" ./src/LinkProblem.o -lsomelib1 -lpthread -lsomelib2 -lsomelib3 ./src/LinkProblem.o: In function `main': /home/notroot/workspace/LinkProblem/Debug/../src/LinkProblem.cpp:17: undefined reference to `SomeClass::close()' ./src/LinkProblem.o: In function `SomeOtherClass': /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:148: undefined reference to `SomeClass::SomeClass()' /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:148: undefined reference to `vtable for SomeOtherClass' /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:151: undefined reference to `SomeClass::~SomeClass()' ./src/LinkProblem.o: In function `~SomeOtherClass': /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:140: undefined reference to `vtable for SomeOtherClass' /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:140: undefined reference to `SomeClass::~SomeClass()' /home/notroot/workspace/somelib-3/somelib/include/sql/somefile.h:140: undefined reference to `SomeClass::~SomeClass()' collect2: ld returned 1 exit status make: *** …
我正在尝试编译一个使用udis86库的程序.实际上我正在使用库的用户手册中给出的示例程序.但是在编译时,它会给出错误.我得到的错误是:
example.c:(.text+0x7): undefined reference to 'ud_init'
example.c:(.text+0x7): undefined reference to 'ud_set_input_file'
.
.
example.c:(.text+0x7): undefined reference to 'ud_insn_asm'
Run Code Online (Sandbox Code Playgroud)
我使用的命令是:
$ gcc -ludis86 example.c -o example
Run Code Online (Sandbox Code Playgroud)
按照用户手册中的说明进行操作.
显然,链接器无法链接libudis库.但如果我改变命令:
$ gcc example.c -ludis86 -o example
Run Code Online (Sandbox Code Playgroud)
它开始工作.那么可以请某人解释第一个命令的问题是什么?
我正在尝试使用libtommath库.我在Ubuntu linux上使用NetBeans IDE作为我的项目.我已经下载并构建了库,我已经完成了'make install'以将生成的.a文件放入/ usr/lib /并将.h文件放入/ usr/include
它似乎是正确地找到文件(因为我不再得到这些错误,我在安装到/ usr目录之前做了这些错误).
但是,当我创建一个简单的main来调用mp_init(在库中)时,当我尝试创建项目时出现以下错误:
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/main.o.d
gcc -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.c
mkdir -p dist/Debug/GNU-Linux-x86
gcc -o dist/Debug/GNU-Linux-x86/cproj1 build/Debug/GNU-Linux-x86/main.o
build/Debug/GNU-Linux-x86/main.o: In function 'main':
/home/[[myusername]]/NetBeansProjects/CProj1/main.c:18: undefined reference to `mp_init'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/cproj1] Error 1
Run Code Online (Sandbox Code Playgroud)
因此,看起来链接器无法在库中找到该函数,但它就在那里,所以我只是不知道是什么原因造成的.
如果我直接输入gcc命令并跳过makefile,我会得到同样的错误,我也确保静态库也用gcc编译.
编辑添加:
如果我直接编译并使用-l或-L添加库,我会得到同样的错误:
$ gcc -l /usr/lib/libtommath.a main.c
/usr/bin/ld: cannot find -l/usr/lib/libtommath.a
collect2: ld returned 1 exit status
$ gcc -llibtommath.a main.c
/usr/bin/ld: cannot find -llibtommath.a …Run Code Online (Sandbox Code Playgroud) 我通过yum在Fedora 20上安装了boost,我正在尝试一些简单的例子.但是,我无法从日志记录教程中编译第一个示例.
编译g++ -c boosttest.cc工作正常,但当我尝试链接它时,我遇到了很多错误
g++ boosttest.o -o boosttest -lboost_log -lpthread
Run Code Online (Sandbox Code Playgroud)
完整的错误日志:
boosttest.o: In function `main':
boosttest.cc:(.text+0x44): undefined reference to `boost::log::v2s_mt_posix::trivial::logger::get()'
boosttest.cc:(.text+0x9a): undefined reference to `boost::log::v2s_mt_posix::trivial::logger::get()'
boosttest.cc:(.text+0x167): undefined reference to `boost::log::v2s_mt_posix::trivial::logger::get()'
boosttest.cc:(.text+0x1bd): undefined reference to `boost::log::v2s_mt_posix::trivial::logger::get()'
boosttest.cc:(.text+0x28a): undefined reference to `boost::log::v2s_mt_posix::trivial::logger::get()'
boosttest.o:boosttest.cc:(.text+0x2e0): more undefined references to `boost::log::v2s_mt_posix::trivial::logger::get()' follow
boosttest.o: In function `boost::log::v2s_mt_posix::record::reset()':
boosttest.cc:(.text._ZN5boost3log12v2s_mt_posix6record5resetEv[_ZN5boost3log12v2s_mt_posix6record5resetEv]+0x18): undefined reference to `boost::log::v2s_mt_posix::record_view::public_data::destroy(boost::log::v2s_mt_posix::record_view::public_data const*)'
boosttest.o: In function `boost::log::v2s_mt_posix::record boost::log::v2s_mt_posix::sources::basic_composite_logger<char, boost::log::v2s_mt_posix::sources::severity_logger_mt<boost::log::v2s_mt_posix::trivial::severity_level>, boost::log::v2s_mt_posix::sources::multi_thread_model<boost::log::v2s_mt_posix::aux::light_rw_mutex>, boost::log::v2s_mt_posix::sources::features<boost::log::v2s_mt_posix::sources::severity<boost::log::v2s_mt_posix::trivial::severity_level>, void, void, void, void, void, void, void, void, void> >::open_record<boost::parameter::aux::tagged_argument<boost::log::v2s_mt_posix::keywords::tag::severity, …Run Code Online (Sandbox Code Playgroud) 我正在尝试从类中创建一个静态库,但是当我尝试使用它时,我总是会遇到任何未定义引用的错误.我继续的方式是创建像这样的目标文件
g++ -c myClass.cpp -o myClass.o
Run Code Online (Sandbox Code Playgroud)
然后用它包装
ar rcs myClass.lib myClass.o
Run Code Online (Sandbox Code Playgroud)
有一些我通常会忽略这一点.我打赌这是符号的东西.感谢您的任何建议,我知道这很可能是我可以找到的东西,如果阅读一些教程,所以很抱歉再次困扰愚蠢的东西:)
myClass.h:
class myClass{
public:
myClass();
void function();
};
Run Code Online (Sandbox Code Playgroud)
myClass.cpp:
#include "myClass.h"
myClass::myClass(){}
void myClass::function(){}
Run Code Online (Sandbox Code Playgroud)
程序使用类:
#include "myClass.h"
int main(){
myClass mc;
mc.function();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
最后我像这样编译它:
g++ -o main.exe -L. -l myClass main.cpp
Run Code Online (Sandbox Code Playgroud)
错误只是经典:
C:\Users\RULERO~1\AppData\Local\Temp/ccwM3vLy.o:main.cpp:(.text+0x31): undefined
reference to `myClass::myClass()'
C:\Users\RULERO~1\AppData\Local\Temp/ccwM3vLy.o:main.cpp:(.text+0x3c): undefined
reference to `myClass::function()'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud) 我们将代码库分解为静态库.不幸的是,这些库具有循环依赖性; 例如,libfoo.a取决于,libbar.a反之亦然.
我知道处理这个的"正确"方法是使用链接器--start-group和--end-group选项,如下所示:
g++ -o myApp -Wl,--start-group -lfoo -lbar -Wl,--end-group
Run Code Online (Sandbox Code Playgroud)
但在我们现有的Makefile中,问题通常是这样处理的:
g++ -o myApp -lfoo -lbar -lfoo
Run Code Online (Sandbox Code Playgroud)
(想象一下,这扩展到约20个具有复杂相互依赖性的库.)
我一直在通过我们的Makefiles将第二种形式更改为第一种形式,但现在我的同事们问我为什么......除了"因为它更清洁"以及另一种形式存在风险的模糊感,我不这样做有一个很好的答案.
因此,可以连接同一个库多次曾经创造出了问题?例如,如果同一个.o被拉入两次,链接是否会失败?或者是否有任何风险,我们可以结束相同的静态对象的两个副本,创建微妙的错误?
基本上,我想知道链接时间或运行时失败是否有可能多次链接同一个库; 如果是的话,如何触发它们.谢谢.
我只是想分享一下我是如何找到错误的解决方案的
没有实现类程序的定义
运行X/Motif C应用程序时.我发布这个是因为我在网上搜索时只发现了一个对此问题的引用,并且它没有包含任何解决方案.
我设法解决了这个问题,如果你再次遇到这个问题,我想分享我的发现(注意:我不是说我的解决方案总能解决这类错误).
问题
我在运行使用Motif和X Intrinsics工具包的简单C程序时发现了这个问题.
$ gcc -Wall -c push.c
$ gcc -Wall -o push push.o -lXt -lXm
$ ./push
Error: No realize class procedure defined
Run Code Online (Sandbox Code Playgroud)
C源代码如下:
#include <stdio.h>
#include <Xm/Xm.h>
#include <Xm/PushB.h>
/* Prototype Callback function */
void pushed_fn(Widget, XtPointer, XmPushButtonCallbackStruct *);
int main(int argc, char **argv)
{
Widget top_wid, button;
XtAppContext app;
Display* display;
XtToolkitInitialize();
app = XtCreateApplicationContext();
display = XtOpenDisplay(app, "localhost:10.0","push","push", NULL,0, &argc,argv);
top_wid = XtAppCreateShell(NULL, "Form", applicationShellWidgetClass, display, NULL, …Run Code Online (Sandbox Code Playgroud) 代码很简单,本教程基本上是直接的.我正在运行Arch Linux并且存储了OpenCV库/usr/include/.我也检查过以确保它/usr/include在我的PATH中.
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <iostream>
using namespace cv;
int main(int argc, char** argv){
Mat image;
Mat grayImage;
if(!argv[1]){
std::cerr << "No image data!" << std::endl;
return -1;
}
image = imread(argv[1], 1);
cvtColor(image, grayImage, CV_BGR2GRAY);
imwrite("Gray_Image.jpg", grayImage);
namedWindow(argv[1], CV_WINDOW_AUTOSIZE);
namedWindow("Gray Image", CV_WINDOW_AUTOSIZE);
imshow(argv[1], image);
imshow("Gray Image", grayImage);
waitKey(0);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译器进程成功查找并包含这些头文件,但我仍然在编译时得到未定义的引用错误.如果你查看我包含的头文件,他们还包括其他文件/usr/include/opencv2.我检查过,这样的头文件确实存在.
有任何想法吗?
/tmp/ccudBcqD.o: In function `main':
test.cpp:(.text+0xc0): undefined reference to `cv::imread(std::string const&, int)'
test.cpp:(.text+0x11f): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)' …Run Code Online (Sandbox Code Playgroud)