Undefined reference error during installation
gaodaohong opened this issue · 15 comments
Hi! I've been following the INSTALL.md and I'm having trouble trying to run make
. When powerplot.c
and xyline.c
are being compiled, it says undefined reference to 'cpgend' (and others). It seems to me that some header files of PGPLOT are not included. Here's the log where things go wrong.
gcc -I/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I -I/usr/local/include -I /usr/bin/astro_apps/presto-4.0/include -g -Wall -W -fPIC -O3 -ffast-math -DUSEMMAP -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DUSE_FFTW_MALLOC -Wno-unused-result -Wno-unused-but-set-variable -Wno-unused-but-set-parameter -fdiagnostics-color=auto -fopenmp -Wl,-rpath,/lib -o /bin/rednoise rednoise.o rednoise_cmd.o -lcfitsio -lpthread -L/lib -lpresto -L/usr/local/lib -lfftw3f -lm
gcc -I/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I -I/usr/local/include -I /usr/bin/astro_apps/presto-4.0/include -g -Wall -W -fPIC -O3 -ffast-math -DUSEMMAP -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DUSE_FFTW_MALLOC -Wno-unused-result -Wno-unused-but-set-variable -Wno-unused-but-set-parameter -fdiagnostics-color=auto -fopenmp -Wl,-rpath,/lib -o /bin/un_sc_td un_sc_td.c
gcc -I/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I -I/usr/local/include -I /usr/bin/astro_apps/presto-4.0/include -g -Wall -W -fPIC -O3 -ffast-math -DUSEMMAP -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DUSE_FFTW_MALLOC -Wno-unused-result -Wno-unused-but-set-variable -Wno-unused-but-set-parameter -fdiagnostics-color=auto -fopenmp -Wl,-rpath,/lib -o /bin/bincand bincand.o bincand_cmd.o -lcfitsio -lpthread -L/lib -lpresto -L/usr/local/lib -lfftw3f -lm
gfortran -g -fPIC -Wl,-rpath,/lib -fopenmp -o /bin/psrorbit powerplot.o xyline.o psrorbit.o -lcfitsio -lpthread -L/lib -lpresto -L/usr/local/lib -lfftw3f -L -lcpgplot -lpgplot -lX11 -lpng16 -lz -lm
/usr/bin/ld: psrorbit.o: in function `main':
/usr/bin/astro_apps/presto-4.0/src/psrorbit.c:205: undefined reference to `cpgend'
/usr/bin/ld: powerplot.o: in function `powerplot':
/usr/bin/astro_apps/presto-4.0/src/powerplot.c:27: undefined reference to `cpgenv'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/powerplot.c:30: undefined reference to `cpgscf'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/powerplot.c:33: undefined reference to `cpglab'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/powerplot.c:40: undefined reference to `cpgline'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/powerplot.c:37: undefined reference to `cpgiden'
/usr/bin/ld: xyline.o: in function `cpgstart_ps':
/usr/bin/astro_apps/presto-4.0/src/xyline.c:11: undefined reference to `cpgopen'
/usr/bin/ld: xyline.o: in function `cpgstart_x':
/usr/bin/astro_apps/presto-4.0/src/xyline.c:22: undefined reference to `cpgopen'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:27: undefined reference to `cpgpap'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:25: undefined reference to `cpgpap'
/usr/bin/ld: xyline.o: in function `xyline':
/usr/bin/astro_apps/presto-4.0/src/xyline.c:101: undefined reference to `cpgenv'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:104: undefined reference to `cpgscf'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:107: undefined reference to `cpglab'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:114: undefined reference to `cpgline'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:111: undefined reference to `cpgiden'
/usr/bin/ld: xyline.o: in function `xybinned':
/usr/bin/astro_apps/presto-4.0/src/xyline.c:161: undefined reference to `cpgenv'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:164: undefined reference to `cpgscf'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:167: undefined reference to `cpglab'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:174: undefined reference to `cpgbin'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:171: undefined reference to `cpgiden'
/usr/bin/ld: xyline.o: in function `xyline2lab':
/usr/bin/astro_apps/presto-4.0/src/xyline.c:196: undefined reference to `cpgscf'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:199: undefined reference to `cpgpage'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:200: undefined reference to `cpgvstd'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:201: undefined reference to `cpgswin'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:202: undefined reference to `cpgbox'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:203: undefined reference to `cpgmtxt'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:204: undefined reference to `cpgmtxt'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:207: undefined reference to `cpgline'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:210: undefined reference to `cpgvstd'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:211: undefined reference to `cpgswin'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:212: undefined reference to `cpgbox'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:213: undefined reference to `cpgmtxt'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:216: undefined reference to `cpgline'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:220: undefined reference to `cpgiden'
/usr/bin/ld: xyline.o: in function `plot_spectrum':
/usr/bin/astro_apps/presto-4.0/src/xyline.c:256: undefined reference to `cpgpage'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:257: undefined reference to `cpgvstd'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:260: undefined reference to `cpgswin'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:261: undefined reference to `cpgbox'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:262: undefined reference to `cpgmtxt'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:265: undefined reference to `cpgswin'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:266: undefined reference to `cpgbox'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:267: undefined reference to `cpgmtxt'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:268: undefined reference to `cpgmtxt'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:271: undefined reference to `cpgline'
/usr/bin/ld: xyline.o: in function `plot_profile':
/usr/bin/astro_apps/presto-4.0/src/xyline.c:295: undefined reference to `cpgenv'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:296: undefined reference to `cpgscf'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:297: undefined reference to `cpglab'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:300: undefined reference to `cpgslw'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:302: undefined reference to `cpgbin'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:306: undefined reference to `cpgslw'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:311: undefined reference to `cpgerrb'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:312: undefined reference to `cpgpt'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:317: undefined reference to `cpgsls'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:322: undefined reference to `cpgline'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:323: undefined reference to `cpgsls'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:324: undefined reference to `cpgsch'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:325: undefined reference to `cpgmtxt'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:326: undefined reference to `cpgsch'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:327: undefined reference to `cpgmtxt'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:328: undefined reference to `cpgmtxt'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:304: undefined reference to `cpgline'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:306: undefined reference to `cpgslw'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:299: undefined reference to `cpgiden'
/usr/bin/ld: xyline.o: in function `cpgstart_x':
/usr/bin/astro_apps/presto-4.0/src/xyline.c:29: undefined reference to `cpgask'
/usr/bin/ld: /usr/bin/astro_apps/presto-4.0/src/xyline.c:29: undefined reference to `cpgask'
collect2: error: ld returned 1 exit status
make: *** [Makefile:284:psrorbit]
Yeah, you have correctly identified the problem. If you look in the Makefile
, you'll see the following:
# Include and link information for PGPLOT v5.X (including shared libs!)
# Typically you need to have your PGPLOT_DIR environment variable set
PGPLOTINC = -I$(PGPLOT_DIR)
PGPLOTLINK = -L$(PGPLOT_DIR) -lcpgplot -lpgplot $(X11LINK) $(PNGLINK)
If your PGPLOT_DIR
environment variable is not set, or does not point to the location where the PGPLOT include files can be found, or if they are not in a "normal" include directory, like /usr/include
, then you need to adjust PGPLOTINC
so that it points to them. And where they are located depends on how you installed PGPLOT. Note that I highly recommend installing it using some kind of package manager!
Yeah, you have correctly identified the problem. If you look in the
Makefile
, you'll see the following:# Include and link information for PGPLOT v5.X (including shared libs!) # Typically you need to have your PGPLOT_DIR environment variable set PGPLOTINC = -I$(PGPLOT_DIR) PGPLOTLINK = -L$(PGPLOT_DIR) -lcpgplot -lpgplot $(X11LINK) $(PNGLINK)
If your
PGPLOT_DIR
environment variable is not set, or does not point to the location where the PGPLOT include files can be found, or if they are not in a "normal" include directory, like/usr/include
, then you need to adjustPGPLOTINC
so that it points to them. And where they are located depends on how you installed PGPLOT. Note that I highly recommend installing it using some kind of package manager!
Thanks for replying!
In fact I've tried installing PGPLOT both ways (by apt-get install pgplot5
and by compiling the source code), and apt-get install pgplot5
didn't add any including file to /usr/include
. I set PGPLOT_DIR
to either /usr/lib/pgplot5
or my own path that I installed through source code and the error is just the same. Reinstalling with apt-get
doesn't work.
This is the directory installed by apt-get
:
$ ls /usr/lib/pgplot5
grexec.f grfont.dat grpckg1.inc rgb.txt
This is the directory installed with source code:
$ ls /usr/local/pgplot
cpgdemo drivers.list grfont.dat libcpgplot.a local.conf pgdemo1 pgdemo11 pgdemo13 pgdemo15 pgdemo17 pgdemo3 pgdemo5 pgdemo7 pgdemo9 pgplot.inc rgb.txt
cpgplot.h grexec.f grpckg1.inc libpgplot.a makefile pgdemo10 pgdemo12 pgdemo14 pgdemo16 pgdemo2 pgdemo4 pgdemo6 pgdemo8 pgplot.doc pgxwin_server
What type of system are you on? For the PGPLOT package in Ubuntu (which is pgplot5), the include file (cpgplot.h
) goes into /usr/include and should automatically be found:
pgplot5: /usr/include/cpgplot.h
Do you not have that file?
I'm sorry I missed it just now, it's true that cpgplot.h
is in /usr/include
. My system is Ubuntu 20.04, and I set PGPLOT_DIR
to /usr/lib/pgplot
(and source
it), but make
still goes wrong.
OK. Can you try adding "-I/usr/include" fo the PGPLOTINC line? And then re-making?
It still goes wrong
Oh! Looking closer at your errors, it doesn't seem to be having an issue with the include files. It is having trouble linking the PGPLOT libraries! Can you verify that you have libpgplot.so and libcpgplot.so in /usr/lib? (or maybe in /lib64?) That directory should be after the "-L" in the PGPLOTLINK link line of the Makefile.
Oh! Looking closer at your errors, it doesn't seem to be having an issue with the include files. It is having trouble linking the PGPLOT libraries! Can you verify that you have libpgplot.so and libcpgplot.so in /usr/lib? (or maybe in /lib64?) That directory should be after the "-L" in the PGPLOTLINK link line of the Makefile.
It works!! The libpgplot.so
and libcpgplot.so
are in /usr/lib
and putting /usr/lib
after -L
just makes it working perfectly fine!! Thanks a lot for your help!!!
Excellent! Sorry that I didn't catch that right away.
Hi there! Sorry to bother again, I'm having some new problems with running test_presto_python.py
. I've successfully run make
and installed python package, which looks like:
$ sudo pip3 install .
Processing /usr/bin/astro_apps/presto-4.0
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Requirement already satisfied: scipy in /usr/local/lib/python3.8/dist-packages (from presto==4.0) (1.6.0)
Requirement already satisfied: pyslalib in /usr/local/lib/python3.8/dist-packages (from presto==4.0) (1.0.4)
Requirement already satisfied: six in /usr/lib/python3/dist-packages (from presto==4.0) (1.14.0)
Requirement already satisfied: numpy in /usr/local/lib/python3.8/dist-packages (from presto==4.0) (1.21.4)
Requirement already satisfied: astropy in /usr/local/lib/python3.8/dist-packages (from presto==4.0) (4.3.1)
Requirement already satisfied: matplotlib in /usr/local/lib/python3.8/dist-packages (from presto==4.0) (3.4.3)
Requirement already satisfied: future in /usr/lib/python3/dist-packages (from presto==4.0) (0.18.2)
Requirement already satisfied: pyerfa>=1.7.3 in /usr/local/lib/python3.8/dist-packages (from astropy->presto==4.0) (2.0.0)
Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.8/dist-packages (from matplotlib->presto==4.0) (2.8.2)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.8/dist-packages (from matplotlib->presto==4.0) (1.3.1)
Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.8/dist-packages (from matplotlib->presto==4.0) (8.3.1)
Requirement already satisfied: pyparsing>=2.2.1 in /usr/local/lib/python3.8/dist-packages (from matplotlib->presto==4.0) (2.4.7)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.8/dist-packages (from matplotlib->presto==4.0) (0.10.0)
Building wheels for collected packages: presto
Building wheel for presto (PEP 517) ... done
Created wheel for presto: filename=presto-4.0-cp38-cp38-linux_x86_64.whl size=794903 sha256=c4aae47110197fc69c192116355ad46b395cd49f2867a5350c7c472de1696135
Stored in directory: /root/.cache/pip/wheels/25/e0/b4/11fc7e42b60a4847118db796d14a5beb1d71c745aa827a4ce0
Successfully built presto
Installing collected packages: presto
Attempting uninstall: presto
Found existing installation: presto 4.0
Uninstalling presto-4.0:
Successfully uninstalled presto-4.0
Successfully installed presto-4.0
When I run the test file, it seems $PRESTO
could not be recognized (I have set it to the directory of presto):
Warning: Couldn't open '(null)/lib/fftw_wisdom.txt'
You should run 'makewisdom'. See $PRESTO/INSTALL.
Testing FFT stuff... success
Testing FFTW call... success
Warning: Couldn't open '(null)/lib/fftw_wisdom.txt'
You should run 'makewisdom'. See $PRESTO/INSTALL.
Testing tablesixstepfft call... success
Testing reading infiles... success
Testing writing infiles... success
Note: If the following fails, edit $PRESTO/Makefile and follow
the instructions about the CFLAGS USE_FFTW_MALLOC option
Testing allocation and freeing of memory... success
Error in chkfopen(): No such file or directory
path = '(null)/lib/pulsars.cat'
I'm sure the python3
and pip3
that I used is the same one and fftw_wisdom.txt
is in /lib
and $PRESTO/src
.
That "null" means that you didn't have the PRESTO environment variable set when you compiled things. Please set that so it points to the presto top-level directory, do a "make clean ; make" in the src directory, and then re-install the python packages and it should work.
It's still the same. I also tried remove all presto file and repeat it again, but it's still (null).
$ sudo make clean
rm -f *.o *~ *#
rm -f slalib/*.o slalib/sla_test
$ sudo make
gcc -I/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I -I/usr/local/include -I/usr/bin/astro_apps/presto-4.0/include -g -Wall -W -fPIC -O3 -ffast-math -DUSEMMAP -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DUSE_FFTW_MALLOC -Wno-unused-result -Wno-unused-but-set-variable -Wno-unused-but-set-parameter -fdiagnostics-color=auto -fopenmp -c -o amoeba.o amoeba.c
gcc -I/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I -I/usr/local/include -I/usr/bin/astro_apps/presto-4.0/include -g -Wall -W -fPIC -O3 -ffast-math -DUSEMMAP -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DUSE_FFTW_MALLOC -Wno-unused-result -Wno-unused-but-set-variable -Wno-unused-but-set-parameter -fdiagnostics-color=auto -fopenmp -c -o atwood.o atwood.c
......
$ cd ..
$ sudo pip3 install .
Processing /usr/bin/astro_apps/presto-4.0
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Requirement already satisfied: matplotlib in /usr/local/lib/python3.8/dist-packages (from presto==4.0) (3.4.3)
Requirement already satisfied: pyslalib in /usr/local/lib/python3.8/dist-packages (from presto==4.0) (1.0.4)
Requirement already satisfied: six in /usr/lib/python3/dist-packages (from presto==4.0) (1.14.0)
Requirement already satisfied: numpy in /usr/local/lib/python3.8/dist-packages (from presto==4.0) (1.21.4)
Requirement already satisfied: astropy in /usr/local/lib/python3.8/dist-packages (from presto==4.0) (4.3.1)
Requirement already satisfied: scipy in /usr/local/lib/python3.8/dist-packages (from presto==4.0) (1.6.0)
Requirement already satisfied: future in /usr/lib/python3/dist-packages (from presto==4.0) (0.18.2)
Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.8/dist-packages (from matplotlib->presto==4.0) (2.8.2)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.8/dist-packages (from matplotlib->presto==4.0) (1.3.1)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.8/dist-packages (from matplotlib->presto==4.0) (0.10.0)
Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.8/dist-packages (from matplotlib->presto==4.0) (8.3.1)
Requirement already satisfied: pyparsing>=2.2.1 in /usr/local/lib/python3.8/dist-packages (from matplotlib->presto==4.0) (2.4.7)
Requirement already satisfied: pyerfa>=1.7.3 in /usr/local/lib/python3.8/dist-packages (from astropy->presto==4.0) (2.0.0)
Building wheels for collected packages: presto
Building wheel for presto (PEP 517) ... done
Created wheel for presto: filename=presto-4.0-cp38-cp38-linux_x86_64.whl size=794896 sha256=c322dee93022ce87c0ededfbc35723bce02f90a04250e174ff3e2db02fb48651
Stored in directory: /root/.cache/pip/wheels/25/e0/b4/11fc7e42b60a4847118db796d14a5beb1d71c745aa827a4ce0
Successfully built presto
Installing collected packages: presto
Attempting uninstall: presto
Found existing installation: presto 4.0
Uninstalling presto-4.0:
Successfully uninstalled presto-4.0
Successfully installed presto-4.0
$ sudo python3 tests/test_presto_python.py
Warning: Couldn't open '(null)/lib/fftw_wisdom.txt'
You should run 'makewisdom'. See $PRESTO/INSTALL.
Testing FFT stuff... success
Testing FFTW call... success
Warning: Couldn't open '(null)/lib/fftw_wisdom.txt'
You should run 'makewisdom'. See $PRESTO/INSTALL.
Testing tablesixstepfft call... success
Testing reading infiles... success
Testing writing infiles... success
Note: If the following fails, edit $PRESTO/Makefile and follow
the instructions about the CFLAGS USE_FFTW_MALLOC option
Testing allocation and freeing of memory... success
Error in chkfopen(): No such file or directory
path = '(null)/lib/pulsars.cat'
$ echo $PRESTO
/usr/bin/astro_apps/presto-4.0
Ah, you are installing as sudo. That might be your issue. Do you have the PRESTO environment variable set as sudo? Note that on my Ubuntu machine, I do all of this as myself (i.e. not sudo).
It worked! I use sudo PRESTO=xxx make
and sudo PRESTO=xxx pip3 install .
instead of simply sudo
and the test worked fine. Thanks again!
Great!