Incomplete type error while using class from my own dll

Pere_Strelka

One more day, one more dumb question on stackoverflow, please excuse me. The idea was to make dll and then import it to another project to use it there, but after including dll header file in second project and writing paths to the .lib and header files I still have these errors:

E0070   incomplete type is not allowed  prjct-1 D:\projects-vs\firstTryWT\prjct-1\prjct-1.cpp   33
C2027   use of undefined type 'stmr::MathProblem'   prjct-1 D:\projects-vs\firstTryWT\prjct-1\prjct-1.cpp   33
C2079   'problem' uses undefined class 'stmr::MathProblem'  prjct-1 D:\projects-vs\firstTryWT\prjct-1\prjct-1.cpp   33  
C3493   'problem' cannot be implicitly captured because no default capture mode has been specified  prjct-1 D:\projects-vs\firstTryWT\prjct-1\prjct-1.cpp   35  

I've tried to rebuild, change some code till I understand that I either already did what is needed or I don't know what is needed. Anyway, here is the code:

Dll header file:

#pragma once

#ifdef STMR_EXPORTS
#define STMR_API __declspec(dllexport)
#else
#define STMR_API __declspec(dllimport)
#endif

#include <vector>
#include <string>

namespace stmr
{
    class STMR_API MathProblem;
    class STMR_API Operation;
}

Definitions of both classes have STMR_API keyword. I have 'STMR_EXPORTS' in C/C++ -> Preprocessor and '$(OutDir)$(TargetName).lib' in Linker -> Advanced -> Import Library so that I have the import lib generated.

main cpp of the project which is supposed to use the dll:

#include <Wt/WApplication.h>
#include <Wt/WBreak.h>
#include <Wt/WContainerWidget.h>
#include <Wt/WLineEdit.h>
#include <Wt/WPushButton.h>
#include <Wt/WText.h>

#include "stmrLib.h"


class HelloApplication : public Wt::WApplication
{
public:
    HelloApplication(const Wt::WEnvironment& env);

private:
    Wt::WPushButton* button_m;
    Wt::WText* summary_m;
};

HelloApplication::HelloApplication(const Wt::WEnvironment& env)
    : Wt::WApplication(env)
{
    button_m = root()->addWidget(std::make_unique<Wt::WPushButton>());
    summary_m = root()->addWidget(std::make_unique<Wt::WText>()); 
    stmr::MathProblem problem = stmr::MathProblem(problemText_m->text().narrow());
    auto solving = [this] {   
        summary_m->setText("This equals " + std::to_string(problem.solve()));
    };
    button_m->clicked().connect(solving);
}

int main(int argc, char** argv)
{
    return Wt::WRun(argc, argv, [](const Wt::WEnvironment& env) {
        return std::make_unique<HelloApplication>(env);
        });
}

I have correct path to the .lib file for dll in Linker -> General -> Additional Library Dependencies and stmr.lib/stmrd.lib in Linker -> Input -> Additional Dependencies for Release/Debug Not sure if the problem in exporting or importing of the dll.

Feedback about question quality is appreciated.

Yakk - Adam Nevraumont

In C++ (prior to modules) the header file needs to expose enough information about a class for another cpp file to create the object or use the type.

You have just forward declared it, which is enough to make pointers or references to the type and nothing else.

These errors have nothing to do with linking or DLLs or exports.

All compilation units that need to make instances or otherwise call methods of your types need to see the class definition. Put it in the headerfile. Method definitions can be in cpp files and exported.

The pImpl pattern may help you hide details, if you do not want to expose them.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Resulting in an `error: incomplete type` while using std::tuple_size

From Dev

Error using Eigen: invalid use of incomplete type ‘const class Eigen

From Dev

Error while running a convolutional network using my own data in Tensorflow

From Dev

Forward declaration of class leads to incomplete type error

From Dev

Error: Variadic template class has incomplete type

From Dev

Template class and 'invalid use of incomplete type' error

From Dev

Invalid use of incomplete type class error when inheriting from class defined externally

From Dev

Using incomplete type in a member function of a class template

From Dev

dereferencing pointer to incomplete type error using strcmp

From Dev

Referring to an object from custom library gives error: "pointer to incomplete class type is not allowed"

From Dev

NodeJS - ES6 - Extend class Error to return my own Type as part of the error response

From Dev

Pointer and Incomplete class type

From Dev

Type error in my own Haskell function

From Dev

Haskell: Patterns matching error with my own type

From Dev

I've derived a class from the list type. But index slicing on my class returns a Python list object, instead of my own object

From Dev

C++ incomplete type error when passing class as function parameter

From Dev

Self-defined class error: incomplete type and can't be defined

From Dev

Qt error Invalid use of incomplete type 'class UI::FrameLess'

From Dev

Using collection initializer on my own class

From Dev

UIButton action is not firing from my own class

From Dev

Error: incomplete type is not allowed

From Dev

Incomplete type is not allowed error

From Dev

c++ template Incomplete type using pointer of class inside template

From Dev

Failing to call a function using GetProcAddress in my own dll

From Java

Using jrawio in my own project, causes an error

From Dev

Tensorflow error using my own data

From Dev

Unknown Type Errors when using functionblocks from my own library project

From Java

Error while using the load class from Java to import property file

From Dev

dereferencing pointer to incomplete type error when using typedef struct in C

Related Related

  1. 1

    Resulting in an `error: incomplete type` while using std::tuple_size

  2. 2

    Error using Eigen: invalid use of incomplete type ‘const class Eigen

  3. 3

    Error while running a convolutional network using my own data in Tensorflow

  4. 4

    Forward declaration of class leads to incomplete type error

  5. 5

    Error: Variadic template class has incomplete type

  6. 6

    Template class and 'invalid use of incomplete type' error

  7. 7

    Invalid use of incomplete type class error when inheriting from class defined externally

  8. 8

    Using incomplete type in a member function of a class template

  9. 9

    dereferencing pointer to incomplete type error using strcmp

  10. 10

    Referring to an object from custom library gives error: "pointer to incomplete class type is not allowed"

  11. 11

    NodeJS - ES6 - Extend class Error to return my own Type as part of the error response

  12. 12

    Pointer and Incomplete class type

  13. 13

    Type error in my own Haskell function

  14. 14

    Haskell: Patterns matching error with my own type

  15. 15

    I've derived a class from the list type. But index slicing on my class returns a Python list object, instead of my own object

  16. 16

    C++ incomplete type error when passing class as function parameter

  17. 17

    Self-defined class error: incomplete type and can't be defined

  18. 18

    Qt error Invalid use of incomplete type 'class UI::FrameLess'

  19. 19

    Using collection initializer on my own class

  20. 20

    UIButton action is not firing from my own class

  21. 21

    Error: incomplete type is not allowed

  22. 22

    Incomplete type is not allowed error

  23. 23

    c++ template Incomplete type using pointer of class inside template

  24. 24

    Failing to call a function using GetProcAddress in my own dll

  25. 25

    Using jrawio in my own project, causes an error

  26. 26

    Tensorflow error using my own data

  27. 27

    Unknown Type Errors when using functionblocks from my own library project

  28. 28

    Error while using the load class from Java to import property file

  29. 29

    dereferencing pointer to incomplete type error when using typedef struct in C

HotTag

Archive