term.h : header not found - c

I have a little piece of code for linux terminal capabilities, it uses the term.h header file
#include <stdio.h>
#include <term.h>
#include <curses.h>
#include <stdlib.h>
main()
{
setupterm("unlisted",fileno(stdout),(int*)0);
printf("Done.\n");
}
but when I try to compile it I get fatal error: term.h : No such file or directory
What should I do? Where's the problem

On Ubuntu, download and install the libncurses5-dev:
sudo apt-get install libncurses5-dev
then compile:
gcc my_program.c -o my_program -lncurses

Related

Do I need to compile separately included header files from another direcotry?

I'm working on a project (hangman.c) and I want to include a module I wrote from another directory (quicksort.h). Here is the top of my hangman.c file:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "../quicksort/quicksort.h"
I've been running this command:
clang -o hangman hangman.c
And i get this error message:
/usr/bin/ld: /tmp/hangman-3292ab.o: in function `append_and_order':
hangman.c:(.text+0x26c): undefined reference to `quicksort'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I compile them separately and link them together manually with
gcc -c hangman.c
gcc -c ../quicksort/quicksort.c
gcc -o hangman hangman.o quicksort.o
(As corrected). And that works, but isn't the point of #include to do this automatically at the preprocessing stage?

gcc cannot compile C files using mpi.h

I just received a message where someone could not compile a C file.
When they try to compile, it's getting the following error.
$ gcc mpi01.c
mpi01.c:1:17: fatal error: mpi.h: No such file or directory
#include <mpi.h>
^
compilation terminated.
$
I'm sure the C code is present so it must be a problem with the installation, but mpi.h is there.
/opt/mpss/3.6/sysroots/k1om-mpss-linux/usr/src/kernel/drivers/message/fusion/lsi/mpi.h
/usr/include/openmpi-x86_64/mpi.h
/usr/src/kernels/3.10.0-229.20.1.el7.x86_64/include/linux/mpi.h
Does someone know what I could do?
The system is running Centos7.
Edit 1:
To respond to the answers. It is not my code that I am trying to compile. What I did to "ensure" everything is in place for C compiling:
yum install gcc openmpi kernel-devel kernel-headers openmpi-devel
I do not know if I am allowed to post the code, but the following headers are included in the code:
#include <mpi.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
The compiler command line was the following:
vim mpi01.c
module load mpi
gcc -o mpi01 mpi01.c
Resulting in the error above.

C code in Eclipse return undefined reference to symbol cvSaveImage

I'm using Eclipse and OpenCV (Version 3) on Ubuntu 15.10 to write a C program but I don't get why I'm always getting the error
undefined reference to symbol 'cvSaveImage'
If I run
pkg-config opencv --cflags --libs
I get
-I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib
-lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres
-lopencv_videostab -lopencv_calib3d -lopencv_features2d
-lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video
-lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann
-lopencv_core -lopencv_hal
So I added the LIbraries to the GCC C Liker as in the image below
If I don't try to use the function cvSaveImage the program runs, so the other libraries correctly work. I included the highgui library:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <stdbool.h>
#include <time.h>
Any idea?
cvSaveImage belongs to opencv_imgcodecs.
You are missing opencv_imgcodecs in the libraries (-l).

Linking R.h Rembedded.h with C code

I am including a few header files:
#include <gsl/gsl_machine.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_cdf.h>
#include <gsl/gsl_cblas.h>
#include <gsl/gsl_sf_gamma.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_blas.h>
#include <gsl/gsl_linalg.h>
#include <R.h>
#include <Rmath.h>
#include <Rembedded.h>
#include <Rdefines.h>
#include <R_ext/Lapack.h>
#include <R_ext/Linpack.h>
I am able to link the blas and gsl libraries using the following command (the -lm is for math?):
gcc -arch x86_64 myfile.c -o myfile -lgsl -lm -lgslcblas
But I get error:
myfile.c:21:15: error: R.h: No such file or directory
myfile.c:22:19: error: Rmath.h: No such file or directory
myfile.c:23:23: error: Rembedded.h: No such file or directory
myfile.c:24:22: error: Rdefines.h: No such file or directory
myfile.c:25:26: error: R_ext/Lapack.h: No such file or directory
myfile.c:26:27: error: R_ext/Linpack.h: No such file or directory
How do I link the header files when compiling my C code?
Header files aren't linked, only included. The errors mean just what they say: the compiler can't find them. Make sure they are in the standard include directory. Maybe you didn't make install the R library. If the header files are in the same directory as your other source files include them with double-quotes instead of angle brackets:
#include "R.h"
You can add other directories to the list of standard include directories with the -I flag to GCC.

getting undefined references from libssh2

I installed the libssh2 library on my Ubuntu linux. When compiling the C code I received this message:
undefined reference to `libssh2_session_init_ex'
I downloaded the libssh2 from their website. I followed the instructions of how to install it on my computer but It seems i am still missing soemthing.
This is my code in my make file:
all: ssh
ssh: mysshpass.c
gcc -lssh2 -g -o mysshpass mysshpass.c
clean:
rm -rf mysshpass
The include part of the C code:
1 #include <stdlib.h>
2 #include <libssh2.h>
3 #include <libssh2_sftp.h>
4
5 #include <sys/socket.h>
6 #include <netinet/in.h>
7 #include <arpa/inet.h>
8 #include <sys/types.h>
9 #include <stdio.h>
10 #include <string.h>
11
12 //#include <libssh2_config.h>
13
14 int main(int argc, char *argv[])
Thanks very much in advance
Note :
I used this new line :
all: ssh
ssh: mysshpass.c
gcc -g -Lusr/src/libssh2-1.4.1/include -o mysshpass mysshpass.c
clean:
rm -rf mysshpass
but still same compilations errors. By the way, I was told to install the libssh2-devel also, but i have no idea how to do that.
Thanks
1) Uninstall what you've got. There's something wrong, and it's being there can only confuse things. Get rid of it.
2) *install" libssh2-dev like this:
sudo apt-get install libssh2-dev libssh2
3) Try building your application again.
Make sure your makefile or build scripts point to the right place ("-I" for compile-time headers, "-L" for link-time libraries)
Good luck!
I think you want:
gcc -g \
-I /usr/src/libssh2-1.4.1/include \
-L /usr/src/libssh2-1.4.1/ \
-l ssh2 \
-o mysshpass mysshpass.c
You may put -lssh at the end.
Use:
gcc a.c -lssh

Resources