QT中编译时出现的undefined reference to 的问题

我在用QT creator想写一个串口通信程序时,跟很多人一样也是
D:\documents\HelloSerialPort\mainwindow.cpp:20: error: undefined reference to SPComm::isOpen() const
D:\documents\HelloSerialPort\debug\mainwindow.o:-1: In function `ZN10MainWindow23on_pushButton_2_clickedEv':
D:\documents\HelloSerialPort\mainwindow.cpp:30: error: undefined reference to `SPComm::isOpen() const'
看网上说是在pro文件中添加类所在的目录,可是我怎么知道它是哪个目录呢?完全不懂啊,求教!下面是我的文件

//mainwindow.h

 #ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "SPComm.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

private:
    Ui::MainWindow *ui;
    SPComm *m_spcomm;
};

#endif // MAINWINDOW_H

spcomm.h

 #ifndef SPCOMM_H
#define SPCOMM_H

#include <QObject>
#include <QtSerialPort/QtSerialPort>

class SPComm : public QObject
{
    Q_OBJECT
public:
    explicit SPComm(QObject *parent = 0);

    ~SPComm();
    bool isOpen() const;

        void setPortName(const QString &name);
        QString portName() const;

        void setBaudRate(int baudRate);
        int baudRate() const;

        virtual bool open();
        virtual void close();
        virtual bool clear();

        int readData(char *buffer, int count, int timeout = 1000);
        int writeData(char *data, int size);
        int write(char ch);

    protected:
        QString m_portName;
        int m_baudRate;
        QSerialPort *m_serialPort;
signals:

public slots:
};

#endif // SPCOMM_H
0

3个回答

// main.cpp

 #include "mainwindow.h"
#include "spcomm.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

//mainwindow.cpp

 #include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    m_spcomm = new SPComm();
}

MainWindow::~MainWindow()
{
    delete ui;
    delete m_spcomm;
}

void MainWindow::on_pushButton_clicked()
{
    if(m_spcomm->isOpen())
           return;
       m_spcomm->setBaudRate(9600);
       m_spcomm->setPortName("com1");
       if(m_spcomm->open())
           qDebug() << "打开串口成功";
}

void MainWindow::on_pushButton_2_clicked()
{
    if(m_spcomm->isOpen())
            m_spcomm->close();
            qDebug() << "关闭串口成功";
}

//spcomm.cpp

 #include "spcomm.h"

/*SPComm::SPComm(QObject *parent) : QObject(parent)
{

}
*/
static QSerialPort::BaudRate getBaudRate(int baudRate)
{
    switch (baudRate)
    {
    case 1200:
        return QSerialPort::Baud1200;
    case 2400:
        return QSerialPort::Baud2400;
    case 4800:
        return QSerialPort::Baud4800;
    case 9600:
        return QSerialPort::Baud9600;
    case 19200:
        return QSerialPort::Baud19200;
    case 38400:
        return QSerialPort::Baud38400;
    case 57600:
        return QSerialPort::Baud57600;
    case 115200:
        return QSerialPort::Baud115200;
    default:
        return QSerialPort::UnknownBaud;
    }
}

//这个函数用来设置串口的名字
//window 下用"com1"   linux下用"/dev/ttyS0"
void SPComm::setPortName(const QString &name)
{
    m_portName = name;
}

//用来获取串口的名字
QString SPComm::portName() const
{
    return m_portName;
}

//设置波特率 9600  19200  38400
void SPComm::setBaudRate(int baudRate)
{
    m_baudRate = baudRate;
}
//用来打开串口,调用前,先设置串口名字和波特率
bool SPComm::open()
{
    if (m_serialPort->isOpen())
    {
        return true;
    }

    m_serialPort->setPortName(m_portName);
    m_serialPort->setBaudRate(getBaudRate(m_baudRate));
    m_serialPort->setParity(QSerialPort::NoParity);
    m_serialPort->setDataBits(QSerialPort::Data8);
    m_serialPort->setStopBits(QSerialPort::OneStop);
    m_serialPort->setFlowControl(QSerialPort::NoFlowControl);
    m_serialPort->setReadBufferSize(1024);
    return m_serialPort->open(QSerialPort::ReadWrite);
}
//用来关闭串口
void SPComm::close()
{
    if (m_serialPort->isOpen())
    {
        m_serialPort->close();
    }
}
//重启串口,清楚数据
bool SPComm::clear()
{
    if (m_serialPort->isOpen())
    {
        m_serialPort->clear();
        this->close();
        return this->open();
    }
    return false;
}
//用来接收串口发来的数据
int SPComm::readData(char *buffer, int count, int timeout)
{
    int len = 0;
    forever
    {
        int n = m_serialPort->read(&buffer[len], count - len);
        if (n == -1)
        {
            return -1;
        }
        else if (n == 0 && !m_serialPort->waitForReadyRead(timeout))
        {
            return -2;
        }
        else
        {
            len += n;
            if (count == len)
                break;
        }
    }

    return len;
}
//发送数据到串口  比如发送协议
int SPComm::writeData(char *data, int size)
{
    int len = 0;
    forever
    {
        int n = m_serialPort->write(&data[len], size - len);
        if (n == -1)
        {
            return -1;
        }
        else
        {
            len += n;
            if (size == len)
                break;
        }
    }

    return len;
}
//别忘记了
//构造函数 添加初始化数据
SPComm::SPComm(QObject *parent) : QObject(parent)
{
    m_serialPort = new QSerialPort();
    m_baudRate = 9600;
    m_portName = "";
}
//析构的时候  删除 数据
SPComm::~SPComm()
{
    delete m_serialPort;
}

0

不知道是要在pro文件中添加什么呢?

0

增加下面段语句
bool SPComm::isOpen() const
{
if(m_serialPort->isOpen())
return true;
else
return false;
}

