-1
#ifndef MYDLL_H
#define MYDLL_H

#endif // MYDLL_H

#ifdef MYDLL_EPORTS
#define MYDLL_API __declspec(dllexport)
#else
#define MYDLL_API __declspec(dllimport)
#endif // MYDLL_EPORTS

MYDLL_API long Fact_none_recursive(int n);
MYDLL_API long Fact_recursive(int n);
MYDLL_API int arlength(string F);

`I'm trying to create a dll and this is my header file(mydll.h) and when I attempt to build or compile the source or impletation file I receive below errors:

14...error:definition of 'int arlength' is marked 'dllimport'
14...error:'string' was not declared in this scope

and this is the impletation of this function in source file (mydll.cpp): `

MYDLL_API int arlength(string F){   `error:expected','or';'before '{'token
                                     error:'string' was not declared in this scope
                                     error:definition of 'int arlength'is marked'dllimport'`
    string line;
    int count=0;
    ifstream inFile (F);
    if(inFile.is_open())
    {
        while(inFile.peek()=!EOF)
        {
            getline(inFile,line);
            count++;
        }
    }
    inFile.close();
    else
        cout<<"couldn't open the file.";
    return count;
}

Are these errors because macros in header file? if not,what causes this error?

I'm trying to make a dll with c++.I declared macros like code samples and dll prototypes I saw and I got some unexpected errors.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
alireza m
  • 9
  • 3
  • Well, what's `string` in that context?? `std::string`? So where's your `#include ` and your `using std::string`?? Also [tag:codeblocks] is quite likely to be completely irrelevant here. – πάντα ῥεῖ Aug 05 '23 at 15:48
  • `#endif // MYDLL_H` is in the wrong place, you should use fully qualified names for the `string` type as well as including the required header, and `MYDLL_EPORTS` could be a typo or it could be missing from your project level preprocessor definitions. There’s a lot there we cannot answer definitively without more information. – tinman Aug 05 '23 at 15:49
  • You also need a header file to define function prototypes, that must be included by your main source file. A couple of examples on how to do it: https://stackoverflow.com/a/34777349/4788546, https://stackoverflow.com/a/73506217/4788546, https://stackoverflow.com/a/30583411/4788546, https://stackoverflow.com/a/44469099/4788546, https://stackoverflow.com/a/47551640/4788546, https://stackoverflow.com/a/54298299/4788546. – CristiFati Aug 17 '23 at 06:13

0 Answers0