error when compiling testfiles from installed c-algorithms library - c

I'm trying to install and test c library c-algorithms from Github.
https://github.com/fragglet/c-algorithms/blob/master/test/test-queue.c
When I try to test the installation from the generated test folder with:
gcc -o test-arraylist `pkg-config --cflags --libs libcalg-1.0` test-arraylist.c
I get the following error massage:
test-arraylist.c:30:23: fatal error: arraylist.h: No such file or directory
compilation terminated.
I use a Vagrant box: ubuntu/xenial32 with Ubuntu 14.04.5 LTS
Prior to installation of c-algorithms:
sudo apt-get install autoconf
sudo apt-get install libtool
sudo apt-get install pkg-config
To install the library I have done following:
sudo ./autogen.sh
sudo ./configure
sudo make
sudo make install
Any help would be highly apriciated

The test-arraylist.c has line #include "arraylist.h" but it is under the libcalg subdirectory not directly in the include path.
libcalg subdir should be added to the include path or you have to modify the include like #include "libcalg/arraylist.h"
If you want only run the tests, then run the
sudo make check from the build root (in your case it is the source root)

This is probably going to be stomped on by process-fetishizers.
But.
When you build in a Unix/Linux operating system (and derivatives like RTEMS), you are building off other people's libraries - so you need those libraries and their header files ( just like c-alg... ) installed in locations that your compiler can find.
To find a file that is associated with a package, use dpkg as explained here:
https://askubuntu.com/questions/481/how-do-i-find-the-package-that-provides-a-file
But you have another problem you might not be aware of. You are trying to compile a test program using a gcc command when the software uses GNU autoconf automake and probably libtool to function PROPERLY.
Perhaps you don't understand you need to make sure autoconf, automake, and then libtool find the right configuration from one directory system to another. Fedora puts files in differing spots from Ubuntu distros.
Instead run:
autoreconf -fvi
first in the top level directory and see if this finds your header file.
THEN you run
./configure
and then
make test/check
(whichever it uses, some use recipe "all-tests", etc.)
make all
This would make all if your system is ready to handle them.

Related

How to make Python.h file work in Ubuntu?

I am on an Ubuntu machine and I want to use python in my C code but when I include the Python.h header file, it shows a warning:
Python.h: No such file or directory
Any method for this. I have already tried to use:
sudo apt-get install python3-dev and;
sudo apt-get install python-dev
But it keeps showing error.
The Python.h file is not in the default compiler include path.
Add the output of pkg-config --cflags python3 to your compiler command line.
Now the compiler will know where to find Python.h (and any dependencies it may have)

How to compile custom PulseAudio module?

I am trying to write a PulseAudio module. To start, first, I wrote the following minimal code for a module as mentioned by this documentation.
#include <pulsecore/module.h>
int pa__init(pa_module *m)
{
return 0;
}
I tried compiling it with this command:
gcc -g -shared -o module-test.so module-test.c
But it gives error:
pulsecore/module.h: No such file or directory
#include <pulsecore/module.h>
^~~~~~~~~~~~~~~~~~~~
compilation terminated.
After searching on the internet, I found that I have to installed libpulse-dev, but I have already installed pulseaudio and libpulse-dev as you can see below.
jyotesh#jyotesh-VM:~$ sudo apt install pulseaudio libpulse-dev
[sudo] password for jyotesh:
Reading package lists... Done
Building dependency tree
Reading state information... Done
libpulse-dev is already the newest version (1:11.1-1ubuntu7.2).
pulseaudio is already the newest version (1:11.1-1ubuntu7.2).
0 upgraded, 0 newly installed, 0 to remove and 10 not upgraded.
I have tried searching for the header file using locate, find, apt-file, etc. I am not able to find where this header file is.
Does anyone know how to compile the PulseAudio module?
I was able to compile the code and build module-test.so file by following the steps from here and here. I will repeat the steps here:
First, I built and installed PulseAudio v12.2 from the source code.
# Clone PulseAudio git repository
git clone https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
# I wanted 12.2 version of PulseAudio, so I checked out that version
cd pulseaudio
git checkout tags/v12.2
# Install the dependencies
sudo apt-get -y build-dep pulseaudio
# Build PulseAudio source code
./bootstrap.sh
make
# Install and configure dynamic linker run-time bindings (so that
# ld can find the libraries that you specify while building your module)
sudo make install
sudo ldconfig
After this, I wrote minimal code for a module.
#include <config.h> // this is required, otherwise you will get compilation errors
#include <pulsecore/module.h>
int pa__init(pa_module *m)
{
return 0;
}
To compile this, I used the command
gcc -g -shared -fPIC -I/home/jyotesh/pulseaudio -I/home/jyotesh/pulseaudio/src -L/home/jyotesh/pulseaudio/.libs -L/usr/local/lib/pulseaudio -o module-test.so module-test.c -lpulsecore-12.2 -lpulsecommon-12.2 -lpulse

Including Linux Headers returns No such file or directory

