Thread: creating libraries for c++

  1. #1
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608

    creating libraries for c++

    does anyone know of any tutorials etc for creating and using your own header files?
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  2. #2
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    Make New Unit (in dev) and write whatever you want in it .. Then rename it into hello.h and in your application put #include "hello.h" (It has to be added to the project first)
    what does signature stand for?

  3. #3
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    yes i know that. but how would i call to it. or would it be like if i had a header file i made including tons of variables, it would be like the varibales were writtin into my main .cpp document?
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  4. #4
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    If you've got a function in your header file call it this way:
    function() .. just like all other ones
    what does signature stand for?

  5. #5
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    The only difference is that you dont make #include <file.h> put with quotes (") like #include "file.h"
    what does signature stand for?

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by Klinerr1
    yes i know that. but how would i call to it. or would it be like if i had a header file i made including tons of variables, it would be like the varibales were writtin into my main .cpp document?
    Yep, thats pretty much how it goes. When you start including that same header in multiple files though, if you want them to use the see same variables you will need to use the extern keyword. If you want a simple example of a single header suited for a single cpp here goes..any questions on part of it, just ask.

    Code:
    #ifndef VECTOR_H
    #define VECTOR_H
    
    typedef struct _tagVector
    {
      float x;
      float y;
      float z;
    }Vector3;
    
    #endif /* VECTOR_H */

  7. #7
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    uhh that is not a library file, that is a header file.

    In visual C++ in the new project menu, you choose Static Linked Library and write your code, hit the build button and voila you have a library.
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  8. #8
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    wut im trying to do is put my intro for a game in a seperatefile. because its like 500 lines down. i want the intro to play before the game so would i pretend intro.h or wutever is a function and call it as if the function was named intro.h
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  9. #9
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    Call it like all other functions but #include "intro.h" in main.cpp
    what does signature stand for?

  10. #10
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    why not put it in another .cpp file, and add it to your project, and prototype it in main.cpp (or whatever your main file is called)
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  11. #11
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    oh stupid me
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  12. #12
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    You're just starting
    what does signature stand for?

  13. #13
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    so is this right (im not usign my intro ni the header)
    PHP Code:
    #include <iostream>
    #include <string> 
    #include <stdlib.h> 
    #include <windows.h>
    #include <conio.h>
    #include <fstream>
    #include "menuscreen_.cpp"
    using namespace std;

    int menuscreen_.cpp();
    char menuscreenv;
    int goldhealthmagicattackaimdefenceynvaricharactertype;
    string empty, weaponshieldarmorszWordszLineplayeritem1item2item3item4item5item6item7item8item9item10item11item12item13item14item15item16item17item18item19item20item21item22item23item24item25item26item27item28item29item30;
    bool menuselect;

    int main(int argcchar *argv[])
    {
    int menuscreen_.cpp();
    cin.get();
    return 
    0;

    menuscreen_.cpp looks like this
    PHP Code:
    #include <iostream>
    #include <string> 
    #include <stdlib.h> 
    #include <windows.h>
    #include <conio.h>
    #include <fstream>

    int main(int argcchar *argv[])
    {
    cout << menuscreenv << endl;
    cin >> menuselect;
    if (
    menuscreen == 1){
    }
    else if (
    menuscreen == 2){
    ofstream fout;
        
    fout.open("stats.sav");
        
    fout << "Player: " << player << " ";
        
    fout << "CharacterType: " << charactertype << " ";
         
    fout << "Health: " << health << " ";
        
    fout << "Gold: "   << gold   << " ";
        
    fout << "Magic: "  << magic   << " ";
        
    fout << "Attack: " << attack   << " ";
        
    fout << "Aim: "    << aim   << " ";
        
    fout << "Defence: "<< defence   << " ";
        
    fout << "Weapon: "   << weapon << " ";
        
    fout << "Shield: "   << shield << " ";
        
    fout << "Armor: "   << armor << " ";
        
    fout << "Item1: " << item1 << " ";
        
    fout << "Item2: " << item2 << " ";
        
    fout << "Item3: " << item3 << " ";
        
    fout << "Item4: " << item4 << " ";
        
    fout << "Item5: " << item5 << " ";
        
    fout << "Item6: " << item6 << " ";
        
    fout << "Item7: " << item7 << " ";
        
    fout << "Item8: " << item8 << " ";
        
    fout << "Item9: " << item9 << " ";
        
    fout << "Item10: " << item10 << " ";
        
    fout << "Item11: " << item11 << " ";
        
    fout << "Item12: " << item12 << " ";
        
    fout << "Item13: " << item13 << " ";
        
    fout << "Item14: " << item14 << " ";
        
    fout << "Item15: " << item15 << " ";
        
    fout << "Item16: " << item16 << " ";
        
    fout << "Item17: " << item17 << " ";
        
    fout << "Item18: " << item18 << " ";
        
    fout << "Item19: " << item19 << " ";
        
    fout << "Item20: " << item20 << " ";
        
    fout << "Item21: " << item21 << " ";
        
    fout << "Item22: " << item22 << " ";
        
    fout << "Item23: " << item23 << " ";
        
    fout << "Item24: " << item24 << " ";
        
    fout << "Item25: " << item25 << " ";
        
    fout << "Item26: " << item26 << " ";
        
    fout << "Item27: " << item27 << " ";
        
    fout << "Item28: " << item28 << " ";
        
    fout << "Item29: " << item29 << " ";
        
    fout << "Item30: " << item30 << " ";
            
    fout.close();
    }
    else if (
    menuscreen == 3){
    }
    else if (
    menuscreen == 4){
    }
    else if (
    menuscreen == 5){
    }

    do i have to do anything if i want to use the same variables in both files? and have it so both variables hold the same data?
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

  14. #14
    no, you don't have to include .cpp files. I don't even think that would compile. Just add the other .cpp file to your project, and any variables you need from it, put an extern at the top of the main source file for them. And any functions, just prototype them like you regularly would.

  15. #15
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    extern?and i need it so the cpp fies read variables from the main.cpp file.
    Email: [email protected] || AIM: MisterSako || MSN: [email protected]

    -the shroom has spoken

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. MinGW thread-safe runtime libraries
    By Mario F. in forum C++ Programming
    Replies: 3
    Last Post: 08-21-2006, 08:15 AM
  3. Two questions (Linking Libraries and Creating Them)
    By Thantos in forum Linux Programming
    Replies: 3
    Last Post: 03-21-2004, 05:01 PM
  4. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 07:18 AM
  5. creating libraries in c
    By reallyfreakedou in forum C Programming
    Replies: 2
    Last Post: 03-31-2003, 12:12 PM