0

I'm trying to build a project with a library (dll) I made. I've never attempted to either load or make a library before and I'm getting the following error.

error: undefined reference to `imp__ZN6NeuronC1Ev'

In Qt, the error is shown in the following line.

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow) <--------------------------- Error indicated here.
{
    ui->setupUi(this);
}

Project File

QT       += core gui

TARGET = Jane
TEMPLATE = app
LIBS += -L quote(C:\Programming\Jane\Jane\Source\Neuron.dll)

SOURCES += main.cpp\
        MainWindow.cpp

HEADERS  += MainWindow.h

FORMS    += MainWindow.ui

Here is one of the classes that I've exported

#ifndef NEURON_H
#define NEURON_H

#include <QList>
#include "Neuron_global.h"
#include <Sensor.h>

class NEURONSHARED_EXPORT Neuron
{
public:
    explicit Neuron();

    const double getOutput() const;
    const double & getWeight() const;

    void setWeight(const double& weight);
private:
    double weight;              // The weight of this neuron.

    QList<Neuron*> neurons;     // This Neuron's children.
    QList<Sensor*> sensors;     // This Neuron's Sensors.
};

#endif // NEURON_H

The NEURONSHARED_EXPORT Marco is defined in "Neuron_global.h"

#ifndef NEURON_GLOBAL_H
#define NEURON_GLOBAL_H

#include <QtCore/qglobal.h>

#if defined(NEURON_LIBRARY)
#  define NEURONSHARED_EXPORT Q_DECL_EXPORT
#else
#  define NEURONSHARED_EXPORT Q_DECL_IMPORT
#endif

#endif // NEURON_GLOBAL_H

If anyone has any advice on how to fix this, I would greatly appreciate it.

Edit: I've added the libNeuron.a file to the LIBS argument in pro file. However, I'm now getting the following error.

LIBS += libNeuron.a

cannot find -lNeuron.a

any ideas?

4
  • Is your DLL built by the same compiler (including version) as the one you're trying to build the Qt project with? Different compilers (or even different revisions of the same compiler) can have different name mangling schemes for C++ functions which can cause the kind of error you're seeing. Commented Jun 28, 2011 at 17:51
  • Is there a reason your ui variable is declared as a pointer? Not doing so would eliminate the need to initialize it with a dynamic memory allocation, eliminating the supposedly offending line, which may or may not help narrow down the problem further. Commented Jun 28, 2011 at 18:34
  • Yea both the same compiler and machine were used for the DLL and the program. Commented Jun 29, 2011 at 16:09
  • The reason the UI variable is a pointer is that is the default setting in QTCreator. I might end up changing that, to see if that helps. Commented Jun 29, 2011 at 16:10

3 Answers 3

1

What are you trying to do?

LIBS += -L quote(C:\Programming\Jane\Jane\Source\Neuron.dll)

It variable contains a lib-files, which project will be linked with, not a library itself!

You should find a lib for the dll or use WINAPI LoadLibrary/GetProcAddres functions to load dll dynamically.

Sign up to request clarification or add additional context in comments.

2 Comments

I think your right. I re-read the LIBS documentation and it only mentions adding dlls to the Symbian platform (strange not for Windows).
LIBS += $$quote(C:\Programming\Jane\Jane\Source\Neuron.dll) Note the "$$", without these the library fails to link. So far everything is working correctly.
0

This is only a quick guess of mine: your trouble is caused c++ name mangling. Google "qt dll c++ name mangling" and find some examples of working dll / client projects.

Comments

0

In this case everything looks right (assuming NEURON_LIBRARY is not defined since you're building under the app template, although Windows v. Linux act differently in this regard).

qmake is known not to pick up all the changes that it ought to so I'd recommend re-running qmake and then your make variant (e.g. make, gmake, nmake):

$ qmake
$ nmake

In some cases, you'll actually need to do a clean (or delete the relevant object files) before everything will be able to link correctly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.