How to resolve error "Undefined reference to `pcap_parse'" - pcap

I am trying to use the libpcap library in a C++ program.
I have downloaded libpcap-1.0.0.tgz, untared it, and then
./configer
make
make install
I have libpcap.a and headers with me, and I have written one sample program to test it. But it is giving me compiler errors as follows:
/usr/local/lib/libpcap.a(gencode.o): In function `.L151':
gencode.c:(.text+0x7f4): undefined reference to `pcap_parse'
collect2: ld returned 1 exit status
I am compiling this program using following command:
g++ -o test test.cpp -lpcap
Am i doing anything wrong in building libpcap and headers?

I'm pretty sure you need to pass -lpcap before test.cpp

Try installing libstdc++-4.8-dev - this worked for me when I had a similar issue.

You have to install Libpcap-devel using this command ( sudo apt-get install libpcap-dev ) if it doesn't work install flex too (sudo apt-get install bison)
good luck

Include grammar.c which gets generated after you run ./configure and make.

Related

example.c:1:22: fatal error: postgres.h: No such file or directory

I'm trying to create my own function (using C) in postgres for which I'm referring this doc: http://www.linuxgazette.cz/139/peterson.html
For compiling - I'm referring: Section 33.9.6 . But, when I run below command:
cc -fpic -c example.c
I get this error:
example.c:1:22: fatal error: postgres.h: No such file or directory
#include "postgres.h"
^
compilation terminated.
I have also installed postgresql-server-dev-all package and tried with the solution provided in this link: How to fix 'postgres.h' file not found problem?
Nothing working for me. Please let me know how I can have postgres.h file.
I'm using postgres-12 on centos -7.
First: If you didn't install PostgreSQL from source, make sure that you installed the headers, which are in the -devel package.
If the problem persists even with the headers installed, the reason is that you forgot to tell the compiler where to look for header files:
cc -fpic -I /location/of/postgres/include -c example.c
To find that location, you can use pg_config:
pg_config --includedir
There is a similar --libdir option to show the library path for when you link the executable.
for ubuntu: apt-get -y install postgresql-server-dev-13 after apt-get -y install postgresql-13

Net::SSLeay::Handle compiling error in Ubuntu 16.04

I've a problem to install the aforementioned module via cpanm in my multi-threading version of Perl (not the original one).
I've Ubuntu 16.04.
When trying to compile and test this module it gives me the following error:
/usr/bin/ld: impossible to find -lz
collect2: error: ld returned 1 exit status
Makefile:494: instructions set for target "blib/arch/auto/Net/SSLeay/SSLeay.so" fail
make: *** [blib/arch/auto/Net/SSLeay/SSLeay.so] Error 1
-> FAIL Installing Net::SSLeay::Handle failed. See /home/my_name/.cpanm/work/1548275319.13675/build.log for details. Retry with --force to force install it.
openssl,ssllib-dev-perl,libnet-ssleay-perl, libcrypt-ssleay-perl already installed via apt-get.
I've also tried to compile manually this module, without success. I forced the installation too...no way.
The error seems linked with something missing in /usr/bin/ld: (impossible to find -lz collect2).
Is there anyone who can help me with this?
Cpanm has always worked pretty well. Up to now i've been able to get all my modules installed and well functioning, apart from Net::SSLeay::Handle.
Thanks in advace for your help
Ok, i solved by installing this packages (Ubuntu 16.04LTS):
-openssl
-libssl-dev
-libnet-ssleay-perl
-libcrypt-ssleay-perl
-zlib1g-dev as suggested above
Once you're done doing that, remember to avoid testing the module when gcc will be finishing compiling it, because in most cases it fails.
So the best incantation in doing this should be as follows:
-cpanm install -v --notest Net::SSLeay::Handle
Many thanks again to all Perl mates writing in this forum.
You saved the day
first log in cpan
sudo cpan
force intalling the module should work
force install Net::SSLeay::Handle
This should also install missing modules or notice it

error while installing open-mpi (make : No rule to make target 'all' stop)

I am trying to install open-mpi library on Ubuntu
I downloaded it from www.open-mpi.org
I followed instructions to install it as follows
./configure --prefix=$HOME/opt/openmpi
make all
make install
when i get to make all command it gives the following error
make :*** No rule to make target 'all' Stop
I don't know what can cause such an error
I found the answer to that the error was in configuration there were no g++ and gfortran compilers
so you have either to install them using
sudo apt-get install g++ gfortran
or disable them
i have now another problem when i try to compile the code it gives me the following error
Can't open module file 'mpi.mod' for reading at (1): No such file or directory
does anyone knows the answer?

Trying to install PostStat, a library to add statistics function into Postgres

I am trying to install Poststat on debian squeeze.
http://poststat.projects.postgresql.org
This project looks not so old (2008), but I am having some difficulties to install it. Although it seems to be a really interesting project, google is empty. I'll try here to sum up what I did (postgres 8.4 is installed) :
apt-get install fort77 postgresql-server-dev-8.4 libblas-dev liblapack-dev gfortran
First, as it is said on the official website, unpack the tar.gz and go in the directory f77stat and 'make'.
Then if you have libpq-dev installed, on debian squeeze it install also its owns pg_config in /usr/bin/ wich report false infos. (see http://postgresql.1045698.n5.nabble.com/Bug-report-Wrong-version-in-pg-config-td2123792.html)
One solution :
mv /usr/bin/pg_config pg_config_bak
ln -s /usr/lib/postgresql/8.4/bin/pg_config pg_config
This is important because the makefile of Poststat is retrieving some info with pg_config.
Then in the main Makefile there is the line :
-lblas -llapack -lg2c
Install those package for blas and lapack :
apt-get install libatlas-base-dev libatlas-dev libatlas-doc libatlas3gf-base
Now my problem is about g2c. According to google, g2c is obsolete so I edited the Makefile and replace -lg2c with -lgfortrant
Last step :
compile and import the new statitics functions in my database.
make && sudo make install
psql -f poststat.sql <database>
Sadly,
psql:poststat.sql:18: ERROR: unable to load the library
« /usr/lib/postgresql/8.4/lib/poststat.so » : /usr/lib/postgresql/8.4/lib/poststat.so:
undefined symbol: s_stop
Any thought ? fortran is not my world, and packages seem to have change a lot in debian about fortran. My switch from -lg2c to -lgfortrant is probably wrong. In fact removing this include does at the end produce the same error.
libg2c belongs to the g77 (http://stackoverflow.com/questions/2406581/what-is-libg2c-library), which is obsolete and unsupported for many years. Switching to a more current compiler involves more than just replacing this library. You need to replace the compiler also, e.g., gfortran. You might need to change the default compiler options of gfortran to be able to compile FORTRAN 77 code. I use: -O2 -ffixed-form -ffixed-line-length-none. If you use gfortran as the linker you won't need to explicitly include the fortran run-time library.
change -lg2c by -lf2c
Add to poststat.c , at the end
int MAIN__(){
return (0);
}

How to install XML::Parser without expat-devel?

XML::Parser fails to build on a quite fresh 64-bit Debian box. After issuing cpan XML::Parser, cpan fails with lots of errors about Expat.c and Expat.xs:
[...]
Expat.xs:2182: error: ‘CallbackVector’ has no member named ‘skip_until’
Expat.c: In function ‘XS_XML__Parser__Expat_Do_External_Parse’:
Expat.c:2904: error: ‘XML_Parser’ undeclared (first use in this function)
Expat.c:2904: error: expected ‘;’ before ‘parser’
Expat.xs:2194: error: ‘parser’ undeclared (first use in this function)
make[1]: *** [Expat.o] Error 1
make[1]: Leaving directory `/root/.cpan/build/XML-Parser-2.41-rpV6ok/Expat'
make: *** [subdirs] Error 2
TODDR/XML-Parser-2.41.tar.gz
/usr/bin/make -- NOT OK
Running make test
Can't test without successful make
Running make install
Make had returned bad status, install seems impossible
Message at the start of the output explains that expat-devel is needed for building.
Expat must be installed prior to building XML::Parser and I can't find
it in the standard library directories. Install 'expat-devel' package with your
OS package manager. See 'README'.
But expat-devel is not in Debian repository.
Is it possible to get over this without need to build/install expat from source?
The package you want to install is named libexpat1-dev. You could also just install libxml-parser-perl via apt-get. Or if you really want to install via CPAN try installing the Debian packages dependencies first via apt-get build-dep libxml-parser-perl.
libexpat1-dev contains both libexpat and expat.h, which are both mentioned in the message as well:
If expat is installed, but in a non-standard directory, then use the
following options to Makefile.PL:
EXPATLIBPATH=... To set the directory in which to find libexpat
EXPATINCPATH=... To set the directory in which to find expat.h
Installing libexpat1-dev seems to solve the problem:
$ aptitude install libexpat1-dev
There is always the manual method - to build/install expat from source.
(This example shows installing to an alternative location for XAMPP | LAMPP)
Download from:
http://sourceforge.net/projects/expat/files/expat/
tar zxf /[where-ever]/expat-2.1.0.tar.gz -C /tmp
cd /tmp/expat-2.1.0
/opt/lampp/bin/perl ./configure --prefix=/opt/lampp LDFLAGS=-L/opt/lampp/lib
make
make install
http://search.cpan.org - search for and download - XML::Parser
tar zxf /[where-ever]/XML-Parser-2.41.tar.gz -C /tmp
cd /tmp/XML-Parser-2.41
/opt/lampp/bin/perl ./Makefile.PL EXPATLIBPATH=/opt/lampp/lib EXPATINCPATH=/opt/lampp/include
make
make test
make install
Work like a charm in Ubuntu 15.04. The only thing that I need is install Perl XML Parser with:
sudo apt-get install libxml-parser-perl
And following the instructions here, I was able to import successfully all my ratings into Rhythmbox. Now, the only work that I need to do is create again the smart play lists, that is nothing compared with my entire libray ratings.
Today I had the same issue wanting to complile the new GIMP 2.9.4 beta on OSX 10.8 and the aid of homebrew.
First install perl
brew install perl
Then the XML::Parser module by going into the perl shell with
perl -MCPAN -e shell
And inside the shell install XML::Parser by typing
install XML::Parser
Exit shell
exit
Now, verify it has been installed successfully. If everything is ok, you will not see an error.
perl -e "require XML::Parser"
If the ./configure still fails missing XML::Parser, then intltools is not using the perl you have installed. Looking at the script tells me it does the test with $INTLTOOL_PERL -e "require XML::Parser". Trying a echo $INTLTOOL_PERL gave out nothing, so the magic is to set it with
export $INTLTOOL_PERL=perl
Now run ./configure again.
None of the above methods worked for me. I had the right environment variables setup but they were somehow not picked up by cpanm that I use to install perl modules. Expat was also installed.
Here is what I did to overcome the same problem that OP is reporting.
This is very close to what #LadyBuzz suggested.
Download the XML::Parser from cpan.org
Extract the tarball into directory and descend to it.
Open the Makefile.pl and edit the first lines to actually have the absolute paths to both: EXPATLIBPATH and EXPATINCPATH
Save the Makefile.pl, go up one level and create a new tarball with the Makefile.pl that you just edited.
Execute cpanm on the newly created tarball.
This resulted in successful installation of the module.