creating libraries for c++

This is a discussion on creating libraries for c++ within the C++ Programming forums, part of the General Programming Boards category; i got it to wokr i just gotta find out how to get the menuscreen._.cpp file to read variaables from ...

  1. #16
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    i got it to wokr i just gotta find out how to get the menuscreen._.cpp file to read variaables from the other cpp file

    (no, im not just starting, i just cant do functions but i got classes and most the other **** down)
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  2. #17
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    Originally posted by frenchfry164
    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.
    aparently i do, sdo i jsut have to lsit them on the top? (of menuscreen_.cpp)
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  3. #18
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    this is what i did apperantly there is linker problem(at bottom of post)

    this is menuscreen_.cpp
    Code:
    #include <iostream>
    #include <string> 
    #include <stdlib.h> 
    #include <windows.h>
    #include <conio.h>
    #include <fstream>
    
    char * menuscreenv;
    int gold, health, magic, attack, aim, defence, ynvari, charactertype;
    string empty, weapon, shield, armor, szWord, szLine, player, item1, item2, item3, item4, item5, item6, item7, item8, item9, item10, item11, item12, item13, item14, item15, item16, item17, item18, item19, item20, item21, item22, item23, item24, item25, item26, item27, item28, item29, item30;
    bool menuselect;
    int mainb(int argc, char *argv[])
    {
    cout << menuscreenv << endl;
    cin >> menuselect;
    if (menuselect == 1){
    }
    else if (menuselect == 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 (menuselect == 3){
    }
    else if (menuselect == 4){
    }
    else if (menuselect == 5){
    }
    }
    this is excalibur.cpp
    Code:
    #include <iostream>
    #include <string> 
    #include <stdlib.h> 
    #include <windows.h>
    #include <conio.h>
    #include <fstream>
    using namespace std;
    
    int menuscreen_();
    char * menuscreenv;
    int gold, health, magic, attack, aim, defence, ynvari, charactertype;
    string empty, weapon, shield, armor, szWord, szLine, player, item1, item2, item3, item4, item5, item6, item7, item8, item9, item10, item11, item12, item13, item14, item15, item16, item17, item18, item19, item20, item21, item22, item23, item24, item25, item26, item27, item28, item29, item30;
    bool menuselect;
    
    int main(int argc, char *argv[])
    {
    int menuscreen_();
    cin.get();
    return 0;
    }
    linker errors
    Code:
    c:\dev-c++\projects\menuscreen_.o(.bss+0x94):menuscreen_.cp: multiple definition of `menuscreenv'
    c:\dev-c++\projects\excalibur.o(.bss+0x94):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0xb8):menuscreen_.cp: multiple definition of `menuselect'
    c:\dev-c++\projects\excalibur.o(.bss+0xb8):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x18):menuscreen_.cp: multiple definition of `player'
    c:\dev-c++\projects\excalibur.o(.bss+0x18):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0xb4):menuscreen_.cp: multiple definition of `charactertype'
    c:\dev-c++\projects\excalibur.o(.bss+0xb4):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x9c):menuscreen_.cp: multiple definition of `health'
    c:\dev-c++\projects\excalibur.o(.bss+0x9c):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x98):menuscreen_.cp: multiple definition of `gold'
    c:\dev-c++\projects\excalibur.o(.bss+0x98):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0xa0):menuscreen_.cp: multiple definition of `magic'
    c:\dev-c++\projects\excalibur.o(.bss+0xa0):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0xa4):menuscreen_.cp: multiple definition of `attack'
    c:\dev-c++\projects\excalibur.o(.bss+0xa4):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0xa8):menuscreen_.cp: multiple definition of `aim'
    c:\dev-c++\projects\excalibur.o(.bss+0xa8):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0xac):menuscreen_.cp: multiple definition of `defence'
    c:\dev-c++\projects\excalibur.o(.bss+0xac):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x4):menuscreen_.cp: multiple definition of `weapon'
    c:\dev-c++\projects\excalibur.o(.bss+0x4):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x8):menuscreen_.cp: multiple definition of `shield'
    c:\dev-c++\projects\excalibur.o(.bss+0x8):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0xc):menuscreen_.cp: multiple definition of `armor'
    c:\dev-c++\projects\excalibur.o(.bss+0xc):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x1c):menuscreen_.cp: multiple definition of `item1'
    c:\dev-c++\projects\excalibur.o(.bss+0x1c):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x20):menuscreen_.cp: multiple definition of `item2'
    c:\dev-c++\projects\excalibur.o(.bss+0x20):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x24):menuscreen_.cp: multiple definition of `item3'
    c:\dev-c++\projects\excalibur.o(.bss+0x24):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x28):menuscreen_.cp: multiple definition of `item4'
    c:\dev-c++\projects\excalibur.o(.bss+0x28):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x2c):menuscreen_.cp: multiple definition of `item5'
    c:\dev-c++\projects\excalibur.o(.bss+0x2c):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x30):menuscreen_.cp: multiple definition of `item6'
    c:\dev-c++\projects\excalibur.o(.bss+0x30):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x34):menuscreen_.cp: multiple definition of `item7'
    c:\dev-c++\projects\excalibur.o(.bss+0x34):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x38):menuscreen_.cp: multiple definition of `item8'
    c:\dev-c++\projects\excalibur.o(.bss+0x38):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x3c):menuscreen_.cp: multiple definition of `item9'
    c:\dev-c++\projects\excalibur.o(.bss+0x3c):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x40):menuscreen_.cp: multiple definition of `item10'
    c:\dev-c++\projects\excalibur.o(.bss+0x40):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x44):menuscreen_.cp: multiple definition of `item11'
    c:\dev-c++\projects\excalibur.o(.bss+0x44):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x48):menuscreen_.cp: multiple definition of `item12'
    c:\dev-c++\projects\excalibur.o(.bss+0x48):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x4c):menuscreen_.cp: multiple definition of `item13'
    c:\dev-c++\projects\excalibur.o(.bss+0x4c):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x50):menuscreen_.cp: multiple definition of `item14'
    c:\dev-c++\projects\excalibur.o(.bss+0x50):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x54):menuscreen_.cp: multiple definition of `item15'
    c:\dev-c++\projects\excalibur.o(.bss+0x54):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x58):menuscreen_.cp: multiple definition of `item16'
    c:\dev-c++\projects\excalibur.o(.bss+0x58):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x5c):menuscreen_.cp: multiple definition of `item17'
    c:\dev-c++\projects\excalibur.o(.bss+0x5c):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x60):menuscreen_.cp: multiple definition of `item18'
    c:\dev-c++\projects\excalibur.o(.bss+0x60):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x64):menuscreen_.cp: multiple definition of `item19'
    c:\dev-c++\projects\excalibur.o(.bss+0x64):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x68):menuscreen_.cp: multiple definition of `item20'
    c:\dev-c++\projects\excalibur.o(.bss+0x68):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x6c):menuscreen_.cp: multiple definition of `item21'
    c:\dev-c++\projects\excalibur.o(.bss+0x6c):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x70):menuscreen_.cp: multiple definition of `item22'
    c:\dev-c++\projects\excalibur.o(.bss+0x70):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x74):menuscreen_.cp: multiple definition of `item23'
    c:\dev-c++\projects\excalibur.o(.bss+0x74):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x78):menuscreen_.cp: multiple definition of `item24'
    c:\dev-c++\projects\excalibur.o(.bss+0x78):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x7c):menuscreen_.cp: multiple definition of `item25'
    c:\dev-c++\projects\excalibur.o(.bss+0x7c):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x80):menuscreen_.cp: multiple definition of `item26'
    c:\dev-c++\projects\excalibur.o(.bss+0x80):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x84):menuscreen_.cp: multiple definition of `item27'
    c:\dev-c++\projects\excalibur.o(.bss+0x84):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x88):menuscreen_.cp: multiple definition of `item28'
    c:\dev-c++\projects\excalibur.o(.bss+0x88):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x8c):menuscreen_.cp: multiple definition of `item29'
    c:\dev-c++\projects\excalibur.o(.bss+0x8c):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x90):menuscreen_.cp: multiple definition of `item30'
    c:\dev-c++\projects\excalibur.o(.bss+0x90):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x0):menuscreen_.cp: multiple definition of `empty'
    c:\dev-c++\projects\excalibur.o(.bss+0x0):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x10):menuscreen_.cp: multiple definition of `szWord'
    c:\dev-c++\projects\excalibur.o(.bss+0x10):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0x14):menuscreen_.cp: multiple definition of `szLine'
    c:\dev-c++\projects\excalibur.o(.bss+0x14):excalibur.cpp: first defined here
    c:\dev-c++\projects\menuscreen_.o(.bss+0xb0):menuscreen_.cp: multiple definition of `ynvari'
    c:\dev-c++\projects\excalibur.o(.bss+0xb0):excalibur.cpp: first defined here
    apperntly im not supposed to name the variables in menuscreen_.cpp but if i dont it says the variables arent named. how do i use the same variables with sama data in both?
    ive tried everything i could think of! i even searched the net and and looked at other sources.
    (note the varibales are prenamed in excalibur.cpp)
    Last edited by Klinerr1; 07-29-2002 at 08:42 PM.
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  4. #19
    Registered User
    Join Date
    Jun 2002
    Posts
    267
    Why did you do it like that? Why do you declare those variables in excalibur.cpp?

  5. #20
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    your such a idiot j/k

    you use extern to use the variables from other source files. it basically tells the linker, "you can use this variable, but it's not declared here".

    So whatcha do is declare it like normal in say, excaliber.cpp. Example:

    int test;

    then in main.cpp write this

    extern int test;

    then main.cpp can use test. and it is the SAME one as well.

  6. #21
    Registered User
    Join Date
    Jun 2002
    Posts
    267
    Originally posted by frenchfry164
    your such a idiot j/k
    do you have many friends?

  7. #22
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    actualy i dont, thats why i like programming. or were u asking the other guy? thanks for ur help the guy who posted before doob
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  8. #23
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    Originally posted by d00b
    Why did you do it like that? Why do you declare those variables in excalibur.cpp?
    thats not he entire excalibnur.cpp file i didnt wanna ahve like another 600 line uneaded.
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  9. #24
    Registered User
    Join Date
    Jun 2002
    Posts
    267
    Ah..

  10. #25
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    Lol the code there is kinda messy
    what does signature stand for?

  11. #26
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    you need to work on your coding style. I like to indent all my lines one space after each open brace, then stop doing it when I get to a closing brace. It's how most people do it. There are some other stuff, like switches, and declaring functions, that I do different from other people.

  12. #27
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    Yea... and If you paste it on the forum do not forget to use the tags
    what does signature stand for?

  13. #28
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    although sometimes it doesn't paste right, and you gotta go in and fix it. I hate it when that happens

  14. #29
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    Originally posted by frenchfry164
    you need to work on your coding style. I like to indent all my lines one space after each open brace, then stop doing it when I get to a closing brace. It's how most people do it. There are some other stuff, like switches, and declaring functions, that I do different from other people.
    well I have my own way of wrting code. i indent stuff that has to do with a certain thing. like if one set of couts made a ascii art banner it could be indented twice and couts that are there and may never look at again are not indented. and i do code braskets the popular war
    Code:
      {
           /// code
      }
    and i aslo line up the open close braskets incase of this situation
    Code:
       {
           {
                //code
           }
       }
    i woulnt run into like THAT but in a case i am using braksets ina s et of braskets.
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  15. #30
    x4000 Ruski's Avatar
    Join Date
    Jun 2002
    Location
    Outer Space!
    Posts
    542
    Originally posted by frenchfry164
    although sometimes it doesn't paste right, and you gotta go in and fix it. I hate it when that happens
    Everybody does
    what does signature stand for?

Page 2 of 3 FirstFirst 123 LastLast
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, 04:01 PM
  4. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 06:18 AM
  5. creating libraries in c
    By reallyfreakedou in forum C Programming
    Replies: 2
    Last Post: 03-31-2003, 11:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21