NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

Re: [netcdfgroup] netcdf-4.3.3.1 link problem with openmpi on Ubuntu (using mpicc)

Try putting the -lnetcdf /after/ the source file / object file (ditto for LDFLAGS, FWIW).

-tom

On 08/16/2015 05:28 PM, John Helly wrote:
Hi.
I'm trying to compile one of the ucar mpi example files for a class and
am having some elementary difficulty pointing to the netcdf libraries. I
haven't used the openmpi compiler (wrapper) before so I'm flailing a
bit. Any pointers would be most welcome.

hellyj@mae2:/data2/mpi-geospatial/src/c/ucar-examples$ make
mpicc -O1 -w  -I/usr/local/netcdf/include -L/usr/local/netcdf/lib
-lnetcdf  simple_xy_wr.c -o simple_xy_wr
/tmp/cc0uYG2N.o: In function `main':
simple_xy_wr.c:(.text+0x44): undefined reference to `nc_create'
simple_xy_wr.c:(.text+0x4f): undefined reference to `nc_strerror'
simple_xy_wr.c:(.text+0x87): undefined reference to `nc_def_dim'
simple_xy_wr.c:(.text+0x92): undefined reference to `nc_strerror'
simple_xy_wr.c:(.text+0xca): undefined reference to `nc_def_dim'
simple_xy_wr.c:(.text+0xd5): undefined reference to `nc_strerror'
simple_xy_wr.c:(.text+0x127): undefined reference to `nc_def_var'
simple_xy_wr.c:(.text+0x132): undefined reference to `nc_strerror'
simple_xy_wr.c:(.text+0x15b): undefined reference to `nc_enddef'
simple_xy_wr.c:(.text+0x166): undefined reference to `nc_strerror'
simple_xy_wr.c:(.text+0x198): undefined reference to `nc_put_var_int'
simple_xy_wr.c:(.text+0x1a3): undefined reference to `nc_strerror'
simple_xy_wr.c:(.text+0x1cc): undefined reference to `nc_close'
simple_xy_wr.c:(.text+0x1d7): undefined reference to `nc_strerror'
collect2: error: ld returned 1 exit status
make: *** [simple_xy_wr] Error 1

Here's the makefile:

##############################################################################

# FILE:
Makefile.MPI.c

#
DESCRIPTION:

#   Makefile for all MPI C Language example
codes

# AUTHOR: J.
Helly

# LAST REVISED:
08/16/15

###############################################################################

LD_LIBRARY_PATH="/usr/local/netcdf/lib:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH
#

#Uncomment your choice of
compiler

CC         = mpicc
CFLAGS     = -I/usr/local/netcdf/include
LIB_NETCDF = -L/usr/local/netcdf/lib
LDFLAGS    = ${LIB_NETCDF}

#Add your choice of
flags

FLAGS   =   -O1 -w

all:    simple_xy_wr
clean:
         /bin/rm -rf     \
         *.o

simple_xy_wr:  simple_xy_wr.c
         $(CC) $(FLAGS) ${CFLAGS} ${LDFLAGS} -lnetcdf  simple_xy_wr.c -o
simple_xy_wr


Thanks.
J.



_______________________________________________
netcdfgroup mailing list
netcdfgroup@xxxxxxxxxxxxxxxx
For list information or to unsubscribe,  visit: 
http://www.unidata.ucar.edu/mailing_lists/




  • 2015 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: