Thread: Need pointing to a guide for importing/exporting library functions

  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733

    Need pointing to a guide for importing/exporting library functions

    I already have this but I sense I'm missing something so I'd like to be pointed to a proper article/document on this sorta thing.
    Code:
    #if defined( __GNUC__ ) || defined( __GNUP__ )
    #define PP_ATTR( TYPE ) __attribute__( TYPE )
    #ifndef _PRAGMA
    #define _PRAGMA( COMMAND ) _Pragma( #COMMAND )
    #endif
    #else
    #define PP_ATTR( TYPE )
    #endif
    
    #ifdef _WIN32
    #define PP_DECLSPEC( TYPE ) __declspec( TYPE )
    #define PP_LIB_EXP __declspec( dllexport )
    #define PP_LIB_IMP __declspec( dllimport )
    #else
    #define PP_DECLSPEC( TYPE )
    #define PP_LIB_EXP PP_ATTR((__visibility__("default")))
    #define PP_LIB_IMP
    #endif

  2. #2
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    By the way I did try searching already but my efforts keep coming up empty

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    Where is the code you posted from? Is it from a particular library you want to use? Which compiler and/or OS are you using to do this? Maybe we need more information to guide you.

  4. #4
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    awsdert, what's the actual problem/task at hand?

    Are you asking for help on managing tricky, compiler/OS/architecture-specific macros, or information on how to manage the entire build process for a portable library?

  5. #5
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Ah no this is intended to be use on the app I mentioned in earlier threads, the app itself is intended to be cross-platform so I'm trying to iron out most of the issues that would reduce portability.
    I figured that the above was the only relevant code for this particular thread, for the most part the main OS's I'm targeting by myself are (in order of priority) Windows/ReactOS, UNIX, POSIX, OSX.

  6. #6
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    I'm not asking for help on managing the build process, if you read the title then you'll see what I want, I'm sure there's plenty of documentation on this I just need some help locating the information, PP_LIB_EXP and PP_LIB_IMP are going to be used by custom libraries relying on a pre-processor only header containing their defines.

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    FYI: These type of macros are normally only needed when building shared/DLL libraries.
    So, if you are only doing static libraries I would forget about this issue.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  8. #8
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Unfortunately at least 1 part of the the app needs shared/dll libraries for it to be capable of reading user selected formats, hence the above macro.

    Edit: Part of the reason for this is to allow the more advanced users to code their own specific formats or simply create support for a format as yet unsupported (kinda a mini extension system)
    Last edited by awsdert; 02-22-2015 at 05:38 PM.

  9. #9
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by awsdert View Post
    Unfortunately at least 1 part of the the app needs shared/dll libraries for it to be capable of reading user selected formats, hence the above macro.
    So, you are writing this libray I would just use the code you posted minus the unneed part of

    Code:
    #ifndef _PRAGMA
    #define _PRAGMA( COMMAND ) _Pragma( #COMMAND )
    #endif
    The most important part is to make sure you put the macros
    PP_LIB_EXP and PP_LIB_IMP in the correct locations. Some compilers are real picky about where the macros are needed when doing C++; not sure if C is as picky.

    Edit: I would change the leading PP_ to a different prefix based on your library unless the PP is already based on your library.

    Tim S.
    Last edited by stahta01; 02-22-2015 at 05:44 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  10. #10
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Ah I guess you didn't get what I was trying to do with the macros entirely but thank you, I honestly thought I had missed something. For reference this is the intended end result:
    Code:
    #ifdef BUILD_EXT_LIB
    #define EXT_LIB_API PP_LIB_EXP
    #else
    #define EXT_LIB_API PP_LIB_IMP
    #endif
    One of my shared libraries is used by both the app and the extension library so this type of macro is helpful there, also the _PRAGMA is defined elsewhere if not defined here, it is for use with macros of this style:
    Code:
    #ifdef _OPENMP
    #define PP_OMP( COMMAND ) _PRAGMA( omp COMMAND )
    #else
    #define PP_OMP( COMMAND )
    #endif

  11. #11
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Well good night, I got work tomorrow, probably won't be checking this thread for a while so any posts should be done as a closure type post.

  12. #12
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Part of the reason for this is to allow the more advanced users to code their own specific formats or simply create support for a format as yet unsupported (kinda a mini extension system)
    O_o

    The mechanism you propose is not "kinda a mini extension system". You are pretty much describing a module system.

    [Edit]
    To be somewhat more specific, you can't just export/import whatever you like as from a resource which you control. You'll have to devise patterns in the interfaces which once found defines the capabilities of a module.
    [/Edit]

    Unfortunately, you'll face more problems implementing a module system than seen just building a shared library by toggling a macro definition.

    You should search around for some variation on "C Plugin Framework". You'll find plenty of tutorials and implementations to guide you.

    Soma
    Last edited by phantomotap; 02-22-2015 at 06:29 PM.
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  13. #13
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Nah that won't be a problem, I've got a struct which each module needs to fill part of with their pointers and return via a single recognisable function, the other part has to be filled by the application so that the 2 are able to communicate properly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Libssh library installation advice/guide
    By Butchy in forum C Programming
    Replies: 2
    Last Post: 04-10-2014, 07:48 PM
  2. Importing/Exporting VS.NET 2003
    By osal in forum C# Programming
    Replies: 1
    Last Post: 09-09-2005, 09:18 AM
  3. Importing DLL / Library Files
    By magic.mike in forum Windows Programming
    Replies: 5
    Last Post: 03-22-2005, 05:47 AM
  4. Replies: 2
    Last Post: 07-15-2004, 06:03 AM
  5. exporting class methods to library results in .lib and .exp
    By Shadow12345 in forum C++ Programming
    Replies: 15
    Last Post: 01-05-2003, 08:01 PM

Tags for this Thread