Hi,
I am using dev c++ 4.9.9.2 and I am new to DLLs. I am tryig to create a DLL which I am not creating thru the "DLL project" in dev cpp.

Here are my three files:
//dlltest.h

#ifndef _DLLTEST_H
#define _DLLTEST_H

#ifdef BUILD_DLL
#define EXPORT _declspec(dllexport)
#else  
#define EXPORT _declspec(dllimport)
#endif
EXPORT void Hello();
#endif    //end of _DLLTEST_H

//dlltest.cpp

#include "dlltest.h"
#include<iostream>
using namespace std;

EXPORT void Hello(){
  cout<<"This is DLL test";
}

//hello.cpp

#include "dlltest.h"
int main(){
  Hello();
}

I now compile dlltest.cpp by:
g++ -c dlltest.cpp -DBUILD_DLL

I get errors related to the EXPORT keyword in "dlltest.h"
What corrections are required in the 3 files (if any)
And how do I create DLLs ? (are there any compiler options/switches I need to modify/correct?)

You've compiled the code, but you still haven't linked it into DLL and lib files.
Make them with g++ -shared -o dlltest.dll dlltest.o -Wl,--out-implib,libdlltest.a This creates both the DLL and an import library. If all you want is the DLL, ignore the stuff that isn't in red. (That's a -W and lower-case L.)

See this link for more.

Good luck.

Hi there and thanks for the reply,
I will check whatever you have told me to...However there's another thing that i must tell you..
I tried using a DLL project this time which gave me some skeletons (i.e. two files one .h and other .main)
I included a third file in my project(which is part of the project), say hello.cpp
It compiles fine. But when I run the prj(or the hello.cpp file)..It gives me an error saying ..
warning :No host application found. You can specify in the paratmeters,execute menu.
I dont exactly understand the meaning of the message.I mean I did go to the parameters option in the execute menu (I think) and all i found was a parameters field and another field which cud open files of type ".exe" only!
After compilation it creates the DLL as projectname.dll
I created another cpp file (outside the project) and tried calling the function from my DLL project like this:

myfile.cpp:

#include "dll.h"
.
.
DLLIMPORT void hello(void);
int main(){
hello();
return 0;
}

It gives me errors...
cud you help???

When you are using an IDE, the options are usually (as they are in your case) to create either a DLL or an EXE. You can't create both in the same project.

Start a DLL project to make your DLL. Make the DLL.

Then start an normal application project. #include the .h from the DLL project. Make and run the EXE.

A DLL is not designed to be executed like an EXE --the entry point (if any) is different and different operating constraints apply. I think you need to read up a little more on the difference between a DLL and an EXE.

Hope this helps.

This article has been dead for over six months. Start a new discussion instead.