Dll creation problem(definition of dllimport function not allowed)

This is a discussion on Dll creation problem(definition of dllimport function not allowed) within the C++ Programming forums, part of the General Programming Boards category; Hi all, I was following a tutorial on how to make .dll's since this is my first time making 1 ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    2

    Dll creation problem(definition of dllimport function not allowed)

    Hi all,
    I was following a tutorial on how to make .dll's since this is my first time making 1 but when i went to build the .dll i got an error saying :

    definition of dllimport function not allowed
    my header and source is simple :
    Header.h :
    Code:
    #ifndef _DLL_TUTORIAL_H_
    #define _DLL_TUTORIAL_H_
    #include <iostream>
    
    #if defined DLL_EXPORT
    #define DECLDIR __declspec(dllexport)
    #else
    #define DECLDIR __declspec(dllimport)
    #endif
    
    extern "C"
    {
       DECLDIR int Add( int a, int b );
       DECLDIR void Function( void );
    }
    
    #endif

    source.cpp :
    Code:
    #include <iostream>
    #include "tutorial.h"
    
    #define DLL_EXPORT
    
    extern "C"
    {
       DECLDIR int Add( int a, int b )
       {
          return( a + b );
       }
    
       DECLDIR void Function( void )
       {
          std::cout << "DLL Called!" << std::endl;
       }
    }
    What am i doing wrong that i am getting this error?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,651
    >> #define DLL_EXPORT
    You need to include Header.h after that - so that you get the function declarations with "dllexport".

    Don't include <iostream> in the header if nothing in the header needs it.

    You don't need 'extern "C"' in the CPP file if you included Header.h.

    gg

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    2
    i did everything you said but the 2 errors still persist.

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,651
    >> definition of dllimport function not allowed
    That means that "DECLDIR" is "dllimport" in source.cpp - and it shouldn't be.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Replies: 3
    Last Post: 07-19-2008, 03:12 PM
  3. need help converting c dll to cpp
    By *DEAD* in forum C++ Programming
    Replies: 4
    Last Post: 07-11-2007, 10:22 PM
  4. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21