'readline/readline.h' file not found - c

I have included:
#include "stdio.h"
#include <readline/readline.h>
#include <readline/history.h>
and my compiler includes the flag
-lreadline
but I am still receiving the error message:
fatal error: 'readline/readline.h' file not found
I am trying to use the function, readline();
Defined in more detail here: http://linux.die.net/man/3/readline

You reference a Linux distribution, so you need to install the readline development libraries
On Debian based platforms, like Ubuntu, you can run:
sudo apt-get install libreadline-dev
and that should install the correct headers in the correct places,.
If you use a platform with yum, like SUSE, then the command should be:
yum install readline-devel

This command helped me on linux mint when i had exact same problem
gcc filename.c -L/usr/include -lreadline -o filename
You could use alias if you compile it many times
Forexample:
alias compilefilename='gcc filename.c -L/usr/include -lreadline -o filename'

Related

Compile an SDL project using gcc?

How can I compile a sdl project using gcc in the linux command line without using Cmake?
EDIT;
gcc SDLGAME.c pkg-config --cflags --libs sdl2
but i get error.
gcc: error: Pkg-config: No such file or directory
gcc: error: sdl2: No such file or directory
gcc: error: unrecognized command line option ‘--cflags’
gcc: error: unrecognized command line option ‘--libs’; did you mean ‘--libs=’?
#HolyBlackCat
source code --->>
#include <stdio.h>
#include <SDL2/SDL.h>
int main(int argc,char *argv[])
{
if (SDL_Init(SDL_INIT_VIDEO) !=0)
{
printf("error SDL");
return 0;
}
SDL_Window* win=SDL_CreateWindow("Game",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
500,500,0);
return 0;
}
I get this error--->>
error: XDG_RUNTIME_DIR not set in the environment.
error SDL
Caveat: This isn't a total solution but some suggestions and is prefaced by top comment's and comments under OP's [now deleted] answer.
To review ...
After fixing the original issue by use of:
gcc -o SDLGAME SDLGAME.c `pkg-config --cflags --libs sdl2`
OP running the program produces:
error: XDG_RUNTIME_DIR not set in the environment.
This may be a general issue about the ubuntu install itself. Some resources for that: https://askubuntu.com/questions/872792/what-is-xdg-runtime-dir and
https://askubuntu.com/questions/456689/error-xdg-runtime-dir-not-set-in-the-environment-when-attempting-to-run-naut
A workaround may be:
export XDG_RUNTIME_DIR=/tmp/dir
mkdir -p /tmp/dir
But, I ran the program successfully on my home system, running fedora 29 and my ubuntu system running 18.04.5
On my systems, XDG_RUNTIME_DIR was set to /run/user/1000. However, with/without the workaround and even doing unset XDG_RUNTIME_DIR worked on my systems.
However: On my ubuntu system, I had removed the standard libsdl2 package and rebuilt and installed it from the source package a year ago due to some issues I had.
So, if the workaround doesn't work, I recommend libsdl2 rebuild/reinstall from source.
Even if the standard package is working, when debugging your app, it can be helpful to be able to consult the libsdl2 source.
Note that one change I made to your app was to add a sleep(3) at the bottom so you can see the window come up.
Here is the method I used to build/install from source:
It's probably necessary to uninstall/remove the binary libsdl2 package. So, you'll have to do (e.g.)
sudo apt-get remove libsdl2 libsdl2-dev
Or, whatever the binary package is called [I forget]. But, those also came from: apt-cache search libsdl2
So, once that's cleaned out, what I did was:
Create a directory (e.g.): $HOME/aptsrc
cd $HOME/aptsrc
Download the source package [without sudo]: apt-get source libsdl2
This extracts several files (e.g. *.tar.gz, *.tar.xz, *.dsc and a directory. On my system, it was: libsdl2-2.0.8+dfsg1, but for you it may be different. Do (e.g.): DIR=$HOME/aptsrc/libsdl2-2.0.8+dfsg1
cd $DIR
Configure with: $DIR/configure
Run cmake: cmake $DIR
Run make with: make
Install with: sudo make install
Note that this comes from an internal script I created. Even after the cd $DIR, I think it's necessary to use full path on the commands [where indicated].
Now, the library should be installed under /usr/local. The output of pkg-config --cflags --libs sdl2 should reflect this:
-D_REENTRANT -I/usr/local/include/SDL2 -L/usr/local/lib -Wl,-rpath,/usr/local/lib -Wl,--enable-new-dtags -lSDL2
The original output of this command would have looked like:
-I/usr/include/SDL2 -D_REENTRANT -lSDL2
This is for the standard install from the binary package, so if you still have that, the binary package may still be installed.
Otherwise, you should now be able to rebuild your app using the original gcc command. Now, it should be attached to the source built version of the library. You can confirm this with: ldd ./SDLGAME but just running it might be easier.

compiling keepalived from source not working

i have been trying to compile and install keepalived like in the following link http://www.keepalived.org/doc/installing_keepalived.html
i'm building it on ubuntu/trusty64 vagrant machine
i have installed all the requirement specified in the document
sudo apt-get install curl gcc libssl-dev libnl-3-dev libnl-genl-3-dev libsnmp-dev
when i made 'make' command
it showed me the following error
gcc -g -O2 -I/usr/src/linux/include -I/usr/src/linux/include -
DLIBIPVS_USE_NL -Wall -Wunused -c -o libipvs.o libipvs.c
In file included from libipvs.h:13:0,
from libipvs.c:23:
ip_vs.h:15:29: fatal error: netlink/netlink.h: No such file or directory
#include <netlink/netlink.h> <-(the terminal saying that the error)
i tried that answer
libnl-3 includes broken?
i entered
sudo make -I /usr/include/libnl3
or
make -I /usr/include/libnl3
but both failed i'm kind new c compiling and building in linux so i would aperciate any help

Using pocketsphinx in c

I am trying to install and use pocketsphinx on ubuntu in c language but I keep getting this error
/Desktop/Programming/C/Tests$ gcc libraries.c -o libraries
libraries.c:2:26: fatal error: pocketsphinx.h: No such file or directory
#include <pocketsphinx.h>
^
compilation terminated.
I have followed the step required to install sphinxbase and pocketsphinx found here but I keep getting the error every time I compile my code. Is there something i missed?
How did you install pocketsphinx? and what do you mean by "installing"
To work with a library you first need to have the headers in place where your compiler can find them (for GCC for example by using the -I option) and then you need to have the library installed so your compiler can build against it.
Judging from the error you didn't specify the header files of the library to your compiler
You can add manually
First go to the includes folder
$ cd /usr/include
Then add the pocketsphinx.h manually
$ sudo ln -s /my/path/to/pocketsphinx.h
So then when you want to include pocketsphinx.h file, you can use:
#include <pocketsphinx.h>

gcc can't find -lX11

I've used linuxbrew to install gcc 5.3 on a machine on which I don't have sudo access. I now want to link with X11:
> gcc test.c -lX11
ld: cannot find -lX11
I've checked that libX11.so exists in /usr/lib64/ which is on the compiler's LIBRARY_PATH. If I use the system's gcc it works fine, but I need a newer version to compile my actual program.
use -L flag, like this -L/usr/lib64, or you can specify full path to library like this gcc test.c /usr/lib64/libX11.so
According to this comment by a linuxbrew developer,
linuxbrewed gcc removes /usr/lib64 from the library path because mixing system libraries with brewed libraries creates havoc.
The solution is to brew install linuxbrew/xorg/xorg.

libc.h: No such file or directory when compiling nanomsg pipeline sample

Trying to get a simple nanomsg file running, starting with the first one here: https://github.com/dysinger/nanomsg-examples
Installed nanomsg to /usr/local/lib/nanomsg-0.2-alpha. Ran sudo ./configure, sudo make check, sudo make install and sudo ldconfig as the instructions said. All tests pass.
When I run it says libc.h is not found:
$ gcc pipeline.c /usr/local/lib/libnanomsg.a -o pipeline
pipeline.c:2:18: fatal error: libc.h: No such file or directory
compilation terminated.
What is libc.h? I haven't done any C programming since college. Is it part of nanomsg or a C library?
$ which gcc
/usr/bin/gcc
Ubuntu 12.04.4 LTS
Libc.h just contains small list of includes. To compile nanomsg sample its enough to (src):
Replacing:
#include <libc.h>
with
#include <unistd.h>
#include <string.h>
#include <pthread.h>
I used this cmd for static compilation:
gcc -pthread bus.c ../nanomsg/.libs/libnanomsg.a -o test -lanl
Note -pthread and -lanl at the end of line.
try the following:
$ sudo updatedb
$ locate libc.h
find the path where libc.h located. eg, if your libc.h is /usr/local/include
gcc -I/usr/local/include pipeline.c /usr/local/lib/libnanomsg.a -o pipeline

Resources