CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 19

Threaded View

  1. #4
    Join Date
    Jul 2017
    Location
    Greece
    Posts
    130

    Re: Dynamic Library: Do you need to export variables of a class?

    Well I tried this but I get link errors.

    DLL.h
    Code:
    #pragma once
    
    #ifdef DLL_EXPORT
    #	undef DLL_EXPORT
    #	define DLL_EXPORT __declspec(dllexport)
    #else
    #	define DLL_EXPORT __declspec(dllimport)
    #endif
    Printer.h
    Code:
    #pragma once
    #include <iostream>
    #include <string>
    #include "DLL.h"
    
    class Printer
    {
    
    public:
    
    	std::string m_msg;
    
    public:
    	Printer(std::string message);
    	~Printer();
    	void print();
    };
    
    DLL_EXPORT Printer *CreatePrinter(std::string message);
    Printer.cpp
    Code:
    #include "Printer.h"
    
    
    
    Printer::Printer(std::string message) : m_msg(message)
    {
    }
    
    
    Printer::~Printer()
    {
    }
    
    void Printer::print()
    {
    	std::cout << m_msg << std::endl;
    }
    
    Printer *CreatePrinter(std::string message)
    {
    	return new Printer(message);
    }

    Client.cpp
    Code:
    #include <Printer.h>
    
    int main()
    {
    	Printer *p = CreatePrinter("Skata melata");
    
    	p->print();
    
    	delete p;
    
    	return 0;
    }

    Link Errors:
    Code:
    1>Source.obj : error LNK2019: unresolved external symbol "public: __thiscall Printer::~Printer(void)" (??1Printer@@QAE@XZ) referenced in function "public: void * __thiscall Printer::`scalar deleting destructor'(unsigned int)" (??_GPrinter@@QAEPAXI@Z)
    1>Source.obj : error LNK2019: unresolved external symbol "public: void __thiscall Printer::print(void)" (?print@Printer@@QAEXXZ) referenced in function _main
    I don't really understand what you mean. Can you make me an example to see it? Maybe i'll understand this way.
    Last edited by babaliaris; November 8th, 2018 at 04:43 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured