c - can't compile with <sys/times.h> ubuntu - c

I have 64bit ubuntu installed, and I am trying to compile a code with times.h however I keep getting sys/times.h No such file or directory
What I have tried so far
1. installing libc6-dev-i386, g++-multili, and libc6 and libc6-dev (Even though it is already installed)
2. I swapped <sys/times.h> to </usr/include/sys/times.h> and now I am getting features.h No such file or directory error
Question:
It is weird how it accepts </usr/include/sys/times.h> instead of <sys/times.h>, and help?
EDIT: I can access times.h, if it matters

I would recommend running:
$ locate /sys/time.h | grep include
Using the output you can determine what to do next:
If there is a file named /usr/include/<x86_64 or i386>-linux-gnu/sys/time.h, then simply run: $ sudo ln -s /usr/include/<x86_64 or i386>-linux-gnu/sys /usr/include/sys. This will direct the compiler to the right file if it checks . This seems to be what you are doing manually.
If there is no relevant output, then try downloading build-essential. It may be that something else is missing. $ sudo apt-get update; sudo apt-get install build-essential
Let me know if this helps!

Related

How can I run GCC into WSL?

So, Windows System on Linux seems to be an inovative light-weight substitute for a virtual machine, especially when it comes to learning Linux. Nevertheless, for me WSL seems to have a little more complicated organization from a VM when it comes to file management. For example, in WSL the data are stored in
C:\Users\<username>\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState\rootfs\usr\
as shown here.
Of course my first try to install GCC was to type in:
sudo apt install gcc
,but after typing
gcc --version
the output was :
Command 'gcc' not found, but can be installed with:
sudo apt install gcc
After that, I tried installing GCC using the following commands as shown here :
$ sudo apt-get update && sudo apt-get upgrade -y
$ sudo apt autoremove -y
$ sudo apt-get install gcc -y
but I end up getting the same output.
On the other hand, I already had installed TDM GCC on Windows and used sudo in VM to install it also there (successfully:).
Like a lot of people, I want to substitute the use of my virtual machine with WSL in order to be able to develop in C without overloading my RAM my questions are :
Can you count out for me how many times have I downloaded GCC files?
Why the folder that I was supposed to be downloading the gcc files in is shown to be empty?
Where are the downloaded files being stored?
How can get gcc fired up?
Is there any way to use the gcc I had on Windows to compile C using the WSL terminal?
I think these questions come from the fact that I cannot understand how WSL file system interacts with Windows. They are a bit more generic on purpose because I want you to have a lot of "answering" freedom.
Please help me out of this one! I don't want to be forced to use a virtual machine and run out of RAM almost every time!

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)

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

error when compiling testfiles from installed c-algorithms library

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.

PECL install fails

I have browsed every Google result, read all the forum posts about this error, but I cannot solve it.
When using PECL install for anything, I always end up getting this error:
checking whether the C compiler works... configure: error: cannot run C compiled programs.
Everything else succeeds up to that point them bam!
I'm using CentOS 4.3, PEAR is the latest stable version, GCC is a stable and recent version. Everything is working as it should, but the C compiler always seems to error. I've tried to make tmp have the right privilages for the operation by temporarily enabling it using:
mount -o remount,exec,suid /tmp
But that doesn't work.
I've literally tried everything that has been suggested by to no avail. Any ideas?
I'm on Centos 5.3 and I was able to get PECL installers running (APC in my case) successfully by removing the noexec flag on both /tmp and /var/tmp
mount -o remount,exec,suid /tmp
mount -o remount,exec,suid /var/tmp
Doing this only on /tmp didn't work - I still received the error "checking whether the C compiler works... configure: error: cannot run C compiled programs."
Remember to run these remounts again with noexec after your install finishes.
cd ~
mkdir setups
cd setups
wget http://pecl.php.net/get/APC-3.1.2.tgz
tar -xvf APC-3.1.2.tgz
cd APC-3.1.2
phpize && ./configure --with-apxs && make
I quickly wrote that up and was able to install APC with a bit of manual work. Such as copying the module to PHP modules and adding the extension to the php.ini. Works perfectly now.
When I had similar problems installing the MongoDB driver, this worked for me:
sudo mkdir /root/tmp.pear
sudo mkdir /root/tmp.pear-build-root
sudo ln -s /root/tmp.pear /tmp/pear
sudo ln -s /root/tmp.pear-build-root /tmp/pear-build-root
Then:
sudo sudo pecl install XXX
(This doesn't open a security hole because only root can create executables in those two directories.)
Note that the following does not work for PECL:
sudo pear config-set temp_dir /var/tmp/pear/temp

Resources