Like Tree3Likes
  • 2 Post By Salem
  • 1 Post By Salem

Need a jumpstart compiling using GCC in BASH/Linux

This is a discussion on Need a jumpstart compiling using GCC in BASH/Linux within the C Programming forums, part of the General Programming Boards category; Hi. I have some programming background coding for applications (think things like coding for Excel, MS Word, etc.). But I'm ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    19

    Need a jumpstart compiling using GCC in BASH/Linux

    Hi. I have some programming background coding for applications (think things like coding for Excel, MS Word, etc.). But I'm back in school and for my math thesis I need to compile a C program using gcc, using SUNDIALS (an ODE solver) library, on Linux. I had a little experience with C over 20 years ago; I've never used Linux, BASH, gcc, or SUNDIALS.

    I think I've installed SUNDIALS correctly, but to test that out, I need to compile one of their example programs. To compile, I need to learn Linux/BASH, gcc, and C. I just don't have the time to do all that reading and I would like it if someone could quickly show me how to compile the attached code (and give a few clues on what to look for to compile my own code, too).

    I apologize for posting a question without doing all the requisite reading and promise to make future questions more germane.

    cvAdvDiff_non_p..c

    Thanks, in advance.

  2. #2
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    You don't really need to learn bash just for compiling:
    Just write "gcc filename.c -o output" and you're done. (You may need to pass gcc a few other options)
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    Lets say you download a library and you put it in say /home/user/mylibs/magic
    Within this directory are further directories called include and lib.
    These respectively contain magic.h and libmagic.a

    Your source code begins with
    Code:
    #include <magic.h>
    and goes onto use various functions.

    The way you compile is by saying
    gcc -I/home/user/mylibs/magic/include -L/home/user/mylibs/magic/lib prog.c -lmagic
    anduril462 and MK27 like this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Feb 2012
    Posts
    19
    Quote Originally Posted by manasij7479 View Post
    You don't really need to learn bash just for compiling:
    Just write "gcc filename.c -o output" and you're done. (You may need to pass gcc a few other options)
    I should have mentioned that I already tried that. Here is the output I got (I can't get this to display correctly, so attaching it, too): cvode.out.txt
    Code:
    $ gcc cvAdvDiff_non_p.c -o 
    cvAdvDiff_non_p.outcvAdvDiff_non_p.c:37:71: error: cvode/cvode.h: No such file or directory
    
    cvAdvDiff_non_p.c:38:78: error: nvector/nvector_parallel.h: No such file or directory
    
    cvAdvDiff_non_p.c:39:67: error: sundials/sundials_types.h: No such file or directory
    
    cvAdvDiff_non_p.c:40:62: error: sundials/sundials_math.h: No such file or directory
    
    cvAdvDiff_non_p.c:42:68: error: mpi.h: No such file or directory
    
    cvAdvDiff_non_p.c:61: error: expected specifier-qualifier-list before 'realtype'
    
    cvAdvDiff_non_p.c:69: error: expected ')' before 'u'
    
    cvAdvDiff_non_p.c:74: error: expected ')' before 't'
    
    cvAdvDiff_non_p.c:80: error: expected ')' before 't'
    
    cvAdvDiff_non_p.c: In function 'main':
    
    cvAdvDiff_non_p.c:90: error: 'realtype' undeclared (first use in this function)
    
    cvAdvDiff_non_p.c:90: error: (Each undeclared identifier is reported only once
    
    cvAdvDiff_non_p.c:90: error: for each function it appears in.)
    
    cvAdvDiff_non_p.c:90: error: expected ';' before 'dx'
    
    cvAdvDiff_non_p.c:91: error: 'N_Vector' undeclared (first use in this function)
    
    cvAdvDiff_non_p.c:91: error: expected ';' before 'u'
    
    cvAdvDiff_non_p.c:97: error: 'MPI_Comm' undeclared (first use in this function)
    
    cvAdvDiff_non_p.c:97: error: expected ';' before 'comm'
    
    cvAdvDiff_non_p.c:99: error: 'u' undeclared (first use in this function)
    
    cvAdvDiff_non_p.c:105: error: 'comm' undeclared (first use in this function)
    
    cvAdvDiff_non_p.c:105: error: 'MPI_COMM_WORLD' undeclared (first use in this function)
    
    cvAdvDiff_non_p.c:118: error: 'struct <anonymous>' has no member named 'comm'
    
    cvAdvDiff_non_p.c:119: error: 'struct <anonymous>' has no member named 'npes'
    
    cvAdvDiff_non_p.c:120: error: 'struct <anonymous>' has no member named 'my_pe'
    
    cvAdvDiff_non_p.c:125: error: 'reltol' undeclared (first use in this function)
    
    cvAdvDiff_non_p.c:126: error: 'abstol' undeclared (first use in this function)
    
    cvAdvDiff_non_p.c:128: error: 'dx' undeclared (first use in this function)
    
    cvAdvDiff_non_p.c:128: error: 'struct <anonymous>' has no member named 'dx'
    
    cvAdvDiff_non_p.c:129: error: 'struct <anonymous>' has no member named 'hdcoef'
    
    cvAdvDiff_non_p.c:130: error: 'struct <anonymous>' has no member named 'hacoef'
    
    cvAdvDiff_non_p.c:136: error: 'CV_ADAMS' undeclared (first use in this function)
    
    cvAdvDiff_non_p.c:136: error: 'CV_FUNCTIONAL' undeclared (first use in this function)
    
    cvAdvDiff_non_p.c:145: error: 'f' undeclared (first use in this function)
    
    cvAdvDiff_non_p.c:155: error: 'umax' undeclared (first use in this function)
    
    cvAdvDiff_non_p.c:158: error: 't' undeclared (first use in this function)
    
    cvAdvDiff_non_p.c:164: error: 'tout' undeclared (first use in this function)
    
    cvAdvDiff_non_p.c:165: error: 'CV_NORMAL' undeclared (first use in this function)
    
    cvAdvDiff_non_p.c: At top level:
    
    cvAdvDiff_non_p.c:189: error: expected ')' before 'u'
    
    cvAdvDiff_non_p.c:221: error: expected ')' before 't'
    
    cvAdvDiff_non_p.c:262: error: expected ')' before 't'

  5. #5
    Registered User
    Join Date
    Feb 2012
    Posts
    19
    Quote Originally Posted by Salem View Post
    Lets say you download a library and you put it in say /home/user/mylibs/magic
    Within this directory are further directories called include and lib.
    These respectively contain magic.h and libmagic.a

    Your source code begins with
    Code:
    #include <magic.h>
    and goes onto use various functions.

    The way you compile is by saying
    gcc -I/home/user/mylibs/magic/include -L/home/user/mylibs/magic/lib prog.c -lmagic
    OK. I have to go figure out where the correct include and lib directories are. I'll report back. Thanks.

  6. #6
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Quote Originally Posted by CCompiler View Post
    OK. I have to go figure out where the correct include and lib directories are. I'll report back. Thanks.
    Right inside your downloaded folder.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  7. #7
    Registered User
    Join Date
    Feb 2012
    Posts
    19
    Quote Originally Posted by manasij7479 View Post
    Right inside your downloaded folder.
    This was not a routine install. I have an include directory, but it has no files in it . There is no directory called lib​, so I had to look for the library directory, too.

    Anyway, I came up with this:
    Code:
    gcc -I/home/<username>/sundials/cvode-2.6.0/include -L/home/<username>/sundials/cvode-2.6.0/instdir/lib cvAdvDiff_non_p.c
    I saved that line to a file called cvAdvDiff_non_p.make. I typed
    Code:
    $ chmod +x cvAdvDiff_non_p.make
    to make it executable. Then typed
    Code:
    ./cvAdvDiff_non_p.make >cvAdvDiff_non_p.out
    .

    There is nothing in the file cvAdvDiff_non_p.out, but the screen showed a whole bunch of errors, which I can't upload. It starts like this:

    Code:
    In file included from /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:50,                 from /home/schwarz/sundials/cvode-2.6.0/include/cvode/cvode.h:37,
                     from cvAdvDiff_non_p.c:37:
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_types.h:50:38: error: sundials/sundials_config.h: No such file or directory
    In file included from /home/schwarz/sundials/cvode-2.6.0/include/cvode/cvode.h:37,
                     from cvAdvDiff_non_p.c:37:
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:73: error: expected specifier-qualifier-list before 'realtype'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:316: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'N_Vector'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:317: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'N_Vector'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:318: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:319: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:320: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'realtype'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:321: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:322: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:323: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:324: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:325: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:326: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:327: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:328: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:329: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:330: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'realtype'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:331: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'realtype'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:332: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'realtype'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:333: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'realtype'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:334: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'realtype'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:335: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'realtype'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:336: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'realtype'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:337: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:338: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'int'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:339: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'int'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:340: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'realtype'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:365: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'N_Vector'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:366: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'N_Vector'
    /home/schwarz/sundials/cvode-2.6.0/include/sundials/sundials_nvector.h:367: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
    In file included from cvAdvDiff_non_p.c:37:
    /home/schwarz/sundials/cvode-2.6.0/include/cvode/cvode.h:155: error: expected ')' before 't'
    /home/schwarz/sundials/cvode-2.6.0/include/cvode/cvode.h:177: error: expected ')' before 't'
    /home/schwarz/sundials/cvode-2.6.0/include/cvode/cvode.h:253: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
    /home/schwarz/sundials/cvode-2.6.0/include/cvode/cvode.h:365: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'int'
    /home/schwarz/sundials/cvode-2.6.0/include/cvode/cvode.h:366: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'int'
    /home/schwarz/sundials/cvode-2.6.0/include/cvode/cvode.h:367: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'int'
    /home/schwarz/sundials/cvode-2.6.0/include/cvode/cvode.h:368: error: expected '=', ',', ';
    Anybody know what this says is wrong? Or how I can fix it? (Sorry for being so obtuse - and thanks for your help).

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    In /home/<username>/sundials/cvode-2.6.0 are there any of the following files (or files with similar names)?

    configure
    make
    readme

    If your library is just source code, then the first thing you need to do is make the library and then perhaps install it.
    Say perhaps by doing
    ./configure
    make
    make install
    stahta01 likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Registered User
    Join Date
    Feb 2012
    Posts
    19
    Quote Originally Posted by Salem View Post
    In /home/<username>/sundials/cvode-2.6.0 are there any of the following files (or files with similar names)?

    configure
    make
    readme

    If your library is just source code, then the first thing you need to do is make the library and then perhaps install it.
    Say perhaps by doing
    ./configure
    make
    make install
    Here are the steps I used to do the install:
    $ tar xzf cvode-2.6.0.tar.gz
    $ cd cvode-2.6.0
    $ mkdir builddir
    $ ./configure --prefix=/home/<username>/sundials/srcdir/instdir --enable-examples$
    $ make
    $ make install
    Last edited by CCompiler; 02-04-2012 at 12:19 PM.

  10. #10
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    OK, so do you know where make install copied the files?

    /usr/include and /usr/lib would seem like good places to look.

    The documentation should tell you where.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  11. #11
    Registered User
    Join Date
    Feb 2012
    Posts
    19
    Quote Originally Posted by Salem View Post
    OK, so do you know where make install copied the files?

    /usr/include and /usr/lib would seem like good places to look.

    The documentation should tell you where.
    I had to do the install in my own account, so all the files are in '/home/<myusername>'.

    There is an include directory, '/home/<username>/sundials/cvode-2.6.0/include', but it has only subdirectories in it (called cvode, nvector, sundials).

    There is no lib directory, but there is one called src, '/home/<username>/sundials/cvode-2.6.0/src'

    The full directory list under cvode-2.6.0 are:
    bin
    builddir
    config
    doc
    examples
    include
    instdir
    src

    Are include and src the directories I'm looking for?

  12. #12
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    What about in instdir?

    You could try
    find . -name "*.a"
    from the project root, to see if any .a files have been created.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  13. #13
    Registered User
    Join Date
    Feb 2012
    Posts
    19
    Quote Originally Posted by Salem View Post
    What about in instdir?

    You could try
    find . -name "*.a"
    from the project root, to see if any .a files have been created.
    Salem, thanks for helping out.

    I'm using '/home/<username>/sundials/cvode-2.6.0' as the project root. Here's what I get

    $ find . -name "*.a"
    ./builddir/src/nvec_par/.libs/libsundials_nvecparallel.a
    ./builddir/src/nvec_ser/.libs/libsundials_nvecserial.a
    ./builddir/src/cvode/.libs/libsundials_cvode.a
    ./instdir/lib/libsundials_nvecserial.a
    ./instdir/lib/libsundials_cvode.a
    ./instdir/lib/libsundials_nvecparallel.a
    I recall creating the name instdir during one attempt at installation. I guess './instdir/lib' is the lib directory.

    I created cvAdvDiff_non_p.make using those directories, like this:
    projDir='/home/<username>/sundials/cvode-2.6.0'
    gcc -I$projDir$/instdir/include -L$projDir$/instdir/lib/ cvAdvDiff_non_p.c

    Then I tried compiling and got the same errors.
    $ ./cvAdvDiff_non_p.make
    cvAdvDiff_non_p.c:37:71: error: cvode/cvode.h: No such file or directory
    cvAdvDiff_non_p.c:38:78: error: nvector/nvector_parallel.h: No such file or directory
    cvAdvDiff_non_p.c:39:67: error: sundials/sundials_types.h: No such file or directory
    cvAdvDiff_non_p.c:40:62: error: sundials/sundials_math.h: No such file or directory
    cvAdvDiff_non_p.c:42:68: error: mpi.h: No such file or directory
    cvAdvDiff_non_p.c:61: error: expected specifier-qualifier-list before 'realtype'
    cvAdvDiff_non_p.c:69: error: expected ')' before 'u'
    cvAdvDiff_non_p.c:74: error: expected ')' before 't'
    cvAdvDiff_non_p.c:80: error: expected ')' before 't'
    cvAdvDiff_non_p.c: In function 'main':
    cvAdvDiff_non_p.c:90: error: 'realtype' undeclared (first use in this function)
    cvAdvDiff_non_p.c:90: error: (Each undeclared identifier is reported only once
    cvAdvDiff_non_p.c:90: error: for each function it appears in.)
    cvAdvDiff_non_p.c:90: error: expected ';' before 'dx'
    cvAdvDiff_non_p.c:91: error: 'N_Vector' undeclared (first use in this function)
    cvAdvDiff_non_p.c:91: error: expected ';' before 'u'
    cvAdvDiff_non_p.c:97: error: 'MPI_Comm' undeclared (first use in this function)
    cvAdvDiff_non_p.c:97: error: expected ';' before 'comm'
    cvAdvDiff_non_p.c:99: error: 'u' undeclared (first use in this function)
    cvAdvDiff_non_p.c:105: error: 'comm' undeclared (first use in this function)
    cvAdvDiff_non_p.c:105: error: 'MPI_COMM_WORLD' undeclared (first use in this function)
    cvAdvDiff_non_p.c:118: error: 'struct <anonymous>' has no member named 'comm'
    cvAdvDiff_non_p.c:119: error: 'struct <anonymous>' has no member named 'npes'
    cvAdvDiff_non_p.c:120: error: 'struct <anonymous>' has no member named 'my_pe'
    cvAdvDiff_non_p.c:125: error: 'reltol' undeclared (first use in this function)
    cvAdvDiff_non_p.c:126: error: 'abstol' undeclared (first use in this function)
    cvAdvDiff_non_p.c:128: error: 'dx' undeclared (first use in this function)
    cvAdvDiff_non_p.c:128: error: 'struct <anonymous>' has no member named 'dx'
    cvAdvDiff_non_p.c:129: error: 'struct <anonymous>' has no member named 'hdcoef'
    cvAdvDiff_non_p.c:130: error: 'struct <anonymous>' has no member named 'hacoef'
    cvAdvDiff_non_p.c:136: error: 'CV_ADAMS' undeclared (first use in this function)
    cvAdvDiff_non_p.c:136: error: 'CV_FUNCTIONAL' undeclared (first use in this function)
    cvAdvDiff_non_p.c:145: error: 'f' undeclared (first use in this function)
    cvAdvDiff_non_p.c:155: error: 'umax' undeclared (first use in this function)
    cvAdvDiff_non_p.c:158: error: 't' undeclared (first use in this function)
    cvAdvDiff_non_p.c:164: error: 'tout' undeclared (first use in this function)
    cvAdvDiff_non_p.c:165: error: 'CV_NORMAL' undeclared (first use in this function)
    cvAdvDiff_non_p.c: At top level:
    cvAdvDiff_non_p.c:189: error: expected ')' before 'u'
    cvAdvDiff_non_p.c:221: error: expected ')' before 't'
    cvAdvDiff_non_p.c:262: error: expected ')' before 't'
    Is there something wrong with cvAdvDiff_non_p.make, or do I still have the directories wrong (or both)?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. linux bash command prompt access with c++
    By elninio in forum C++ Programming
    Replies: 2
    Last Post: 06-30-2008, 09:33 AM
  2. Compiling in Linux
    By IdioticCreation in forum Linux Programming
    Replies: 2
    Last Post: 05-31-2007, 05:09 PM
  3. Linux: Use C to call a bash script
    By harada in forum Linux Programming
    Replies: 9
    Last Post: 10-27-2006, 01:59 PM
  4. Compiling in Linux - GCC
    By gqchynaboy in forum C Programming
    Replies: 15
    Last Post: 03-02-2005, 11:15 AM

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