标签: undefined-reference

未定义的引用

当我编译链表的代码时,我得到了一堆未定义的引用错误.代码如下.我一直在编写这两个语句:

g++ test.cpp 
Run Code Online (Sandbox Code Playgroud)

以及

g++ LinearNode.h LinearNode.cpp LinkedList.h LinkedList.cpp test.cpp  
Run Code Online (Sandbox Code Playgroud)

我真的不明白为什么我会收到这些错误,因为我对C++中的类很生疏.我真的可以使用一些帮助.

LinearNode.h:

#ifndef LINEARNODE_H
#define LINEARNODE_H
#include<iostream>

using namespace std;

class LinearNode
{
    public:
        //Constructor for the LinearNode class that takes no arguments 
        LinearNode();
        //Constructor for the LinearNode class that takes the element as an argument
        LinearNode(int el);
        //returns the next node in the set.
        LinearNode* getNext();
        //returns the previous node in the set
        LinearNode* getPrevious();
        //sets the next element in the set
        void setNext(LinearNode* node);
        //sets the previous element …
Run Code Online (Sandbox Code Playgroud)

c++ undefined-reference

23
推荐指数
3
解决办法
18万
查看次数

C头问题:#include和"未定义引用"

好吧,我一直试图用这个工作的时间最长,而我似乎无法让它正常工作.我有三个文件,main.c,hello_world.c,和hello_world.h.无论出于何种原因,他们似乎没有很好地编译,我真的无法弄清楚为什么......

这是我的源文件.首先是hello_world.c:

#include <stdio.h>
#include "hello_world.h"

int hello_world(void) {
  printf("Hello, Stack Overflow!\n");
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

然后hello_world.h,简单:

int hello_world(void);
Run Code Online (Sandbox Code Playgroud)

最后是main.c:

#include "hello_world.h"

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

当我把它放入GCC时,这就是我得到的:

cc     main.c   -o main
/tmp/ccSRLvFl.o: In function `main':
main.c:(.text+0x5): undefined reference to `hello_world'
collect2: ld returned 1 exit status
make: *** [main] Error 1

有人能帮帮我吗?我真的坚持这个,但我99%肯定这是一个非常简单的修复.

c gcc header header-files undefined-reference

23
推荐指数
3
解决办法
6万
查看次数

未定义的引用`__gxx_personality_sj0`

使用gcc 4.6尝试执行此代码时:

   #include <iostream>

using namespace std;

#include <bitset>

int main()
{
   //Int<> a;
   long long min = std::numeric_limits<int>::min();
   unsigned long long max = std::numeric_limits<int>::max();
   cout << "min: " << min << '\n';
   cout << "max: " << max << '\n';
   cout << (min <= max);
   std::bitset<64> minimal(min);
   cout << "minimal: " << minimal;

   return 0;
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:
1.未定义引用__gxx_personality_sj
2.未定义引用_Unwind_SjLj_Register
3. undefined引用_Unwind_SjLj_Unregister
4. undefined引用_Unwind_SjLj_Resume

到底是怎么回事?!

c++ gcc linker-errors undefined-reference

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

Qt:信号和插槽错误:未定义引用`vtable for

以下链接示例:http://developer.kde.org/documentation/books/kde-2.0-development/ch03lev1sec3.html

#include <QObject>
#include <QPushButton>
#include <iostream>
using namespace std;

class MyWindow : public QWidget
{
    Q_OBJECT  // Enable slots and signals
    public:
        MyWindow();
    private slots:
        void slotButton1();
        void slotButton2();
        void slotButtons();
    private:
        QPushButton *button1;
        QPushButton *button2;
};

MyWindow :: MyWindow() : QWidget()
{
    // Create button1 and connect button1->clicked() to this->slotButton1()
    button1 = new QPushButton("Button1", this);
    button1->setGeometry(10,10,100,40);
    button1->show();
    connect(button1, SIGNAL(clicked()), this, SLOT(slotButton1()));

    // Create button2 and connect button2->clicked() to this->slotButton2()
    button2 = new QPushButton("Button2", this);
    button2->setGeometry(110,10,100,40); …
Run Code Online (Sandbox Code Playgroud)

qt vtable signals-slots undefined-reference

19
推荐指数
2
解决办法
4万
查看次数

OpenCV - 未定义的引用:SurfFeatureDetector和BruteForceMatcher

我正在用C++制作一个程序,它使用2个图像来检测SURF特征,用bruteforcematcher计算匹配并绘制它.

这是代码

#include <cstdio>
#include <string>
#include <vector>
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include "opencv2/features2d/features2d.hpp"


using namespace cv;
using namespace std;

int main(int argc, char **argv){
        if (argc <3) {
            cout << "Usage: " << argv[0] << " imageLocation1 imageLocation2" << endl;

            return -1;
        }

        Mat source1 = imread(argv[1],CV_LOAD_IMAGE_GRAYSCALE);
        Mat source2 = imread(argv[2],CV_LOAD_IMAGE_GRAYSCALE);
        if(source1.empty() || source2.empty()){
        printf("Can't load all the images!");
        return -1;
        }   

//Initialise the Wrapping Class for Surf()
    SurfFeatureDetector detector(400);

//detect : first param: Image, second param: vector (output) …
Run Code Online (Sandbox Code Playgroud)

c++ linker opencv surf undefined-reference

18
推荐指数
2
解决办法
4万
查看次数

RapidXML打印头有未定义的方法

我一直在搞乱在我的一个项目中使用RapidXML.直到我决定使用它写出xml之前,一切都进展顺利.我的代码或多或少如下:

//attempt to open the file for writing
std::ofstream file(fileName.c_str());
if (!file.is_open())
    return false; //the file didn't open

xml_document<> doc;
//creates the contents of the document...
//...
//...

//write the document out to the file
file << doc; //if I remove this line it compiles...but I kinda need this line to output to the file
file.close();
Run Code Online (Sandbox Code Playgroud)

在编译时,我收到以下错误:

In file included from ../Engine/xmlfileloader.cpp:12:0:
../Engine/include/rapidxml_print.hpp: In instantiation of 'OutIt rapidxml::internal::print_node(OutIt, const rapidxml::xml_node<Ch>*, int, int) [with OutIt = std::ostream_iterator<char, char, std::char_traits<char> >; Ch …
Run Code Online (Sandbox Code Playgroud)

c++ rapidxml undefined-reference

18
推荐指数
2
解决办法
5567
查看次数

对"initscr"Ncurses的未定义引用

我正在尝试编译我的项目,我使用lib ncurse.编译器链接文件时我遇到了一些错误.

这是我在Makefile中的标志行:

-W -Wall -Werror -Wextra -lncurses
Run Code Online (Sandbox Code Playgroud)

我已经包含了ncurses.h

一些布局:

prompt$> dpkg -S curses.h
libslang2-dev:amd64: /usr/include/slcurses.h
libncurses5-dev: /usr/include/ncurses.h
libncurses5-dev: /usr/include/curses.h

prompt$> dpkg -L libncurses5-dev | grep .so
/usr/lib/x86_64-linux-gnu/libncurses.so
/usr/lib/x86_64-linux-gnu/libcurses.so
/usr/lib/x86_64-linux-gnu/libmenu.so
/usr/lib/x86_64-linux-gnu/libform.so
/usr/lib/x86_64-linux-gnu/libpanel.s
Run Code Online (Sandbox Code Playgroud)

这是我的错误:

gcc -W -Wall -Werror -Wextra -I./Includes/. -lncurses -o Sources/NCurses/ncurses_init.o -c Sources/NCurses/ncurses_init.c
./Sources/NCurses/ncurses_init.o: In function `ncruses_destroy':
ncurses_init.c:(.text+0x5): undefined reference to `endwin'
./Sources/NCurses/ncurses_init.o: In function `ncurses_write_line':
ncurses_init.c:(.text+0xc5): undefined reference to `mvwprintw'
./Sources/NCurses/ncurses_init.o: In function `ncurses_init':
ncurses_init.c:(.text+0xee): undefined reference to `initscr'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

非常感谢

c linker compilation ncurses undefined-reference

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

未定义的引用C++

我正在尝试编译我从Java转换的第一个合法程序(我运行了一个测试hello world类型程序来检查我的编译器并且它有效).有三个文件:

main.cpp

#include <iostream>
#include "skewNormal.h"

using namespace std;

double getSkewNormal(double, double);

int main(int argc, char **argv) {
    cout << getSkewNormal(10.0, 0.5) << endl;
}
Run Code Online (Sandbox Code Playgroud)

skewNormal.cpp

#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>

using namespace std;

#include <skewNormal.h>

double SkewNormalEvalutatable::evaluate(double x)
{
    return 1 / sqrt(2 * M_PI) * pow(M_E, -x * x / 2);
}

SkewNormalEvalutatable::SkewNormalEvalutatable()
{
}

double sum (double start, double stop,
                               double stepSize,
                               Evaluatable evalObj)
{
  double sum = 0.0, current = start;
  while (current <= …
Run Code Online (Sandbox Code Playgroud)

c++ undefined-reference

15
推荐指数
1
解决办法
4万
查看次数

使用GCC Undefined Behavior Sanitizer

今天我读了一篇关于GCC Undefined Behavior Sanitizer(ubsan)的文章.但是,当我按照那里的步骤(添加-fsanitize=undefined到我的代码中)时,编译器(UCCntu 15.04上的GCC 4.9.2)说某些引用没有定义:

||=== Build: Debug in Entangle (compiler: GNU GCC Compiler) ===|
obj/Debug/EntangleApp.o||In function `EntangleApp::OnInit()':|
/home/ilya/Projects/Entangle/EntangleApp.cpp|31|undefined reference to `__ubsan_handle_type_mismatch'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|31|undefined reference to `__ubsan_handle_load_invalid_value'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|32|undefined reference to `__ubsan_handle_type_mismatch'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|34|undefined reference to `__ubsan_handle_type_mismatch'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|34|undefined reference to `__ubsan_handle_load_invalid_value'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|34|undefined reference to `__ubsan_handle_type_mismatch'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|34|undefined reference to `__ubsan_handle_load_invalid_value'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|35|undefined reference to `__ubsan_handle_type_mismatch'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|37|undefined reference to `__ubsan_handle_type_mismatch'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|37|undefined reference to `__ubsan_handle_load_invalid_value'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|43|undefined reference to `__ubsan_handle_type_mismatch'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|43|undefined reference to `__ubsan_handle_load_invalid_value'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|52|undefined reference to `__ubsan_handle_type_mismatch'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|52|undefined reference to …
Run Code Online (Sandbox Code Playgroud)

c++ gcc undefined-reference undefined-behavior ubsan

15
推荐指数
2
解决办法
5849
查看次数

14
推荐指数
2
解决办法
508
查看次数