I'm trying to write a C code that will make use of the memory information in Linux kernel (Virtual address space of a process, status of a process and such info.)
I'll need to include the below headers to get these info.
#include<linux/init.h>
#include<linux/module.h>
#include<linux/mm.h>
The actual files exists under the linux folder, but when compiling the file using gcc it returns that
No such file or directory
Can someone please explain why i'm getting this error! and what should i do?
I've already compiled the Kernel and installed all updates available (kernel version 3.16.0)
The answer to your question.
Install the missing package kernel-devel using apt-get
NOTE: I've mentioned apt install package you can use what is supported on your system for example yum.
If you're not able to install kernel-devel then you can try this which install generic Linux headers.
sudo apt-get update && sudo apt-get install linux-headers-`uname -r`
Then you can check where the init.h or module.h using locate utility
and then add the path in your compilation using -I flag.
gcc -g your_file.c -I/usr/path/of/the/kernel/header/include

linking clang address sanitizer on FreeBSD 10.1 Release

I'm trying to get address sanitizer working on FreeBSD 10.1 Release, but whenever I try to compile a program with -fsanitize=address I get undefined references to _asan_stack_malloc_1 etc, etc. I found
https://forums.freebsd.org/threads/gcc-clang-address-sanitizer.47985/ on google but the suggestion of adding -L/usr/local/lib -I/usr/local/include didn't resolve the linking issue. I tried the llvm binaries for FreeBSD but when I go to compile with that clang I get /usr/bin/../lib/clang/3.6.0/lib/freebsd/libclang_rt.asan-x86_64.a , no such file or directory. . Either way I'm not sure what library I need to link or where it is.
Below is the program I tried compiling and here is the command I used,
clang -fsanitize=address san.c
#include <stdio.h>
int main(void)
{
return 0;
}
As an alternative to building LLVM, as suggested in this answer on Unix SE, you can install llvm37 from ports, which supports AddressSanitizer, and build with that:
# pkg install llvm37
$ clang37 -fsanitize=address san.c
To use asan on FreeBSD you can build llvm with asan support as shown below or you can install from packages/ports like in Kevinoid's answer.
Step one, grab the latest stable llvm source.
fetch http://llvm.org/releases/3.9.0/llvm-3.9.0.src.tar.xz
Now uncompress the llvm source directory.
tar -xvf llvm-3.9.0.src.tar.xz
Next change directory to llvm and grab the clang source files.
cd llvm-3.9.0.src/tools && fetch http://llvm.org/releases/3.9.0/cfe-3.9.0.src.tar.xz
Uncompress clang.
tar -xvf cfe-3.9.0.src.tar.xz
Enter the projects directory and grab compiler-rt.
cd ../projects && fetch http://llvm.org/releases/3.9.0/compiler-rt-3.9.0.src.tar.xz
Uncompress compiler-rt.
tar -xvf compiler-rt-3.9.0.src.tar.xz
Goto the root llvm directory and make a build directory for cmake.
cd ../ && mkdir build && cd build
Use cmake to setup the llvm build.
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON [-DLLVM_ENABLE_WERROR=ON] [-DLLVM_TARGETS_TO_BUILD=X86] -DBUILD_SHARED_LIBS=ON ../
Build llvm and go grab some tea, it will take a bit.
make -j12
If the build worked you should be left with clang with asan support. Make sure to remove the old compiler, /usr/bin/clang, /usr/bin/clang++ and /usr/bin/cc.
Then install the new clang by doing sudo make install. Finally you will probably want to link /usr/bin/cc to /usr/local/bin/clang by running sudo ln /usr/local/bin/clang /usr/bin/cc.
After doing all these steps you should be able to compile code with the -fsanitize=address compile option.

Building/Linking libgcrypt for Mingw

I'd like to implement some features of libgcrypt in my program, but it is currently running on Windows, OSX, and Linux (Arch/Xubuntu), so I can only really do so if I can build it for all three platforms. On OSX and Linux I had no problem.
I got the sources from the github page for libgcrypt and libgpg-error, and I've successfully built and run the libraries on both Linux and OSX, so I know that my test code is valid (which I am now having trouble with on Windows w/MinGW).
I did the following on Xubuntu (and similar on Arch but using pacman instead of apt-get):
sudo apt-get install mingw32 mingw32-runtime mingw32-binutils
to get the cross compiling tool chain and
git clone https://github.com/Chronic-Dev/libgcrypt.git
git clone https://github.com/Chronic-Dev/libgpg-error.git
cd libgpg-error
autoreconf -vfi
./autogen.sh --build-w32
make
sudo make install
cd ../libgcrypt
autoreconf -vfi
./autogen.sh --build-w32
make
sudo make install
to build, and it successfully builds these files in home/myuser/w32root/:
libgcrypt.a
libgcrypt.def
libgcrypt.dll.a
libgcrypt.la
libgpg-error.dll.a
libgpg-error.la
include/
gcrypt.h
gcrypt-module.h
gpg-error.h
I took these files over to windows, and tried compiling the test code (named main.c locally) with
gcc main.c -o main.exe -lgcrypt
but I get undefined reference errors leading me to the conclusion that the library wasn't linked correctly (initially only using libgcrypt.a), so I looked some stuff up, and found that some libraries require a set of files like .a, .def, et al. to work, so I dropped them all in C:\Mingw\lib to see if it made a difference; it didn't. The following was also silent in finding the library file to link, but didn't resolve the undefined references:
gcc main.c -o main.exe -lgcrypt -lgpg-error
So I'm not really sure where to go from here. The readme doesn't get into cross compiling too much, like what files to copy and link once you're on the Windows side. Any pointers (to docs for it I missed maybe?) are appreciated! Thanks a bunch for reading my wall of text.

Resources