标签: linker-errors

什么是未定义的引用/未解析的外部符号错误,我该如何解决?

什么是未定义的参考/未解决的外部符号错误?什么是常见原因以及如何修复/预防它们?

随意编辑/添加您自己的.

c++ c++-faq linker-errors unresolved-external undefined-reference

1418
推荐指数
32
解决办法
52万
查看次数

为什么即使我包含math.h标题,我也会收到"对sqrt的未定义引用"错误?

我是C的新手,我有这个代码:

#include <stdio.h>
#include <math.h>
int main(void)
{
  double x = 0.5;
  double result = sqrt(x);
  printf("The square root of %lf is %lf\n", x, result);
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

但是当我编译它时:

gcc test.c -o test
Run Code Online (Sandbox Code Playgroud)

我收到这样的错误:

/tmp/cc58XvyX.o: In function `main':
test.c:(.text+0x2f): undefined reference to `sqrt'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

为什么会这样?是sqrt()不是在math.h头文件中?我cosh和其他三角函数有同样的错误.为什么?

c linker linker-errors libm

98
推荐指数
5
解决办法
19万
查看次数

架构arm64的重复符号

当我尝试运行我的Xcode项目时,它失败并显示一条错误,指出我有重复的符号.我在网上查找了这些重复但没有运气的地方:

在此输入图像描述

任何想法如何解决这一问题?

xcode objective-c linker-errors ios

95
推荐指数
10
解决办法
8万
查看次数

未定义的引用`sin`

我有以下代码(根据这个问题的基础知识):

#include<stdio.h>
#include<math.h>

double f1(double x)
{
    double res = sin(x);
    return 0;
}

/* The main function */
int main(void)
{
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

gcc test.c我编译它时,我得到以下错误,我无法解决原因:

/tmp/ccOF5bis.o: In function `f1':
test2.c:(.text+0x13): undefined reference to `sin'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

但是,我编写了各种sinmain函数内部调用的测试程序,并且这些程序完美地工作.我必须在这里做一些明显错误的事 - 但它是什么?

c math linker-errors undefined-reference

90
推荐指数
4
解决办法
13万
查看次数

文件是为归档而构建的,而不是被链接的体系结构(i386)

我要构建静态库.我想在我的iPhone和ipad应用程序中使用.当我尝试运行模拟器时,我得到链接错误.我是iOS开发的新手.善意的帮助;

ld:警告:忽略文件/Users/valuelabs/Desktop/DruvaProject/libraries/libnetUtils.a,文件是为存档而构建的,而不是被链接的体系结构(i386)体系结构i386的未定义符号:
"_ OBJC_CLASS _ $ _ netUtils",引用自:ViewController.o中的objc-class-ref ld:找不到架构i386 clang的符号:错误:链接器命令失败,退出代码为1(使用-v查看调用)

我尝试在架构中添加i386.但没有运气

iphone xcode linker-errors ipad ios

76
推荐指数
6
解决办法
7万
查看次数

找不到符号:kUTTypeImage

我从apple的文档中复制了一些代码- 我得到了这两个错误:

Undefined symbols for architecture i386:
  "_kUTTypeImage", referenced from:
      -[ImagePicker imagePickerController:didFinishPickingMediaWithInfo:] in ImagePicker.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

编辑:代码:

- (IBAction) showSavedMediaBrowser {
    [self startMediaBrowserFromViewController: self
                                usingDelegate: (id)self];
}

- (BOOL) startMediaBrowserFromViewController: (UIViewController*) controller
                               usingDelegate: (id <UIImagePickerControllerDelegate,
                                               UINavigationControllerDelegate>) delegate {

    if (([UIImagePickerController isSourceTypeAvailable:
          UIImagePickerControllerSourceTypeSavedPhotosAlbum] == NO)
        || (delegate == nil)
        || (controller == nil))
        return NO;

    UIImagePickerController *mediaUI = [[UIImagePickerController …
Run Code Online (Sandbox Code Playgroud)

objective-c linker-errors ios mobilecoreservices

74
推荐指数
2
解决办法
3万
查看次数

Apple Mach-O链接器警告"找不到选项的目录......"

我只是想摆脱像这样弹出的警告:

ld: warning: directory not found for option '-F/Users/m/Desktop/FacebookSDK'
ld: warning: directory not found for option '-F/Users/m/Desktop/FacebookSDK/FBAudienceNetwork'
ld: warning: directory not found for option '-F/Users/gavin/Downloads/shaffiulla11-bat-b86d81d8adc6'
ld: warning: directory not found for option '-F/Users/gavin/Desktop/shaffiulla11-bat-b86d81d8adc6'
ld: warning: ignoring file /Users/Gavin/Desktop/FacebookSDK/Bolts.framework/Bolts, missing required architecture x86_64 in file /Users/Gavin/Desktop/FacebookSDK/Bolts.framework/Bolts (2 slices)
Run Code Online (Sandbox Code Playgroud)

显然我现在正在使用不同的目录,因为我的驱动器由于逻辑板问题而进行了多次重新格式化,并且我想知道最方便的方法来摆脱这些错误.感谢您的时间和帮助.

objective-c linker-errors linker-warning ios

64
推荐指数
2
解决办法
6万
查看次数

Q_OBJECT抛出'未定义的引用vtable'错误

我在Windows 7 Ultimate 32位上使用Qt Creator 2.0.1和Qt 4.7.0(32位).

请考虑以下代码,这是产生错误的最小代码:

class T : public QObject, public QGraphicsItem
{
    Q_OBJECT

public:
    T() {}

    QRectF      boundingRect() const {return QRectF();}
    void        paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
                      QWidget *widget) {}
};

int main()
{
    T t;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

上面的代码片段导致以下链接器错误:

在函数"T"中:

未定义引用`vtable for T'

未定义引用`vtable for T'

在函数`~T'中:

未定义引用`vtable for T'

未定义引用`vtable for T'

如果我注释掉包含的行Q_OBJECT,它编译得很好.我需要信号和插槽,QGraphicsItem所以我需要Q_OBJECT.

代码有什么问题?谢谢.

c++ qt linker-errors vtable

63
推荐指数
4
解决办法
6万
查看次数

Qt链接器错误:"对vtable的未定义引用"

这是我的标题:

#ifndef BARELYSOCKET_H
#define BARELYSOCKET_H

#include <QObject>
//! The First Draw of the BarelySocket!

class BarelySocket: public QObject
{
    Q_OBJECT

public:
    BarelySocket();
public slots:
    void sendMessage(Message aMessage);
signals:
    void reciveMessage(Message aMessage);

private:
    //   QVector<Message> reciveMessages;
};

#endif // BARELYSOCKET_H
Run Code Online (Sandbox Code Playgroud)

这是我的班级:

#include <QTGui>
#include <QObject>
#include "type.h"
#include "client.h"
#include "server.h"

#include "barelysocket.h"

BarelySocket::BarelySocket()
{
    //this->reciveMessages.clear();
    qDebug("BarelySocket::BarelySocket()");
}

void BarelySocket::sendMessage(Message aMessage)
{
}

void BarelySocket::reciveMessage(Message aMessage)
{
}
Run Code Online (Sandbox Code Playgroud)

我收到链接器错误:

undefined reference to 'vtable for BarelySocket'
Run Code Online (Sandbox Code Playgroud)
  • 这意味着我有一个未实现的虚方法.但我班上没有虚拟方法.
  • 我评论出矢量认为它是原因,但错误并没有消失.
  • Message是一个复杂的struct …

c++ qt linker-errors vtable qobject

60
推荐指数
5
解决办法
3万
查看次数

试图包含一个库,但不断获得'未定义的'消息引用

我正在尝试使用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)

ubuntu compiler-errors build linker-errors static-libraries

59
推荐指数
3
解决办法
11万
查看次数