Thread: Plz help me to include cs50.h and cs50.c into Code::Block

  1. #1
    Registered User
    Join Date
    Nov 2009
    Location
    Florida
    Posts
    15

    Question Plz help me to include cs50.h and cs50.c into Code::Block

    I am trying to follow some lessons from cs50.net. In order to do that I needed to download 2 files since they are using some custom stuff. I am using Code::Blocks under windows XP. I have selected the gcc compiler during the install.

    Here is what I did:

    I have downloaded these two files

    cs50.h
    cs50.c

    from here:

    Index of /pub/releases/cs50

    I figured I have to put the cs50.h file into this folder:

    C:\Program Files\CodeBlocks\MinGW\include

    First I have got a ton of errors whenever I was trying to compile anything including <cs50.h>

    Then I realized downloading them will not work, so I just copied the content of the files form the website into notepad and saved them using the "" marks i.e. "cs50.h" . Now it seems the compiler can read the cs50.h file and I did not get errors anymore when I was using

    #include <cs50.h>

    BUT. I do get an error if I actually use a function from that file. So I guess there is more to do:

    The error I get is:

    Compiling: E:\C Programming\projects\getname.c
    Linking console executable: E:\C Programming\projects\getname.exe
    E:\C Programming\projects\getname.o:getname.c.text+0x37): undefined reference to `GetString()'
    collect2: ld returned 1 exit status
    Process terminated with status 1 (0 minutes, 1 seconds)
    1 errors, 0 warnings


    The code I am trying to compile is this:

    Code:
    #include <cs50.h>
    #include <stdio.h>
    
    int
    main(int argc, char *argv[])
    {
        printf("state your name: ");
        string name = GetString();
        printf("O hai, %s!\n", name);
    }
    I am guessing I will need to put the cs50.c file somewhere or link it somehow but I have no clue how to do that form within code::blocks.

    Thanks for any help!
    Last edited by Huncowboy; 11-03-2009 at 05:46 PM.

  2. #2
    Registered User
    Join Date
    Mar 2010
    Posts
    10
    hey
    it`s not justto put it
    read the top of thefile that says
    * To compile as a static library on your own system:
    * % gcc -c -ggdb -std=c99 cs50.c -o cs50.o
    * % ar rcs libcs50.a cs50.o
    * % rm -f cs50.o
    * % cp cs50.h /usr/local/include
    * % cp libcs50.a /usr/local/lib
    this code will make it .o & .a & also copy them in to the include location
    just define /usr/local/include
    with theinclude location
    &
    /usr/local/lib
    with the lib folder location

    som thing like
    C:\MinGW\lib
    C:\MinGW\include

    okay

  3. #3
    Registered User
    Join Date
    Nov 2009
    Location
    Florida
    Posts
    15
    Thanks polipyc. This was a few months ago for me, but someone else may be able to use this info.

  4. #4
    Registered User
    Join Date
    Mar 2010
    Posts
    10
    iwas searching about it but after i saw the auother header i understad it
    so i tried to help

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by polypic View Post
    iwas searching about it but after i saw the auother header i understad it
    so i tried to help
    Well it is useful info. If you want to use your own include and lib folders (so you don't have to use /usr/include and /lib), gcc uses these environment variables which you can set:

    Code:
    LIBRARY_PATH=$HOME/lib
    C_INCLUDE_PATH=$HOME/include
    CPLUS_INCLUDE_PATH=$HOME/include
    These are empty to start with, so you don't have to do PATH=$PATH;/new kind of thing.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed