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

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

Related

Exception: Failed to attach BPF to kprobe when executing sudo opensnoop-bpfcc

When I try to execute sudo opensnoop-bpfcc I get this message:
In file included from /virtual/main.c:4:
In file included from include/linux/sched.h:14:
In file included from include/linux/pid.h:5:
In file included from include/linux/rculist.h:11:
In file included from include/linux/rcupdate.h:40:
In file included from include/linux/preempt.h:81:
In file included from ./arch/x86/include/asm/preempt.h:7:
In file included from include/linux/thread_info.h:38:
In file included from ./arch/x86/include/asm/thread_info.h:53:
./arch/x86/include/asm/cpufeature.h:150:2: warning: "Compiler lacks ASM_GOTO support. Add -D __BPF_TRACING__ to your compiler arguments"
[-W#warnings]
#warning "Compiler lacks ASM_GOTO support. Add -D __BPF_TRACING__ to your compiler arguments"
^
1 warning generated.
Traceback (most recent call last):
File "/usr/sbin/opensnoop-bpfcc", line 127, in <module>
b.attach_kprobe(event="sys_open", fn_name="trace_entry")
File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 526, in attach_kprobe
raise Exception("Failed to attach BPF to kprobe")
Exception: Failed to attach BPF to kprobe
I don't understand how to fix it. I've just installed bcc tools using this command
sudo apt-get install bpfcc-tools linux-headers-$(uname -r)
as suggested on the github page https://github.com/iovisor/bcc/blob/master/INSTALL.md#ubuntu---binary
The running OS is 18.04.2 LTS (Bionic Beaver).
I had to compile bcc from source code instead of installing it using the package.
Install linux kernel headers
sudo apt install linux-headers-$(uname -r)
Install required dependencies
sudo apt-get -y install bison build-essential cmake flex git libedit-dev \ libllvm6.0 llvm-6.0-dev libclang-6.0-dev python zlib1g-dev libelf-dev
Compile bcc from source code
git clone https://github.com/iovisor/bcc.git
mkdir bcc/build; cd bcc/build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr
make
sudo make install
#Maicake is right. Compiling and installing from source did work for me. Here are the steps to install on Ubuntu 22.04:
Follow the steps described here. Specifically for Ubuntu 22.04 you may need to make some changes after cloning the bcc repository.
Add the following line to your .bashrc file:
export PATH=$PATH:/usr/share/bcc/tools
Create a symlink to python3 as most of the tools use python (not python3) to run the scripts.
sudo ln -s /usr/bin/python3 /usr/bin/python

GPAC MP4Box ZLIB Error

I've been trying to get MP4Box installed on my CentOS 7 box using the following instructions:
...
cd extra_libs
cp -r * /usr/local/src/gpac/extra_lib
cd ..
cd gpac
chmod 755 configure
./configure
make lib
make apps
make install lib
make install
cp bin/gcc/libgpac.so /usr/lib
install -m644 bin/gcc/libgpac.so /usr/local/lib/libgpac.so
chmod +x /usr/local/lib/libgpac.so
ldconfig
Everything works fine until I get to ./configure which gives me an error:
./configure: line 354: gcc: command not found
error: zlib not found on system or in local libs
I've removed and reinstalled ZLIB and still no luck. I'm pretty new to CentOS so I'm not sure if the problem is with MP4Box or my CentOS installation. I did read that is could be a location issue, here is what I get when I run a whereis /usr/include/zlib.h /usr/share/man/man3/zlib.3.gz. Thoughts?
It turns out that gcc was not installed. I did a yum install gcc and that resolved my issue.

/usr/bin/ld: cannot find -lstdc++ for Ubuntu while trying to "swift build" Perfect2 project

Description:
I've followed the installation steps for Swift3 and Perfect2
and I've cloned the PerfectTemplate test project proposed by Perfect and I've tried swift build
Error Message:
warning: minimum recommended clang is version 3.6, otherwise you may
encounter linker errors. Linking ./.build/debug/PerfectTemplate
/usr/bin/ld: cannot find -lstdc++ clang: error: linker command failed
with exit code 1 (use -v to see invocation) :0: error: link
command failed with exit code 1 (use -v to see invocation)
:0: error: build had 1 command failures error: exit(1):
/etc/swift301/usr/bin/swift-build-tool -f
/home/XXXX/ClionProjects/PerfectTemplate/.build/debug.yaml
What I've tried:
I've gone on different SO questions that seemed similar but all on different projects and attempted to try their solutions without luck:
For example:
Matlab Kalman /usr/bin/ld: cannot find -lstdc++
I also noticed the warning coming from the clang version, I am aware that my current version is 3.4, but that is what was installed via sudo apt-get install clang as mentioned in the documentation.
I've also tried installing the 3.6 version of clang with: sudo apt-get install clang-3.n
However, after when I try swift build again I get the following error:
error: invalid inferred toolchain: could not find clang
Question:
How do I get rid of the /usr/bin/ld: cannot find -lstdc++ error, so I can build the PerfectTemplate project?
Try this. It might not work, but it's worth a shot.
Update packages and dependencies:
sudo apt-get update
Then install clang 3.6:
sudo apt-get install clang-3.6
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100
I hope this helps, but apologies if it doesn't. Best of luck!
If this error appears:
/usr/bin/ld.gold: error: cannot open
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../libstdc++.‌​so: No
such file or directory
It's most likely that the libstdc++.so symbolic link points to an inexisting file.
In my case it was pointing to:
/usr/lib/libstdc++.so -> /usr/lib/libstdc++.so.6
Which was incorrect because libstdc++.so.6 did not exist in that area. Simply find it's location via: sudo find / -name libstdc++.so.6 which gave me:
/usr/lib/x86_64-linux-gnu/libstdc++.so.6
Then recreate the link with:
sudo rm /usr/lib/libstdc++.so
sudo ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /usr/lib/libstdc++.so
sudo apt-get install build-essential
I faced with same problem and update-alternatives didn't help me, but after
sudo apt-get update && sudo apt-get upgrade
swift build ran successfully. Looks like some dependencies were deprecated.

GLib compile error (ffi.h), but libffi is installed

After a succesful configure, make exits with snipped
gclosure.c:29:17: fatal error: ffi.h: No such file or directory
compilation terminated.
I have libffi installed, and locate ffi.h gives:
/home/luca/gcc4.6/gcc-4.6.0/libffi/include/ffi.h.in
/usr/include/x86_64-linux-gnu/ffi.h
/usr/share/doc/ghc-doc/html/users_guide/ffi.html
/usr/share/doc/libffi5/html/Using-libffi.html
If you have a Debian-based Linux OS with apt-get:
sudo apt-get install libffi-dev
With a Redhat-base OS:
yum install libffi-devel
With Alpine Linux:
apk add libffi-dev
When compling libffi 3.0.9 from source code, the include/Makefile.in installs the includes in the ${PREFIX}/lib/libffi-3.0.9/include directory. I'm sure there's a WONDERFUL reason for that, but I'm annoyed by it.
This line fixes it, when compiling libffi:
/bin/perl -pe 's#^includesdir = .*#includesdir = \#includedir\##' -i include/Makefile.in
The includes will now be installed in ${PREFIX}/include, which is /usr/local/include for me.
My full recipe is:
cd /var/tmp
rm -rf libffi-3.0.9
untgz /usr/local/src/utils/libffi-3.0.9.tar.gz
cd libffi-3.0.9
/bin/perl -pe 's#^AM_CFLAGS = .*#AM_CFLAGS = -g#' -i Makefile.in
/bin/perl -pe 's#^includesdir = .*#includesdir = \#includedir\##' -i include/Makefile.in
./configure --prefix=/usr/local \
--includedir=/usr/local/include
gmake
gmake install
Resolved by manually setting LIBFFI_CFLAGS for location of ffi.h in configure
Check your GCC version and note this entry in the Debian Bug Archive: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=523869
It was the final solution to my particular issue (it looked exactly like what you report, but couldn't be solved with the solution above)... my problem had nothing to do with LIBFFI at all.
An old thread, but anyway...
After putting the required files in a location where they could be found, I got it working:
cp /usr/include/x86_64-linux-gnu/ffi* /usr/local/include/
cp /usr/lib/libffi.so /usr/local/lib/

pcap.h header file problem

anyone know how to fix the problem regarding header file in ubuntu 10.10.
I am executing a sniffing program which makes use of this header file. My system shows libcap package is installed. Still, on compiling the code, an error is coming which reads:
fatal error: pcap.h: No such file or directory
compilation terminated.
Please help me out.
Thanks all:)
The system won't let me correct Eric Fossum's comment, because I lack reputation. There is a typo ("libcap" vs. "libpcap") and his suggested command should read the following:
sudo apt-get install libpcap-dev
sudo apt-get install libpcap0.8-dev
If you are using yum, then
sudo yum install install libpcap-devel
You don't have the pcap.h file in your include path. You need to add the location of pcap.h to your include path when compiling:
-I/path/to/pcap.h
If you're using linuxbrew, you can just brew install libpcap. In my case I was trying to install nethogs and it failed with this error.
First install libpcap:
sudo apt-get install libpcap0.8-dev
then create its shortcut for header file:
ln -s /usr/include/pcap/bpf.h /usr/include/net/bpf.h