CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2002
    Posts
    1,798

    How to link a static library struct to a user app ?

    Using a struct object can be quite useful to combine several different data types into a single package. I have tried to do this utilizing a static library, but have run into problems. The main problem is to get the calling app to access the library struct. I have attached a small demo to illustrate the problem. Any help greatly appreciated. Thanks.
    Attached Files Attached Files
    Last edited by Mike Pliam; January 15th, 2016 at 06:50 PM.
    mpliam

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,241

    Re: How to link a static library struct to a user app ?

    To use a global variable in more than one translation unit, declare it in a header using extern specifier...
    Code:
    // MyLib.h
    
    // ...
    
    extern sTensor g_tensor;  // declaration
    ...and define it in an implementation file...
    Code:
    // MyLib.cpp
    
    #include "stdafx.h"
    #include "MyLib.h"
    
    sTensor g_tensor; // definition
    
    // ...
    ...or a little bit better, avoid global variables at all.

    Or at least... as much as possible.

    Also, it no hurts if throwing an eye in
    Last edited by ovidiucucu; January 16th, 2016 at 02:31 PM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: How to link a static library struct to a user app ?

    Quote Originally Posted by Mike Pliam View Post
    Using a struct object can be quite useful to combine several different data types into a single package. I have tried to do this utilizing a static library, but have run into problems. The main problem is to get the calling app to access the library struct.
    Mike, structure is just a data type declaration. Header thing. It just cannot have anything to do with static library, as library is able to contain definitions (function bodies or global variables) but not declarations. Static library has nothing common with java packages or c# assemblies. When programming in C/C++ you'd better think in C/C++ and use proper terminology. Then it would be easier to isolate irrelevant aspects, and therefore, focus on your real issues.
    Best regards,
    Igor

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