how to convert program to lib?

Discussion in 'C++' started by joe, Jan 8, 2004.

  1. joe

    joe Guest

    Hi I have a little executable that has this description for the main
    procedure
    main(int argc, char **argv)
    is it possible to call the program from another program if i compile it as
    a lib? or do i need to modifiay the main function to a different name? do i
    need to create a .h file for the procedure definition? where can i find
    info about this? thanks
    joe, Jan 8, 2004
    #1
    1. Advertising

  2. joe wrote in news:Xns946AD3DA2FDCjosephthecianet@207.69.154.205:

    > Hi I have a little executable that has this description for the main
    > procedure
    > main(int argc, char **argv)
    > is it possible to call the program from another program if i compile
    > it as a lib? or do i need to modifiay the main function to a different
    > name? do i need to create a .h file for the procedure definition?


    Yes (to both question's).

    > where can i find info about this? thanks


    In your compilers documentation or online help, compiler specific
    newsgroups (there FAQ's if they have them). Also maybe there is
    some third party library (with sources preferably) that you can
    get for you compiler, if so, take a look see how they do it.


    The easy part is rewriting the source code:

    rename int main( int argc, char **argv ) to (say (*))

    int yourlib_main( int argc, char **argv )
    {
    // current code.

    // note if you may need to add:

    return 0; // as main() is special in that you can
    // omit its return statement
    }


    Create a header file:

    #if !defined( YOURLIB_GUARD_H )
    #define YOURLIB_GUARD_H

    #if !defined( __cplusplus )
    # error "Must use C++ with yourlib"
    #endif

    int yourlib_main( int argc, char **argv );

    #endif

    I'd also suggest while your at it you may want to change the arguments
    to yourlib_main() to something easier to create maybe:

    #include <vector>
    #include <string>

    int yourlib_main( std::vector< std::string > const &args );

    (*) Replace yourlib/YOURLIB above with something more meaninfull
    and unique to this library you are creating.

    HTH.

    Rob.
    --
    http://www.victim-prime.dsl.pipex.com/
    Rob Williscroft, Jan 8, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Yong
    Replies:
    0
    Views:
    551
    James Yong
    Sep 12, 2005
  2. Praetorian

    Need odbc32.lib odbccp32.lib

    Praetorian, Apr 20, 2006, in forum: C++
    Replies:
    1
    Views:
    1,385
    mlimber
    Apr 20, 2006
  3. Durduran
    Replies:
    10
    Views:
    539
    Durduran
    Jul 30, 2007
  4. Replies:
    3
    Views:
    2,759
  5. Christopher
    Replies:
    4
    Views:
    320
    Christopher
    Nov 1, 2007
Loading...

Share This Page