Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to build a Lib

How to build a Lib

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 663 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kofr
    wrote on last edited by
    #1
    #ifndef CALCLIB_H
    #define CALCLIB_H
    
    #if defined(CALCLIB)
    #define CALCLIB_COMMON_DLLSPEC Q_DECL_EXPORT
    #else
    #define CALCLIB_COMMON_DLLSPEC Q_DECL_IMPORT
    #endif
    namespace CalcLib {
    enum TypeWork : int {
        Addition,
        Subtraction,
        Division,
        Multiplication
    };
    enum ErrorCode : int {
        Div0 = -9,
        WrongTypeWork = -8,
        Ok = 0,
        OperandIsWorng
    };
    }
    
    CALCLIB_COMMON_DLLSPEC double DoIt(int TypeWork, double OperandA, double OperandB, int& ErrorCode);
    
    
    #endif // CALCLIB_H
    
    #include "calclib.h"
    #include <limits>
    
    
    
    double DoIt(int TypeWork, double OperandA, double OperandB, int &ErrorCode)
    {
        switch (TypeWork) {
        case CalcLib::Addition:
            ErrorCode = CalcLib::Ok;
            return OperandA + OperandB;
        case  CalcLib::Subtraction:
            ErrorCode = CalcLib::Ok;
            return OperandA - OperandB;
        case CalcLib::Division:
            if(OperandB == 0) {
                ErrorCode = CalcLib::Div0;
                return std::numeric_limits<double>::infinity();
            }
            ErrorCode = CalcLib::Ok;
            return OperandA / OperandB;
        case CalcLib::Multiplication:
            ErrorCode = CalcLib::Ok;
            return OperandA * OperandB;
        default:
            ErrorCode = CalcLib::WrongTypeWork;
            return 0;
        }
    }
    
    

    When building I get errors in this line
    CALCLIB_COMMON_DLLSPEC double DoIt(int TypeWork, double OperandA, double OperandB, int& ErrorCode);
    :-1: error: LNK2001: unresolved external symbol _WinMainCRTStartup

    debug\src.exe:-1: error: LNK1120: 1 unresolved externals

    D:\dev\testing\DumbCalc\calcLib\calclib.h:24: error: C2144: syntax error: 'double' should be preceded by ';'

    D:\dev\testing\DumbCalc\calcLib\calclib.h:24: error: C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    Compiler is MSVC2015 x86
    What do I do wrong? How to make it work.

    jsulmJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Can you also show your .pro file ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      K 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Can you also show your .pro file ?

        K Offline
        K Offline
        Kofr
        wrote on last edited by Kofr
        #3

        @SGaist

        TEMPLATE = lib
        CONFIG += c++14 exceptions_off rtti_off
        SOURCES += calclib.cpp
        HEADERS += calclib.h
        DEFINES += CALCLIB
        

        the full project
        https://www.dropbox.com/s/d3ttz06dtxrd2i6/DumbCalc.zip?dl=1

        1 Reply Last reply
        0
        • K Kofr
          #ifndef CALCLIB_H
          #define CALCLIB_H
          
          #if defined(CALCLIB)
          #define CALCLIB_COMMON_DLLSPEC Q_DECL_EXPORT
          #else
          #define CALCLIB_COMMON_DLLSPEC Q_DECL_IMPORT
          #endif
          namespace CalcLib {
          enum TypeWork : int {
              Addition,
              Subtraction,
              Division,
              Multiplication
          };
          enum ErrorCode : int {
              Div0 = -9,
              WrongTypeWork = -8,
              Ok = 0,
              OperandIsWorng
          };
          }
          
          CALCLIB_COMMON_DLLSPEC double DoIt(int TypeWork, double OperandA, double OperandB, int& ErrorCode);
          
          
          #endif // CALCLIB_H
          
          #include "calclib.h"
          #include <limits>
          
          
          
          double DoIt(int TypeWork, double OperandA, double OperandB, int &ErrorCode)
          {
              switch (TypeWork) {
              case CalcLib::Addition:
                  ErrorCode = CalcLib::Ok;
                  return OperandA + OperandB;
              case  CalcLib::Subtraction:
                  ErrorCode = CalcLib::Ok;
                  return OperandA - OperandB;
              case CalcLib::Division:
                  if(OperandB == 0) {
                      ErrorCode = CalcLib::Div0;
                      return std::numeric_limits<double>::infinity();
                  }
                  ErrorCode = CalcLib::Ok;
                  return OperandA / OperandB;
              case CalcLib::Multiplication:
                  ErrorCode = CalcLib::Ok;
                  return OperandA * OperandB;
              default:
                  ErrorCode = CalcLib::WrongTypeWork;
                  return 0;
              }
          }
          
          

          When building I get errors in this line
          CALCLIB_COMMON_DLLSPEC double DoIt(int TypeWork, double OperandA, double OperandB, int& ErrorCode);
          :-1: error: LNK2001: unresolved external symbol _WinMainCRTStartup

          debug\src.exe:-1: error: LNK1120: 1 unresolved externals

          D:\dev\testing\DumbCalc\calcLib\calclib.h:24: error: C2144: syntax error: 'double' should be preceded by ';'

          D:\dev\testing\DumbCalc\calcLib\calclib.h:24: error: C4430: missing type specifier - int assumed. Note: C++ does not support default-int

          Compiler is MSVC2015 x86
          What do I do wrong? How to make it work.

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #4

          @Kofr said in How to build a Lib:

          CALCLIB_COMMON_DLLSPEC double DoIt(int TypeWork, double OperandA, double OperandB, int& ErrorCode);

          Why do you name the first parameter same as your first enum (TypeWork) and same for ErrorCode?!
          Don't you mean:

          CALCLIB_COMMON_DLLSPEC double DoIt(CalcLib::TypeWork typeWork, double OperandA, double OperandB, CalcLib::ErrorCode &errorCode);
          

          I can build your project after adding

          #include <QtCore/QtGlobal>
          

          in calclib.h

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          3

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved