Thread: Library's library can't be found (Stupid newbie needs help compiling)

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

    Library's library can't be found (Stupid newbie needs help compiling)

    This is a followup to this. I made a little bit of progress, but I'm still flummoxed. I have a more specific question this time.

    I am trying to compile a sample program which came with a software package I installed called SUNDIALS. The code is correct (it is supplied as an example with the code).

    However, I am getting an error message which indicates that a library cannot find one of the libraries referenced in its #include statement. But the file that it cannot find is in the same directory.

    So I am compiling the file /home/<myusername>/sundials/srcdir/examples/cvode/parallelcvAdvDiff_non_p.c, which starts like this:
    Code:
    #include <stdio.h>#include <stdlib.h>
    #include <math.h>
    
    
    #include <cvode/cvode.h>              /* prototypes for CVODE fcts. */
    #include <nvector/nvector_parallel.h> /* definition of N_Vector and macros */
    #include <sundials/sundials_types.h>  /* definition of realtype */
    #include <sundials/sundials_math.h>   /* definition of EXP */
    
    
    #include <mpi.h>                      /* MPI constants and types */
    ...
    See the #include <sundials/sundials_types.h>? That file's full location is /home/<myusername>/sundials/srcdir/include/sundials/sundials_types. The compiler finds it. It starts
    Code:
    #ifndef _SUNDIALSTYPES_H#define _SUNDIALSTYPES_H
    
    
    #ifdef __cplusplus  /* wrapper to enable C++ usage */
    extern "C" {
    #endif
    
    
    #ifndef _SUNDIALS_CONFIG_H
    #define _SUNDIALS_CONFIG_H
    #include <sundials/sundials_config.h>
    #endif
    
    
    #include <float.h>
    Now, see the line #include <sundials/sundials_config.h>? That file is in the same directory as sundials_types., but the compiler can't find it.

    The compile command I'm using is
    Code:
    $ gcc -I/home/schwarz/sundials/cvode-2.6.0/include -L/home/schwarz/sundials/cvode-2.6.0/instdir/lib/ cvAdvDiff_non_p.c
    The start of the error message I'm getting is
    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:
    Anybody know why the compiler doesn't find the library's library? How do I fix that?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You've specified where to look, but you didn't specify what to look for.

    Look at the end of the command line in the previous post.
    You also need the name(s) of the libraries you want to link with.
    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.

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    19
    Quote Originally Posted by Salem View Post
    You've specified where to look, but you didn't specify what to look for.

    Look at the end of the command line in the previous post.
    You also need the name(s) of the libraries you want to link with.
    Hi Salem. I'm not following you. What is the option which tells what to look for (I paged through the 12000 pages of man gcc), and what are the choices. Thanks.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    gcc -I/home/user/mylibs/magic/include -L/home/user/mylibs/magic/lib prog.c -lmagic
    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.

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    What Salem is telling you is this. Here's your command line:
    Code:
    $ gcc -I/home/schwarz/sundials/cvode-2.6.0/include -L/home/schwarz/sundials/cvode-2.6.0/instdir/lib/ cvAdvDiff_non_p.c
    -I means "this directory has additional header files for including"
    -L means "this directory has additional library files for linking"

    So that's good. However, as you've discovered it's not enough information. You need to tell the linker exactly what libraries you want to link in. You do this with the -l (lower-case L) flag and the library names. And that's where it gets tricky.

    A library is a .a file, which is named liblibrary_name.a. You only need the part in italics. So, if you need to link a library with a library file of libmy_library.a, then your command line would look like:

    Code:
    $ gcc -I/home/schwarz/sundials/cvode-2.6.0/include -L/home/schwarz/sundials/cvode-2.6.0/instdir/lib/ cvAdvDiff_non_p.c -lmy_library
    EDIT: But it looks like I went off of Salem's post rather than yours. You're saying it's not finding your include files. Ummm...let me see if I can build this.
    Last edited by rags_to_riches; 02-08-2012 at 03:17 PM.

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Did you run ./configure? I think you're trying to compile a file which has not been pre-processed. You shouldn't be using files in the src/ directory, but in the install-root/examples directory.

    Code:
    neon:sundials-2.4.0 rags$ ./configure --prefix=`pwd`/ctest
    ---------------------------------
    Running SUNDIALS Configure Script
    ---------------------------------
    
    Initialization
    --------------
    
    checking build system type... i386-apple-darwin10.8.0
    checking host system type... i386-apple-darwin10.8.0
    checking whether make sets $(MAKE)... yes
    checking for a BSD-compatible install... /opt/local/bin/ginstall -c
    <snip>
    
      Type 'make' and then 'make install' to build and install SUNDIALS 2.4.0.
    
    ----------------------------------
    Finished SUNDIALS Configure Script
    ----------------------------------
    
    neon:sundials-2.4.0 rags$ make
    ----------------------
    Make src/sundials...
    ----------------------
    <snip>
    
    neon:sundials-2.4.0 rags$ make install
    /bin/sh ./config/mkinstalldirs /Users/rags/Downloads/sundials-2.4.0/ctest/bin
    mkdir -p -- /Users/rags/Downloads/sundials-2.4.0/ctest/bin
    /opt/local/bin/ginstall -c  ./bin/sundials-config    /Users/rags/Downloads/sundials-2.4.0/ctest/bin/
    ----------------------
    Install src/sundials...
    ----------------------
    <snip>
    
    neon:sundials-2.4.0 rags$ cd ctest/
    neon:ctest rags$ ls
    bin/		include/	lib/
    neon:ctest rags$ cd lib/
    neon:lib rags$ ls
    libsundials_cvode.a		libsundials_idas.la*
    libsundials_cvode.la*		libsundials_kinsol.a
    libsundials_cvodes.a		libsundials_kinsol.la*
    libsundials_cvodes.la*		libsundials_nvecparallel.a
    libsundials_ida.a		libsundials_nvecparallel.la*
    libsundials_ida.la*		libsundials_nvecserial.a
    libsundials_idas.a		libsundials_nvecserial.la*
    
    
    neon:sundials-2.4.0 rags$ gcc -Ictest/include -Lctest/lib examples/cvode/parallel/cvAdvDiff_non_p.c -o mytest -lsundials_cvode -lmpi -lsundials_nvecparallel 
    neon:sundials-2.4.0 rags$ ls
    CMakeLists.txt	README		config.h	configure.ac	libtool*
    INSTALL_NOTES	a.out*		config.hin	ctest/		mytest*
    LICENSE		acinclude.m4	config.log	doc/		src/
    Makefile	bin/		config.status*	examples/	sundialsTB/
    Makefile.in	config/		configure*	include/
    neon:sundials-2.4.0 rags$ ./mytest 
    
     1-D advection-diffusion equation, mesh size = 10 
    
     Number of PEs =   1 
    
    At t = 0.00  max.norm(u) =  1.569909e+01  nst =   0 
    At t = 0.50  max.norm(u) =  3.052881e+00  nst = 113 
    At t = 1.00  max.norm(u) =  8.753188e-01  nst = 191 
    At t = 1.50  max.norm(u) =  2.494926e-01  nst = 265 
    At t = 2.00  max.norm(u) =  7.109437e-02  nst = 332 
    At t = 2.50  max.norm(u) =  2.026175e-02  nst = 405 
    At t = 3.00  max.norm(u) =  5.776619e-03  nst = 473 
    At t = 3.50  max.norm(u) =  1.653843e-03  nst = 540 
    At t = 4.00  max.norm(u) =  4.740297e-04  nst = 626 
    At t = 4.50  max.norm(u) =  1.361421e-04  nst = 694 
    At t = 5.00  max.norm(u) =  3.864269e-05  nst = 766 
    
    Final Statistics: 
    
    nst = 766     nfe  = 1437    nni = 1433    ncfn = 139     netf = 5

  7. #7
    Registered User
    Join Date
    Feb 2012
    Posts
    19
    I did run ./configure. This is how I installed the program:
    Code:
    $ cd cvode-2.6.0
    $ mkdir builddir
    $ ./configure --prefix=/home/schwarz/sundials/srcdir/instdir --enable-examples --with-precision=extended --enable-shared
    $ make
    $ make install

  8. #8
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Well I downloaded the sundials package, and documented pretty much everything from configure to compiling an example above. Don't know what else to tell you.

  9. #9
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    OK, I downloaded the package you did, configured and installed it as you did, then did this:
    Compiled and linked, creating an executable named cvAdvDiff_non_p from the file cvAdvDiff_non_p.c:
    Code:
    neon:cvode-2.6.0 rags$ gcc -I$HOME/sundials/srcdir/instdir/include -L$HOME/sundials/srcdir/instdir/lib $HOME/sundials/srcdir/instdir/examples/cvode/parallel/cvAdvDiff_non_p.c -o cvAdvDiff_non-p -lsundials_cvode -lmpi -lsundials_nvecparallel
    Then ran it:
    Code:
    neon:cvode-2.6.0 rags$ ./cvAdvDiff_non-p  1-D advection-diffusion equation, mesh size = 10 
    
     Number of PEs =   1 
    
    At t = 0.00  max.norm(u) =  1.569909e+01  nst =   0 
    At t = 0.50  max.norm(u) =  3.052881e+00  nst = 113 
    At t = 1.00  max.norm(u) =  8.753188e-01  nst = 191 
    At t = 1.50  max.norm(u) =  2.494926e-01  nst = 265 
    At t = 2.00  max.norm(u) =  7.109437e-02  nst = 332 
    At t = 2.50  max.norm(u) =  2.026175e-02  nst = 405 
    At t = 3.00  max.norm(u) =  5.776619e-03  nst = 473 
    At t = 3.50  max.norm(u) =  1.653843e-03  nst = 540 
    At t = 4.00  max.norm(u) =  4.740297e-04  nst = 626 
    At t = 4.50  max.norm(u) =  1.361421e-04  nst = 694 
    At t = 5.00  max.norm(u) =  3.864269e-05  nst = 766 
    
    Final Statistics: 
    
    nst = 766     nfe  = 1437    nni = 1433    ncfn = 139     netf = 5
    OK? Help you?

  10. #10
    Registered User
    Join Date
    Feb 2012
    Posts
    19
    Hey all. I lucked out when a friend of a friend who has good Linux experience agreed to help me. It's a good thing, too, because I was waaay off. You all couldn't help me because I didn't understand enough and wasn't giving you nearly enough information.

    The end result is that we got it working. For those curious about the answer, we had to update an environment variable (which I conveniently forgot to write down!) and ended up with the following "make" file which hardly looked like it came from the one earlier in this thread:
    Code:
    projDir='/home/schwarz/sundials/srcdir/'
    mpicc -I${projDir}instdir/include -I/usr/local/mpi/include -L${projDir}instdir/lib -L/usr/local/mpi/lib cvAdvDiff_non_p.c -lpthread -lsundials_cvode -lsundials_nvecparallel -o cvAdvDiff_non_p.out -Wl,-R,/home/schwarz/sundials/srcdir/instdir/lib
    I don't understand all of this yet, but fortunately my friend's friend is a coffee nut and he's in my area often. He agreed to teach me a little in return for some Starbucks on Friday.

    Thanks all for your help. Feel free to post any hints you can glean from the final answer which might help me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. compiling shared library
    By django in forum C Programming
    Replies: 18
    Last Post: 08-24-2011, 03:48 PM
  2. compiling the fftw3 library through Makefiles
    By mjs91 in forum C++ Programming
    Replies: 1
    Last Post: 06-09-2011, 11:45 AM
  3. Compiling A Shared library
    By Ectara in forum C Programming
    Replies: 6
    Last Post: 01-18-2010, 04:39 PM
  4. Compiling a library
    By MTK in forum C++ Programming
    Replies: 1
    Last Post: 12-03-2009, 05:04 PM
  5. Compiling Library Into Program.
    By Shogun in forum Linux Programming
    Replies: 10
    Last Post: 11-30-2004, 01:29 PM