Menu

How do I create a library with Dev-C++?

2007-01-25
2012-09-26
  • Nobody/Anonymous

    I am new to Dev-C++, but i am no noob to the C++ language. I was taught C++ on Metroworks Codewarrior and am no longer able to use that compiler, through a little bit of toying around I learned that Dev-C++ is a world different from Metroworks (if not, then close).On to my question... I have some libraries I really like that i would like to convert to the Dev but at the same time create new libraries from scratch to use in future programs, could someone help me convert on of my libraries (i will post it also) and give me a basic outline of a good Dev-C++ library that i can call my own and customize w/out end?

    BTW: I am running Dev-C++ 4.9.8.0 and Windows 98 SE

    a73h_L337lib.h:

    ifndef a73h_L337lib

    define a73h_L337lib

    void randomnum(int high,int low, int &num1, int &num2);
    void ending();
    void randomHP(int high,int low, int &HP);
    void randomMP(int high,int low, int &MP);

    endif

    a73h_L337lib.cpp:

    include "a73h_L337lib.h"

    include <time>

    include <iostream>

    include <stdlib>

    void randomnum(int high, int low, int &num1, int &num2){
    time_t seconds;
    time(&seconds);
    srand((unsigned int) seconds);
    num1=rand()%(high-low+1)+low;
    num2=rand()%(high-low+1)+low;
    }

    void ending(){

    cin.ignore(256,'\n');
    cout&lt;&lt;&quot;\n\n\n\n\n\n\nPress Enter&quot;;
    cin.get();
    

    }

    void randomHP (int high,int low,int &HP){
    time_t seconds;
    time(&seconds);
    srand((unsigned int) seconds);
    HP=rand()%(high-low+1)+low;
    }

    void randomMP (int high,int low,int &MP){
    time_t seconds;
    time(&seconds);
    srand((unsigned int) seconds);
    MP=rand()%(high-low+1)+low;
    }

     
    • Nobody/Anonymous

      srand() in all the functions looks bad. Just leave the seeding to the user of the function.

      Have you thought what would happen if you called your random number functions several times a second?

       
    • Soma

      Soma - 2007-01-25

      "and give me a basic outline of a good Dev-C++ library that i can call my own and customize w/out end?"

      Sounds to me like you were taught bad C++. Code is code, libraries are a tool issue. A quality library will be a quality library regardless of the tools used to craft it. No one can give you a magic description for a "basic outline" that will ever be valid.

      I can't believe that that code compiles with Code Warrior. Shift the headers 'time' and 'stdlib' to the actual 'ctime' and 'cstdlib'.

      Soma

       
    • Anonymous

      Anonymous - 2007-01-25

      I am not sure about all the irrelevant blurb, the only relevant part seems to be the title of post, and to that end:

      File->New->Project->Static Library, select language, and project name (used as library name, prefix it "lib" to conform with the GNU convention of libXXX.a). Add your sourced to teh project (See project menu or Project pane context menu), and build. The result will be a librray archive (.a) file that you can use just like any other.

      C and C++ are standardised languages, and even before standardisation variations between compilers are not that great (original pre-1989 K&R C excepted). So I am not sure how you can say that "Dev-C++ is a world different from Metroworks" unless you are only referring to teh IDEs.

       
    • Anonymous

      Anonymous - 2007-01-25

      I am not sure about all the irrelevant blurb, the only relevant part seems to be the title of post, and to that end:

      File->New->Project->Static Library, select language, and project name (used as library name, prefix it "lib" to conform with the GNU convention of libXXX.a). Add your sourced to the project (See project menu or Project pane context menu), and build. The result will be a library archive (.a) file that you can use just like any other.

      C and C++ are standardised languages, and even before standardisation variations between compilers are not that great (original pre-1989 K&R C excepted). So I am not sure how you can say that "Dev-C++ is a world different from Metroworks" unless you are only referring to the IDEs.

       
    • Nobody/Anonymous

      thanx, that helped.
      wat i was taught was basic and learned in high school(which i am still in, high school), not all of it is the original code i used for the class (previous attempt to compile). and again i thank ye for lending me your intellect.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.