Archived

This forum has been archived. Please start a new discussion on GitHub.

Problem creating Windows libraries

xdm
xdm La Coruña, Spain
Hello every body

I developing a proyect that is compose for multiple shared libraries same libraries are IceBox services and I create then with the macro
#ifndef ACL_API
#   define ACL_API ICE_DECLSPEC_EXPORT
#endif

other libraries are not IceBox services are only shared libarys for expecific functions of my project , if i don't include the macro in any of this files Visual Studio Net don't generate a .lib file, to solve it i use this macro in not IceBox libraries. This is the correct way to generate .lib files in Windows? now the .lib files are generated ok. but when a project try to link with the generate library therea are a lot of unresolver external functios to the clasess in this library.

I only include the macro in one header file of file the libary because the other are generated by slice2cpp. All unresolver external are to the generated files, but the library that include it compile and linking with no errors and warnings

The proyect run's ok in my linux box with not needed to use the macro.

I Attach a Visual Studio soluction with all the code

Slice project include all neded slice definitions
EventService a util library for dispact events in my classes

AclService a util library to control access to objects

OnRez a libary that define a base object for use in other services

Comments

  • xdm
    xdm La Coruña, Spain
    project files

    the project files for Visua studio
  • bernard
    bernard Jupiter, FL
    This is not the recommended way to use these macros. You should instead:
    * choose a different macro name for each DLL that exports symbols
    * by default, import (ICE_DECLSPEC_IMPORT), not export. This corresponds to the situation when other code uses the library, as opposed to implement it
    * set the macro to ICE_DECLSPEC_EXPORT when you build that library

    Cheers,
    Bernard
  • xdm
    xdm La Coruña, Spain
    ICE_DECLSPEC_IMPORT

    hello again

    my problem continue

    I have a proyect that implement a library this proyect is compose for netxt
    sources files Acl.h ,AclAdmin.h,AclServer.h,AcliI.h the three first files are genarete by slice2cpp and i not changue nothing in this files.

    AclI is the servant implementation for class Acl.

    In AclI.h i define the next macro
    #ifndef ACL_API
    #   define ACL_API ICE_DECLSPEC_EXPORT
    #endif
    
    class ACL_API AclI : virtual public Acl
    {
        //My clas implementation
    }
    
    

    In want to buil ohter library that use this

    my other library has a Class called OnRez that implements AclAdmin interface
    and this class has a referece to and Acl object

    slice code for OnRez class
                 class OnRez implements AclAdmin
                  {
                       Acl* myAcl;
                  }
    

    I implement this servant in OnRezI class
     #ifndef ON_REZ_API
    #   define ON_REZ_API ICE_DECLSPEC_EXPORT
    #endif
    
    
    #define ACL_API_IMPORT ICE_DECLSPEC_IMPORT
    
     class ON_REZ_API OnRezI : virtual public OnRez
     {
    
     }
    

    All cllases compiles ok but when OnRezI try to link there are unresolved references to AclAdmin object that is compile in Acl project
    IceInternal::Handle __thiscall IceProxy::AclAdmin::__createDelegateD(void)" 
    (?__createDelegateD@AclAdmin@IceProxy@@EAE?AV?$Handle@VObject@
    Ice@IceDelegateD@@@IceInternal@@XZ)
    
    OnRez.obj : error LNK2001: unresolved external symbol "private: virtual class 
    IceInternal::Handle __thiscall IceProxy::AclAdmin::__createDelegateM(void)"
    (?__createDelegateM@AclAdmin@IceProxy@@EAE?AV?$Handle@VObject@
    Ice@IceDelegateM@@@IceInternal@@XZ)
    

    I need to changue samething in to generated classes for correct export?

    I linux my shared libraries are created an linking ok with any of this macros
    and the project is runing with no problems. I linux i only use the macro to
    IceBox services but any of these libraries are IceBox services.

    Thanks for all
  • bernard
    bernard Jupiter, FL
    None of these macros are used on Linux.

    You should use the same definitions as in the generated code (with a different name per DLL):

    #ifndef NAME_API
    # ifdef NAME_API_EXPORTS
    # define NAME_API ICE_DECLSPEC_EXPORT
    # else
    # define NAME_API ICE_DECLSPEC_IMPORT
    # endif
    #endif

    And when you build 'NAME', don't forget to define -DNAME_API_EXPORTS. You don't need to define anything when you use 'NAME'.

    In your (incorrect) build environment, the default is to export, which explains why you get unresolved references when you use another library (the linker expects exported symbols in your .obj files).

    Cheers,
    Bernard
  • xdm
    xdm La Coruña, Spain
    continue undefined

    I changue the macro in AclI.h file of Acl project and added ACL_API_EXPORTS
    to the preprocesor definitions
    #ifndef ACL_API
    # ifdef ACL_API_EXPORTS
    # define ACL_API ICE_DECLSPEC_EXPORT
    # else
    # define ACL_API ICE_DECLSPEC_IMPORT
    # endif
    #endif
    
    class ACL_API AclI : virutal public Acl
    {
      ..........
    }
    

    In OnREz project i changue the macro to and aded the
    prepocersor definition ONREZ_API_EXPORTS
    #ifndef ONREZ_API
    # ifdef ONREZ_API_EXPORTS
    # define ONREZ_API ICE_DECLSPEC_EXPORT
    # else
    # define ONREZ_API ICE_DECLSPEC_IMPORT
    # endif
    #endif
    class OnRezI : virtual public OnRez
    {
    
    }
    



    but i continue with unresolved references to AclAdmin object that is compiled in Acl project and is generated for slice2cpp. I not changued nothing of the genearted code, is neded to changued samething in AclAdmin generated code?

    Note that my OnRez class in onrez project implements AclAdmin in Acl project
    and has and Acl object.

    Note that all undefined references are to AclAdmin:: and never to Acl:: or AclI

    thanks bernad
  • Just have a look at the various Ice projects, such as IcePatch, and how they use the export macros. For example, IcePatch.dsp generates a DLL, and IcePatchC.dsp and IcePatchS.dsp use this library.

    You neither need to change any generated code, nor do you need to write any import/export macros by hand.
  • xdm
    xdm La Coruña, Spain
    thank for all

    looking in your IcePach.ice file i look that in your command use
    --dll-export ICE_PATCH_API
    

    i think that my error is that i don't use --dll-export option.

    Tkanks :D