0
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
QT中编译时出现的undefined reference to ''
这是我QT .pro里面加的rn LIBS += -L../ffmpeg/lib/libavcodec.dll.arnrn我想要调用该库中的avcodec_register_all();函数rn 于是就出现 错误:undefined reference to `avcodec_register_all'rn :-1: 错误:collect2: ld returned 1 exit statusrnrn出现该错误,很明显是在编译的时候,该函数没有找到定义。也就是说没有找到该库。rn可是我在.pro中加了LIBS += -L../ffmpeg/lib/libavcodec.dll.a。不知道是什么原因造成的。
XOpenDisplay为什么编译时出现:”undefined reference to XOpenDisplay"?
#include rnrnmain()rnrn Display *display;rnrn display=XOpenDisplay("0:0");rnrn rnrngcc -o x x.c -I/usr/X11R6/Include -L/usr/X11R6 b -IX11rnrn为什么编译时出现:rn”undefined reference to XOpenDisplay"?
关于Qt的问题 undefined reference to
问题是这样的:我用类QSvgRenderer 写了一个小程序,结果报错 rnD:\programing\svg/svgwidget.cpp:3: undefined reference to `_imp___ZN10QSvgWidgetC2EP7QWidget'rnD:\programing\svg/svgwidget.cpp:5: undefined reference to `_imp___ZNK10QSvgWidget8rendererEv'rnD:\programing\svg/svgwidget.cpp:6: undefined reference to `_imp___ZN10QSvgWidgetD2Ev'rnD:\programing\svg/svgwidget.cpp:3: undefined reference to `_imp___ZN10QSvgWidgetC2EP7QWidget'rnD:\programing\svg/svgwidget.cpp:5: undefined reference to `_imp___ZNK10QSvgWidget8rendererEv'rnD:\programing\svg/svgwidget.cpp:6: undefined reference to `_imp___ZN10QSvgWidgetD2Ev'rn....rn应该是一些库没链接上?具体应该怎么办呢?rn有一点线索rn在预处理命令里,我用#include 是不行的rn必须用#include rn求大神指点
qt 当中undefined reference to
/home/sdust/untitled1/mainwindow.cpp:154: rn我自己写了个函数bool IsValidEmail(string)rn运行提示rnerror: undefined reference to `MainWindow::IsValidEmail(std::string)'rn急~~~
QT编译错误 undefined reference to
编译QT遇到如下错误,请问怎么解决rn[img=https://img-bbs.csdn.net/upload/201706/22/1498118569_898383.png][/img]
c++ 编译时报错 "undefined reference to ……"
![编译情况](https://img-ask.csdn.net/upload/201803/17/1521251236_172399.png)rnrn总共有五个文件,Graph.h ,Graph.cpp,diamond.h.diamond.cpp,new.cpprn编译成功的是我把diamond类的声明和定义(Graph的声明和定义也放在了一个文件里,但是没有影响)都放在diamond.cpp里。rnnew.cpp 就是包含了"Graph.h"和"diamond.",然后用diamond创建了一个对象,调用ShapePrint()函数。rnrnGraph.hrn```rn #ifndef _Graph_H_rn#define _Graph_H_rnrnclass shapernrn public:rn void ShapePrint();rn void ShapePrint(int x);rn void ShapePrint(int x,int y);rn int GetLength_x();rn int GetLength_y();rn protected:rn void SetLength_x(int length_x);rn void SetLength_y(int length_y);rn private:rn int length_x ;rn int length_y ;rnrn;rnrn#endifrn```rndiamond.hrnrnrn```rn #include rn#include rn#include "Graph.h"rn#ifndef _diamond_rn#define _diamond_rnclass diamond:public shapernpublic:rn diamond();rn rn diamond(int x);rnrn int GetLength();rnprotected:rn void SetLength(int l);rn rnprivate:rn int length;rn rn;rn#endifrnrn```rnrnrndiamond.cpprn```rn #include "diamond.h"rnusing namespace std;rnvoid diamond::SetLength(int l)rnrn this->length = l;rnrnrnrnint diamond::GetLength()rnrn return length;rnrnrnrndiamond::diamond()rn rn SetLength(7);rn rndiamond::diamond(int l)rn rn SetLength(l);rn rn void diamond::ShapePrint()rn rn int length=GetLength();rn for(int i=1;i<=length;++i)rn rn cout<
编译时奇怪的引用问题,undefined reference
最近想使用activemq做消息处理,在ubuntu12.04上做客户端 http://activemq.apache.org/openwire-c-client.html 。使用activemq项目自带的客户端openwire(c语言),下载源码后,分别编译了apache apr, openwire, activemq, 分别产生了 libapr-1.so, libopenwire.so, libactivemq.so,其中apr放在它自己的安装目录下,后两个在 /usr/lib下。rnrn然后编译openwire提供的main.c,编译没问题,连接就出来了undefined reference to "xx"rnrnmain.c 在 http://svn.apache.org/repos/asf/activemq/sandbox/openwire-c/src/examples/main.crnrn编译命令是rnrngcc -W -Wall -lactivemq -lopenwire -lapr-1 -L/usr/local/apr/lib main.o -o testmqrnrn出错信息(部分):rnmain.o: In function 'die':rnmain.c:(.text+0xf3):undefined reference to 'apr_initialize'rn...rnmain.c:(.text+0x2c5):undefined reference to 'amqcs_send'rn...rnrn如果是amqcs.h或者ow.h里面的函数,都是undefined referencernrn另外,这些代码都是C,没有c++,ow.h 可以看rnhttp://svn.apache.org/repos/asf/activemq/sandbox/openwire-c/src/libopenwire/ow.hrnrnamqcs.h 在 http://svn.apache.org/repos/asf/activemq/sandbox/openwire-c/src/libactivemq/amqcs.hrnrn谢谢回复!
【错误笔记】NDK编译时出现undefined reference to 'stderr' 问题
文章目录一、问题描述:二、问题分析:三、解决方法:四、android系统版本 和 API 对应表 一、问题描述: NDK版本:ndk16b; 使用 NDK 编译工具编译程序的时候,有时会出现了如下问题: root@XXX_Device:/data/test # ./build.sh [你的源文件路径:行号]: error: undefined reference to 'stderr' coll...
解决使用NDK进行编译时出现undefined reference to function的问题
之前在编译jni时出现了undefined reference to function这个问题,查阅相关资料说是可能链接的库问题,然后通过各种gcc调整顺序解决了这个问题。这个工程是导师的工程,工程在Linux环境下运行无误,我从Linux环境往Android jni的一个迁移,由于文件的关联比较多代码量异常庞大和复杂(尝试着把方法直接复制到目标cpp中无果),而且我对gcc编译顺序这方面不是特别熟
qt 编译时出现的问题
Running build steps for project spreadsheet...rnStarting: "c:/qt/2010.05/qt/bin/qmake.exe" D:/qtlainx/spreadsheet/spreadsheet.pro -r -spec win32-g++rnThe process "c:/qt/2010.05/qt/bin/qmake.exe" crashed.rnError while building project spreadsheet (target: Desktop)rnWhen executing build step 'qmake'rnrn环境变量都设置了,!
QT Creator 报“undefined reference to” 问题
你不要告诉我没有加LIB库,不是的,因为报错的这些函数根本不在任何库里边,是我我自己写的啊,文件头也include 了,为什么?rnE:\qt\gerbv\gerb_image.c:810: error: undefined reference to `gerber_create_new_net'rnE:\qt\gerbv\gerb_image.c:824: error: undefined reference to `gerber_update_min_and_max'rn。。。。。
QT出现“undefined reference to `vtable for’”问题的原因及解决方法
在添加新文件时系统没有自动添加 Q_OBJECT宏定义,导致编译时qt没有创建moc_xx 文件(用来实现信号槽机制的文件),那么在手动添加Q_OBJECT宏定义后,清除再执行qmake,最后构建一下即可。 ...
ffmpeg 编译时报错 undefined reference to `av_find_stream_info'
在ubuntu 上编译copy的一个demo,编译时出现了下面的错误。(注:编译环境都已搭好,已生成ffplay ffmpeg等)rnrngulinux@ubuntu:~/mmWorkspace$ gcc -o simplest_ffmpeg_player simplest_ffmpeg_player.c -I/usr/local/ffmpeg/include -L/usr/local/ffmpeg/lib -pthread -lavdevice -lavfilter -lavformat -lavcodec -ldl -lSDL -lavutil -lswscale -lmrnsimplest_ffmpeg_player.c: In function ‘main’:rnsimplest_ffmpeg_player.c:64:2: warning: ‘avcodec_alloc_frame’ is deprecated (declared at /usr/local/ffmpeg/include/libavcodec/avcodec.h:3927) [-Wdeprecated-declarations]rn pFrame=avcodec_alloc_frame();rn ^rnsimplest_ffmpeg_player.c:65:2: warning: ‘avcodec_alloc_frame’ is deprecated (declared at /usr/local/ffmpeg/include/libavcodec/avcodec.h:3927) [-Wdeprecated-declarations]rn pFrameYUV=avcodec_alloc_frame();rn ^rn/tmp/ccJOq61p.o: In function `main':rnsimplest_ffmpeg_player.c:(.text+0x6e): [color=#FF0000]undefined reference to `av_find_stream_info'[/color]rncollect2: error: ld returned 1 exit statusrngulinux@ubuntu:~/mmWorkspace$ rnrnrn应该是却了某个库,请大侠们指点一下。非常谢谢哈!
编译时undefined reference to的错误怎么解决
我下了一个叫做SFML的SDK,在codeblocks里面使用,结果怎么弄都弄不好rnrn给的错误是:rn[img=https://img-bbs.csdn.net/upload/201405/10/1399694387_488068.png][/img]rnrn我是这么设置的rn[img=https://img-bbs.csdn.net/upload/201405/10/1399694476_997555.png][/img]rn[img=https://img-bbs.csdn.net/upload/201405/10/1399694482_714952.png][/img]rn[img=https://img-bbs.csdn.net/upload/201405/10/1399694488_637661.png][/img]rn请问这是怎么回事,我该怎么解决啊,搞了4个多小时,还没有弄好rn求帮助啊
ffmpeg 编译时报错 undefined reference to `SDL_Init'
复制了一个ffmpeg的demo,ffmpeg+sdl都搭好了,在编译时出现下面的错误。求大神帮忙解决一下,先在此感谢了哈!rnrnrngulinux@ubuntu:~/mmWorkspace$ gcc -o simplest_ffmpeg_player simplest_ffmpeg_player.c -I/usr/local/ffmpeg/include -L/usr/local/ffmpeg/lib -lavformat -lavcodec -lavutilrnsimplest_ffmpeg_player.c: In function ‘main’:rnsimplest_ffmpeg_player.c:64:2: warning: ‘avcodec_alloc_frame’ is deprecated (declared at /usr/local/ffmpeg/include/libavcodec/avcodec.h:3927) [-Wdeprecated-declarations]rn pFrame=avcodec_alloc_frame();rn ^rnsimplest_ffmpeg_player.c:65:2: warning: ‘avcodec_alloc_frame’ is deprecated (declared at /usr/local/ffmpeg/include/libavcodec/avcodec.h:3927) [-Wdeprecated-declarations]rn pFrameYUV=avcodec_alloc_frame();rn ^rn/tmp/ccJLfKXD.o: In function `main':rnsimplest_ffmpeg_player.c:(.text+0x6e): undefined reference to `av_find_stream_info'rnsimplest_ffmpeg_player.c:(.text+0x1ee): undefined reference to `SDL_Init'rnsimplest_ffmpeg_player.c:(.text+0x1f7): undefined reference to `SDL_GetError'rnsimplest_ffmpeg_player.c:(.text+0x23b): undefined reference to `SDL_SetVideoMode'rnsimplest_ffmpeg_player.c:(.text+0x286): undefined reference to `SDL_CreateYUVOverlay'rnsimplest_ffmpeg_player.c:(.text+0x365): undefined reference to `sws_getContext'rnsimplest_ffmpeg_player.c:(.text+0x415): undefined reference to `sws_scale'rnsimplest_ffmpeg_player.c:(.text+0x421): undefined reference to `SDL_LockYUVOverlay'rnsimplest_ffmpeg_player.c:(.text+0x49b): undefined reference to `SDL_UnlockYUVOverlay'rnsimplest_ffmpeg_player.c:(.text+0x4d5): undefined reference to `SDL_DisplayYUVOverlay'rnsimplest_ffmpeg_player.c:(.text+0x4e1): undefined reference to `SDL_Delay'rnsimplest_ffmpeg_player.c:(.text+0x515): undefined reference to `sws_freeContext'rncollect2: error: ld returned 1 exit statusrnrn个人认为是没有找到SDL.h文件造成的,但在代码里面已经加了这个头文件,请大神帮忙指点一二,再次感谢!!!rn
caffe编译时出现undefined reference错误的原因与解决办法
在make caffe项目的时候,可能会在最后的CXX/LD部分遇到libcaffe.so的链接过程出现undefined reference错误。此类错误出现的原因可能是.so文件进行链接时,其中的符号在链接路径中无法找到。也可能是.so等待链接的符号没有定义。
编译时链接我的动态库出现错误:undefined reference to ‘XXXXXX’
如题,之前没问题,编译了自己的动态库,又编译自己的测试程序,能链接到这个动态库。rn可是,今天,我又重新编译了自己的动态库, 到了编译测试程序的时候,gcc居然报错,错误信息大致这样:rnundefined reference to ‘XXXXXX’rn也就是说动态库里没有这个程序使用的函数。rn但是,我用mn命令列出动态库的符号清单,清单中,我看到了这些被报错不存在的函数名。rn这是什么情况?
gcc编译出现大量undefined reference
各位大牛好,最近网上找了个贪吃蛇的程序练习练习,敲完代码发现程序无法正常编译。rn一、代码一共两个文件(在同一文件夹内):1.snake.c 2.snake.hrn二、具体操作如下:rn 1.我是这样执行的:gcc -o snake.c runrn 2.然后出现一些错误bug,比如漏字错字之类的,我就开始着手改。那个时候没有一个错误提示说undefined reference。rn 3.就在我把最后一个bug改完之后,出现无数undefined referencern三、如截图所示。rn[img=https://img-bbs.csdn.net/upload/201803/16/1521197287_555151.png][/img][img=https://img-bbs.csdn.net/upload/201803/16/1521197294_300602.png][/img]
出现undefined reference to `QScreenShade::run()'
我的程序中QScreenShade是一个动态库.so的类,里面有自定义的函数void run(),我编译这个动态库可以编译过,也能从其他类打开调用,但如果在其他类中调用这个自定义的函数run()里,编译这个类里会出现undefined reference to `QScreenShade::run()',不知这是什么问题,如果我调用show()这样QScreenShade继承来的函数却不会报错,编译可以通过,也可以运行,真是奇怪了。rn
模板类 出现undefined reference to错误
[code=C/C++]rnlinearlist.cpprnrn#include "linearlist.h"rntemplate rnLinearList::LinearList(int nMaxSize)rnrn nMaxListSize = nMaxSize;rn length = 0;rn element = new T[nMaxSize];rnrntemplate rnLinearList::~LinearList()rnrn delete []element;rnrntemplate rnbool LinearList::IsEmpty()constrnrn return length==0;rnrntemplate rnint LinearList::GetLength()constrnrn return length;rnrntemplate rnbool LinearList::Find(int k,T& x)constrnrn if(k<1||k>length)rn return false;rn x = element[k-1];rn return true;rnrntemplate rnint LinearList::Search(const T& x)constrnrn for(int i=0;irnbool LinearList::Delete(int k,T &x)rnrn if(Find(k,x))rn rn for(int i=k;irnbool LinearList::Insert(int k,const T &x)rnrn if(k<0||k>length)rn return false;rn if(length == nMaxListSize)rn return false;rn for(int i=length-1;i>=k;i--)rn rn element[i+1] = element[i];rn rn element[k] = x;rn length++;rn return true;rnrntemplate rnvoid LinearList::OutPut(ostream &out) constrnrn for(int i=0;irnostream &operator<<(ostream &out,const LinearList &x)rnrn x.OutPut(out);rn return out;rnrnrnlinearlist.hrnrn#ifndef LINEARLIST_Hrn#define LINEARLIST_Hrn#include rnusing namespace std;rnrntemplate class LinearList;rntemplate rnostream &operator<<(ostream &out,const LinearList &x);rnrntemplate rnclass LinearListrnrn public:rn LinearList(int nMaxSize=10);rn ~LinearList();rn public:rn bool IsEmpty()const;rn int GetLength()const;rn bool Find(int k,T& x)const;rn int Search(const T& x)const;rn bool Delete(int k,T& x);rn bool Insert(int k,const T& x);rn void OutPut(ostream &out)const;rn private:rn int length;rn int nMaxListSize;rn T *element;rn;rn#endifrnrnmain.cpprnrn#include "linearlist.h"rnint main(void)rnrn LinearList list(5);rn list.Insert(0,1);rn list.Insert(1,2);rn cout<::LinearList(int)'rnmain.cpp:(.text+0x3f): undefined reference to `LinearList::Insert(int, int const&)'rnmain.cpp:(.text+0x63): undefined reference to `LinearList::Insert(int, int const&)'rnmain.cpp:(.text+0x8b): undefined reference to `std::basic_ostream >& operator<< (std::basic_ostream >&, LinearList const&)'rnmain.cpp:(.text+0xac): undefined reference to `LinearList::~LinearList()'rnmain.cpp:(.text+0xc7): undefined reference to `LinearList::~LinearList()'rncollect2: ld returned 1 exit statusrnrn望高手指教rn[/code]
编译出现undefined reference 错误
我现在看的是一个项目中的某部分,项目文件总共大小有50M。我在项目的src源码中的一个模块(例如:osdc)中,增加了两个文件add.cc,add.h.原osdc下面有文件(a.h, a.cc, b.h, b.cc, f.h, f.cc等),其中我实现的时候在a.h中包含了add.h(代码如下:),同时我有add.cc实现了.h中的函数。rn[code=c]#ifndef ADD_Hrn#define ADD_Hrnrntypedef unsigned int usInt;rntypedef char usChar;rn//#define SIZE 300*1024rn#define ArraySize 1024*1024*2rn#define BLOCK_MAX_SIZE 1024*1024rnclass Robin rn public:rn usInt **TA;rn usInt **TB;rn usInt **TC;rn.....rnint rabin(usChar * array,BlockLIinkList* blockLinkList);rn.....rn;rn#endif[/code]rnrn在a.cc中使用:[code=c]rn.....rnBlockLIinkList *blockLinkList = NULL;//使用rabin分块rn Robin *robin = new Robin();rn robin->rabin(temp_data,blockLinkList);rn......rn[/code]rnrn之后,我就执行./configure,然后make,make的时候就出现错误说rnundefined reference to `Robin::rabin(char*, BlockLIinkList*)。rn我不知道是不是因为./configure生成Makefile的时候,不认识我添加的文件(我不熟悉Makefile),我查看通过make之后生成的Makefile时发现,osdc下面除了我新加入的文件add.cc没有,其他所有的.cc文件在Makefile中都能搜索到。rnrn我希望能大家帮帮我,解决这个问题,非常感谢!还有就是针对这种大型项目,如果我增加新的文件的时候需要注意什么?
mingw 出现 undefined reference to 'WinMain@16'
安装完mingw,然后试卷编译一段代码,出现了错误:undefined reference to 'WinMain@16'rn[code=C/C++]rn#include rnint mian(int argc, char *argv[]) rn printf("Hello world");rn return 0;rnrn[/code]rn上面是源代码。rn请问是什么原因导致错误呢?
cups 编程出现 undefined reference
//函数测试小程序 test.cpprnrn#includern#includernusing namespace std;rnint main()rnrn cups_dest_t *dests;rn int num_dests =cupsGetDests(&dests);rn cups_dest_t *dest = cupsGetDest("name",NULL,num_dests,dests);rn cout<<"the name is :"<name<num_options<
gcc编译出现了undefined reference to `exp'
在Ubuntu下编译word.cngcc -lm -pthread word.c -o wordn还是出现了undefined reference to `exp',n后来有gcc -pthread word.c -o word /usr/lib/libm.a则提示没有/usr/lib/libm.a这个文件,nn**有没有有经验的大侠有解决办法?**n
GCC编译出现undefined reference to `pcap_lex'
代码如下rn#include rn#include rn#include /* GIMME a libpcap plz! */rn#include rn#include rn#include rn#include rnrnint main(int argc, char **argv)rnrn char *dev; /* name of the device to use */ rn char *net; /* dot notation of the network address */rn char *mask;/* dot notation of the network mask */rn int ret; /* return code */rn char errbuf[PCAP_ERRBUF_SIZE];rn bpf_u_int32 netp; /* ip */rn bpf_u_int32 maskp;/* subnet mask */rn struct in_addr addr;rnrn /* ask pcap to find a valid device for use to sniff on */rn dev = pcap_lookupdev(errbuf);rnrn /* error checking */rn if(dev == NULL)rn rn printf("%s\n",errbuf);rn exit(1);rn rnrn /* print out device name */rn printf("DEV: %s\n",dev);rnrn /* ask pcap for the network address and mask of the device */rn ret = pcap_lookupnet(dev,&netp,&maskp,errbuf);rnrn if(ret == -1)rn rn printf("%s\n",errbuf);rn exit(1);rn rnrn /* get the network address in a human readable form */rn addr.s_addr = netp;rn net = inet_ntoa(addr);rnrn if(net == NULL)/* thanks Scott :-P */rn rn perror("inet_ntoa");rn exit(1);rn rnrn printf("NET: %s\n",net);rnrn /* do the same as above for the device's mask */rn addr.s_addr = maskp;rn mask = inet_ntoa(addr);rn rn if(mask == NULL)rn rn perror("inet_ntoa");rn exit(1);rn rn rn printf("MASK: %s\n",mask);rnrn return 0;rnrn
c 中使用 minixml 出现 undefined reference to
在使用 minixml 解析xml ,编译可以通过,但是运行时会出现rnmain.c:12: undefined reference to `mxmlLoadFile'rnmain.c:17: undefined reference to `mxmlFindElement'rnmain.c:20: undefined reference to `mxmlElementGetAttr'rnmain.c:21: undefined reference to `mxmlElementGetAttr'rnmain.c:25: undefined reference to `mxmlFindElement'rnmain.c:28: undefined reference to `mxmlFindElement'rnmain.c:33: undefined reference to `mxmlDelete'rnrn(本身是写java的 因为需求要c 解,看了一下午也没看出啥,求解答)rnrn代码如下rnrn[code=text]#includern#includern#includern#includernrnint main()rnrn FILE *fp;rn mxml_node_t *tree,*node;rnrn fp = fopen("debug_settings.xml", "r");rn tree = mxmlLoadFile(NULL, fp,MXML_TEXT_CALLBACK);rn fclose(fp);rnrn mxml_node_t *id,*password;rnrn node = mxmlFindElement(tree, tree, "note",NULL, NULL,MXML_DESCEND);rnrn printf(" year:%s \n",mxmlElementGetAttr(node,"year"));rn printf(" date:%s \n",mxmlElementGetAttr(node,"date"));rn printf(" month:%s \n",mxmlElementGetAttr(node,"month"));rnrnrnrn id = mxmlFindElement(node, tree, "id",NULL, NULL,MXML_DESCEND);rn printf("[%s\n",id->child->value.text.string);rnrn password = mxmlFindElement(node, tree, "password",NULL, NULL,MXML_DESCEND);rnrn printf("[%s]\n",password->child->value.text.string);rnrnrn mxmlDelete(tree);rnrn return 0 ;rn[/code]
android jni 编译出现undefined reference问题
undefined reference to 'android::OMXCodec::Create(...)';rn这是在哪个库里面定义的呢?libstagefright?
undefined reference to ... 问题
在写一个内存池,可是在总是出现如题的这个错误rn[code=c]rn#ifndef MEMORYPOOL_Hrn#define MEMORYPOOL_Hrnrn#include rn#include rnrntemplate rnclass MemoryPoolrnrnpublic:rn MemoryPool(int _size = DEFAULTSIZE);rn ~MemoryPool();rn void* alloc(size_t _size);rn void free(void* element, size_t size);rn int size() const rn return _size;rn rn int vaildSize() const rn return _validsize;rn rnprivate:rn enum DEFAULTSIZE = 5;rn /**rn * @brief pool 用来存放内存块的指针rn */rn std::list pool;rn void expandPool(int _len = DEFAULTSIZE);rn int _size;rn int _validsize;rn;rnrntemplate rnMemoryPool::MemoryPool(int _size):rn _size(0),rn _validsize(0)rnrn expandPool(_size);rnrntemplate rnMemoryPool::~MemoryPool()rnrn std::list::iterator ite = pool.begin();rn for (;ite != pool.end();++ite) rn delete[] (*ite);rn rnrntemplate rnvoid* MemoryPool::alloc(size_t /*_size*/)rnrn if (pool.empty()) rn expandPool();rn rn void* t = pool.front();rn pool.pop_front();rn --_validsize;rn return t;rnrntemplate rnvoid MemoryPool::free(void *element, size_t /*size*/)rnrn pool.push_back(element);rn ++_validsize;rnrntemplate rnvoid MemoryPool::expandPool(int _len)rnrn for (int i = 0;i < _len;++i) rn pool.push_back(static_cast(new char[sizeof(T)]));rn rn _validsize += _len;rn _size += _len;rnrnrnrn#endif // MEMORYPOOL_Hrnrn#ifndef TESTOBJ_Hrn#define TESTOBJ_Hrn#include "memorypool.h"rnrnclass Objrnrnpublic:rn Obj() rn static void newPool() rn mPool = new MemoryPool();rn rn static void deletePool() rn delete mPool;rn rn void* operator new(size_t size) rn return mPool->alloc(size);rn rn void operator delete(void* m, size_t size) rn mPool->free(m,size);rn rnrnprivate:rn static MemoryPool *mPool;rn;rnMemoryPool Obj::mPool = NULL;rnrn#endif // TESTOBJ_Hrnrnrn[/code]rnrnrn[img=https://img-bbs.csdn.net/upload/201304/30/1367282753_435259.png][/img]rnrn希望大虾帮解决下
undefined reference to的问题
小弟我入门不久,遇到一个不懂的问题,我写了如下程序,但是编译的时候出现了问题,不知道怎么修正,望各位师傅解答解答rn#include rnvoid printed(int n);rnint main()rn rn int a = 287;rn printed(287);rn getchar();rn return 0;rnrnvoid printd(int n)rnrn if (n < 0) rn rn putchar('-');rn n = -n;rn rn if (n / 10)rn printed(n / 10);rn putchar(n % 10 + '0');rn
问题关于undefined reference to
在linux下,我装了一个新的库,叫Gosu的2d游戏引擎。用CodeBlocks打开一个范例程序,报了很多的undefined reference to错误,程序include了gosu/gosu.hpp这个文件,我去/usr/include文件夹下,找到了gosu这个文件夹,文件夹下的文件也都是齐的。但是我不知道cpp文件都放在什么地方。安装的时候没报错。是什么原因呢?rnrn以前也常有这种问题,不知道是怎么回事。rnrn是不是编译器设置不对?GNU GCC Compiler。
关于undefined reference to 问题
ab.h文件有这么一段定义rnclass Matrix : public GeneralMatrix // usual rectangular matrixrnrn GeneralMatrix* Image() const; // copy of matrixrnpublic:rn Matrix() rn ~Matrix() rn Matrix(int, int); // standard declarationrn Matrix(const BaseMatrix&); // evaluate BaseMatrixrn void operator=(const BaseMatrix&);rn void operator=(Real f) GeneralMatrix::operator=(f); rn void operator=(const Matrix& m) operator=((const BaseMatrix&)m); rn ...rn ...rn;rnrn主函数k.cpp 下面这段代码出错rn Matrix xhat(n,1);rn Matrix phi(n,n);rn Matrix z(m,1);rn错误信息是类似undefined reference to `Matrix::Matrix(int, int)'rn请问如何解决?rn
undefined reference to'CPU_ZERO'问题
我在使用sched_setaffinity将线程和CPU绑定,但总显示“undefined reference to'CPU_ZERO'”。我在文件头已经写了rn#define __USE_GNUrn#include rn为什么出现这些问题,怎样解决?谢谢
undefined reference to 问题
一个简单的建树,打印树的程序。。上眼。。rn[code=C/C++]rn//Tree.h rn 1 #includern 2 using namespace std; rn 10 template < typename T>rn 11 struct nodern 12 //friend class Act;rn 13 T data; rn 14 node< T > *lch;rn 15 node< T > *rch;rn 16 node();rn 17 //node( const T &x );rn 18 ~node();rn 19 ;rn 20 rn 21 template < typename T >rn 22 class Actrn 23 public:rn 24 void Init( node< T >* tr );rn 25 void Print( node< T >* tr );rn 26 ;rnrn//Tree.cpprn 1 #includern 2 #include"Tree.h"rn 3 using namespace std;rn 4 template < typename T >rn 5 void Act< T >::Init( node< T >* tr )rn 6 rn 7 tr = new node< char >;rn 8 cout << "输入data : " << flush;rn 9 cin >> tr -> data;rn 10 if ( tr -> data != "*" )rn 11 rn 12 Init( tr -> lch );rn 13 Init( tr -> rch );rn 14 rn 15 rn 16 template < typename T >rn 17 void Act< T >::Print(node< T >* tr )rn 18 rn 19 if( tr -> data != "*" )rn 20 rn 21 cout << tr -> data << endl;rn 22 Print(tr -> lch ); rn 23 Print(tr -> rch );rn 24 rn 25 rnrn//Main.cpprn 1 #includern 2 #include"Tree.h"rn 3 using namespace std;rn 4 int main()rn 5 rn 6 node< char >* root;rn 7 Act< char > act;rn 8 act.Init( root );rn 9 act.Print( root );rn 10 rn 11 return 0;rn 12 rn[/code]rn报错:rn/tmp/ccP9q7K0.o: In function `main':rn/home/jzh/ProgrammerExcerse/Main.cpp:8: undefined reference to `Act::Init(node*)'rn/home/jzh/ProgrammerExcerse/Main.cpp:9: undefined reference to `Act::Print(node*)'rncollect2: ld 返回 1rnrn不明白阿。。。。。求解
undefined reference to ....
http://codepad.org/7x4aaR3D 不知道问题是什么。。。
undefined reference
编译时出错:rn.o /e/pocobuild/Foundation/obj/MinGW/ia32/debug_shared/pcre_exec.o /e/pocobuild/Foundation/obj/MinGW/ia32/debug_shared/pcre_ord2utf8.o /e/pocobuild/Foundation/obj/MinGW/ia32/debug_shared/pcre_newline.o /e/pocobuild/Foundation/obj/MinGW/ia32/debug_shared/pcre_fullinfo.o /e/pocobuild/Foundation/obj/MinGW/ia32/debug_shared/pcre_xclass.o -L/e/pocobuild/lib/MinGW/ia32 -liphlpapi -lws2_32 -lpcrernCreating library file: e:/pocobuild/lib/MinGW/ia32/libPocoFoundationd.arne:/pocobuild/Foundation/obj/MinGW/ia32/debug_shared/LoggingFactory.o(.text$_ZNK4Poco12InstantiatorINS_15EventLogChannelENS_7ChannelEE14createInstanceEv[Poco::Instantiator::createInstance() const]+0x59): In function `ZN4Poco12InstantiatorINS_17FormattingChannelENS_7ChannelEED1Ev':rne:/poco-1.3.1-data/Foundation/include/Poco/Instantiator.h: undefined reference to `Poco::EventLogChannel::EventLogChannel()'rne:/pocobuild/Foundation/obj/MinGW/ia32/debug_shared/LoggingFactory.o(.text$_ZNK4Poco12InstantiatorINS_21WindowsConsoleChannelENS_7ChannelEE14createInstanceEv[Poco::Instantiator::createInstance() const]+0x59):e:/poco-1.3.1-data/Foundation/include/Poco/Instantiator.h: undefined reference to `Poco::WindowsConsoleChannel::WindowsConsoleChannel()'rne:/pocobuild/Foundation/obj/MinGW/ia32/debug_shared/SyslogChannel.o(.text+0x6e4): In function `ZN4Poco13SyslogChannel4openEv':rne:/poco-1.3.1-data/Foundation/src/SyslogChannel.cpp:76: undefined reference to `openlog'rne:/pocobuild/Foundation/obj/MinGW/ia32/debug_shared/SyslogChannel.o(.text+0x702): In function `ZN4Poco13SyslogChannel5closeEv':rne:/poco-1.3.1-data/Foundation/src/SyslogChannel.cpp:85: undefined reference to `closelog'rne:/pocobuild/Foundation/obj/MinGW/ia32/debug_shared/SyslogChannel.o(.text+0x762): In function `ZN4Poco13SyslogChannel3logERKNS_7MessageE':rne:/poco-1.3.1-data/Foundation/src/SyslogChannel.cpp:94: undefined reference to `syslog'rnrn看样子是是缺少可查了很久rn第一我包含了//这个只有openlog(),closelog()的声明,缺没有定义,rn我不知道到底怎么回事?是不是g++时 没有带什么时候-l参数如果缺少库是缺那个我也不知道,望高手指点rn
undefined reference to `__asan_report_load8'问题
在ubuntu上写c++,gcc和g++版本都是4.8.4。rn编译的时候出现这个提示:rn[code=c]rnrn1> ~/workspace/fileservicemanager/bin/x64/Debug/liblog4cplus-1.2.so.5.1.6: undefined reference to `__asan_report_load8'rn1> ~/workspace/fileservicemanager/bin/x64/Debug/liblog4cplus-1.2.so.5.1.6: undefined reference to `__asan_report_store2'rn1> ~/workspace/fileservicemanager/bin/x64/Debug/liblog4cplus-1.2.so.5.1.6: undefined reference to `__asan_report_load4'rn1> ~/workspace/fileservicemanager/bin/x64/Debug/liblog4cplus-1.2.so.5.1.6: undefined reference to `__asan_handle_no_return'rn1> ~/workspace/fileservicemanager/bin/x64/Debug/liblog4cplus-1.2.so.5.1.6: undefined reference to `__asan_report_load16'rn1> ~/workspace/fileservicemanager/bin/x64/Debug/liblog4cplus-1.2.so.5.1.6: undefined reference to `__asan_init_v1'rn1> ~/workspace/fileservicemanager/bin/x64/Debug/liblog4cplus-1.2.so.5.1.6:/home/zhaokt/workspace/fileservicemanager/bin/x64/Debug/liblog4cplus-1.2.so.5.1.6: undefined reference to `__asan_report_load8'rn1> ~/workspace/fileservicemanager/bin/x64/Debug/liblog4cplus-1.2.so.5.1.6: undefined reference to `__asan_report_store2'rn1> ~/workspace/fileservicemanager/bin/x64/Debug/liblog4cplus-1.2.so.5.1.6: undefined reference to `__asan_report_load4'rn1> ~/workspace/fileservicemanager/bin/x64/Debug/liblog4cplus-1.2.so.5.1.6: undefined reference to `__asan_handle_no_return'rn1> ~/workspace/fileservicemanager/bin/x64/Debug/liblog4cplus-1.2.so.5.1.6: undefined reference to `__asan_report_load16'rn1> ~/workspace/fileservicemanager/bin/x64/Debug/liblog4cplus-1.2.so.5.1.6: undefined reference to `__asan_init_v1'rn1> ~/workspace/fileservicemanager/bin/x64/Debug/liblog4cplus-1.2.so.5.1.6: undefined reference to `__asan_report_store4'rn1> ~/workspace/fileservicemanager/bin/x64/Debug/liblog4cplus-1.2.so.5.1.6: undefined reference to `__asan_report_load2'rn1> ~/workspace/fileservicemanager/bin/x64/Debug/liblog4cplus-1.2.so.5.1.6: undefined reference to `__asan_report_store8'rnrn[/code]rn链接命令:rn[code=c]rnrng++ -o "~/workspace/fileservicemanager/fileservicemanager/../bin/x64/Debug/fileservicemanager" -Wl,--no-undefined -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -ldl -pthread ~/workspace/fileservicemanager/fileservicemanager/obj/x64/Debug/main.o ~/workspace/fileservicemanager/bin/x64/Debug/libnetwork.so ~/workspace/fileservicemanager/bin/x64/Debug/liblog4cplus-1.2.so.5.1.6rnrn[/code]rnrn在网上没找到好的解决方案,不知道该怎么解决。
请教 undefined reference to的问题
我编译成功了libfaad.a,把这个文件和libfaad下面include目录的2个头文件拷贝到ffmpeg下面,./config -enable-libfaad等成功,但是在进入libavcodec目录,并执行make命令时,在生成libfaad.o之后,连接时出现下面的错误:rn/ffmpegwm5/libavcodec/libfaad.c:316: undefined reference to `NeAACDecClose'rn/ffmpegwm5/libavcodec/libfaad.c:316: undefined reference to `NeAACDecOpen'rnrn而这两个函数我都在libfaad.a上能找到符号的,请问各位大虾知不知道怎么回事? 谢谢。
[vxworks undefined reference to 的问题]
各位大大,知道的麻烦说一下,rn往BSP中添加一块dm9000a的网卡,Feidm9KEndLoad,结果rbuild的时候出现下面的错误,不知道是什么原因?rnC:\Tornado2.2\host\x86-win32\bin\makeSymTbl.bat pentium tmp.o symTbl.crnccpentium -c -fdollars-in-identifiers -g -mcpu=pentiumiii -march=p3 -ansi -nostdlib -fno-b rnuiltin -fno-defer-pop -I.. -IC:\Tornado2.2\target\config\SR-3120 -IC:\Tornado2.2\target\h rn-IC:\Tornado2.2\target\config\comps\src -IC:\Tornado2.2\target\src\drv -DCPU=PENTIUM3 -DTO rnOL_FAMILY=gnu -DTOOL=gnu -DPRJ_BUILD -w symTbl.c -o symTbl.ornccpentium -g -mcpu=pentiumiii -march=p3 -ansi -nostdlib -fno-builtin -fno-defer-pop -I.. - rnIC:\Tornado2.2\target\config\SR-3120 -IC:\Tornado2.2\target\h -IC:\Tornado2.2\target\confi rng\comps\src -IC:\Tornado2.2\target\src\drv -DCPU=PENTIUM3 -DTOOL_FAMILY=gnu -DTOOL=gnu -DP rnRJ_BUILD -c C:\Tornado2.2\target\config\comps\src\dataSegPad.crnldpentium -X -N -e sysInit -Ttext 00308000 \rn dataSegPad.o partialImage.o ctdt.o symTbl.o \rn -T C:\Tornado2.2\target\h\tool\gnu\ldscripts\link.RAM -o vxWorksrnpartialImage.o: In function `vgaWriteString':rnf:\work_project\PCI_project\work_spce\proj\SR-3120\default\C:\Tornado2.2\target\src\drv\se rnrial\m6845Vga.c:1068: undefined reference to `Feidm9kEndLoad'rnmake: *** [vxWorks] Error 0x1rnrnDone.
undefined reference to `WinMain@16'问题
程序调用QTest::qwait函数,但编译提示我undefined reference to `WinMain@16'错误问题,头文件QTest.h加了,pro项目文件里添加了CONFIG += qtestlib,但还是提示上面的错误。
undefined reference to问题!!!
main.c:(.text+0x7): undefined reference to `test' rncollect2: ld returned 1 exit status rnrntest是在mainwindow.h中定义的全局变量,然后在main.cpp和mainwindow.cpp中使用时出现这个问题,求助
相关热词 c# 线程顺序 c#昨天当前时间 c# 多进程 锁 c#mysql图片存取 c# ocx 委托事件 c# 读取类的属性和值 c# out 使用限制 c#获取url的id c#怎么进行分页查询 c# update 集合