@@Creating DLL in @@

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2007
Posts: 113
Reputation: abhi_elementx is an unknown quantity at this point 
Solved Threads: 6
abhi_elementx's Avatar
abhi_elementx abhi_elementx is offline Offline
Junior Poster

@@Creating DLL in @@

 
0
  #1
Feb 7th, 2008
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
  1. #ifndef _DLLTEST_H
  2. #define _DLLTEST_H
  3.  
  4. #ifdef BUILD_DLL
  5. #define EXPORT _declspec(dllexport)
  6. #else
  7. #define EXPORT _declspec(dllimport)
  8. #endif
  9. EXPORT void Hello();
  10. #endif //end of _DLLTEST_H

//dlltest.cpp
  1. #include "dlltest.h"
  2. #include<iostream>
  3. using namespace std;
  4.  
  5. EXPORT void Hello(){
  6. cout<<"This is DLL test";
  7. }

//hello.cpp
  1. #include "dlltest.h"
  2. int main(){
  3. Hello();
  4. }

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?)
PEACE !
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: @@Creating DLL in @@

 
0
  #2
Feb 8th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 113
Reputation: abhi_elementx is an unknown quantity at this point 
Solved Threads: 6
abhi_elementx's Avatar
abhi_elementx abhi_elementx is offline Offline
Junior Poster

Re: @@Creating DLL in @@

 
0
  #3
Feb 9th, 2008
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:
  1. myfile.cpp:
  2.  
  3. #include "dll.h"
  4. .
  5. .
  6. DLLIMPORT void hello(void);
  7. int main(){
  8. hello();
  9. return 0;
  10. }
It gives me errors...
cud you help???
PEACE !
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: @@Creating DLL in @@

 
0
  #4
Feb 9th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC