PDA

View Full Version : LNK1107 invalid or corrupt file; cannot read at 0x2EB | create & use a simple DLL fil



scoobyDoo
25th August 2015, 00:09
I was able to create a DLL file in the Debug mode, but due to this error I was unable to use it.

Just a message that I wanted to display at the command line.

ChrisW67
25th August 2015, 12:03
What would you like us to do about it? Apart from being able to guess you are use a Microsoft compiler on a Windows machine we have absolutely no information to work with.

scoobyDoo
25th August 2015, 23:19
Here's the code, really nothing. Just trying to create DLL and use it

File Name : createDLL.h
#ifndef CREATEDLL_H
#define CREATEDLL_H

#include "createdll_global.h"

class CREATEDLLSHARED_EXPORT CreateDLL
{

public:
CreateDLL();
void Message();
};

#endif // CREATEDLL_H

File Name : createdll_global.h
#ifndef CREATEDLL_GLOBAL_H
#define CREATEDLL_GLOBAL_H

#include <QtCore/qglobal.h>

#if defined(CREATEDLL_LIBRARY)
# define CREATEDLLSHARED_EXPORT Q_DECL_EXPORT
#else
# define CREATEDLLSHARED_EXPORT Q_DECL_IMPORT
#endif

#endif // CREATEDLL_GLOBAL_H

File Name : createdll.cpp
#include "createdll.h"
#include "qDebug.h"


CreateDLL::CreateDLL()
{
}

void CreateDLL::Message()
{
qDebug() << "Hello from inside DLL";
}

Compiled it, just noticed now, exited with error code -1 ?
M:\QtExamples\build-createDLL-Desktop_Qt_5_5_0_MSVC2012_32bit-Debug exited with code -1

DLL File Size = 46KB

For using the DLL file I created a Console Application.
I loaded the header files createdll.h & createll_global.h into the usingDLL project.

Included the LIBS += "DLL File Path i.e. output from the code given"
Compiled and got the error LNK1107 invalid or corrupt file: cannot read at 0x2D0

ChrisW67
26th August 2015, 21:40
Post the actual pro file you are using for your consumer program. If you have explicitly listed the DLL file in the LIBS variable then that would explain why the linker gets confused. The linker is not expecting the runtime library, it is expecting the link library created at the same time.

scoobyDoo
26th August 2015, 22:37
Post the actual pro file you are using for your consumer program. If you have explicitly listed the DLL file in the LIBS variable then that would explain why the linker gets confused. The linker is not expecting the runtime library, it is expecting the link library created at the same time.

Here's the pro file :

#-------------------------------------------------
#
# Project created by QtCreator 2015-08-26T16:31:15
#
#-------------------------------------------------

QT += core

QT -= gui

TARGET = usingDLL
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app'

LIBS += "D:\Testing\build-createDLL-Desktop_Qt_5_5_0_MSVC2012_32bit-Debug\debug\createDLL.dll"


SOURCES += main.cpp

HEADERS += \
../createDLL/createdll.h \
../createDLL/createdll_global.h

ChrisW67
27th August 2015, 11:05
LIBS += "D:\Testing\build-createDLL-Desktop_Qt_5_5_0_MSVC2012_32bit-Debug\debug\createDLL.dll"



The linker is not expecting the runtime library, it is expecting the link library created at the same time as the DLL was compiled.

The DLL file is a run-time library. In the same folder you will likely find a "createDLL.lib", which is the import or link library. It contains stubs and data about the run-time library that the linker can attach to the remainder of your program so it can access the run-time library at (you guessed it) run time. Your PRO file could look like:


LIBS += "D:/Testing/build-createDLL-Desktop_Qt_5_5_0_MSVC2012_32bit-Debug/debug/createDLL.lib"

although you could use the other syntax (something like):


LIBS += -L"D:/Testing/build-createDLL-Desktop_Qt_5_5_0_MSVC2012_32bit-Debug/debug" -lcreateDLL