Linking R.h Rembedded.h with C code - c

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.

Related

gcc tdm 10.3.0 get missing header files

I downloaded tdm gcc 10.3.0 and installed it succesfully. I have a file I want to compile yet it is missing header files. Is there a way to add components to tdm gcc from an interface, or do I download the files(headers) manually and add them to the project. If so, where do I add them in the project ? I know header files exist in C:\TDM-GCC-32\include
Also, just in case, I have these header files in my main.c,
#include <winsock2.h>
#include <Windows.h>
#include <ws2ipdef.h>
#include <ws2tcpip.h>
#include <iphlpapi.h>
#include <bcrypt.h>
#include <wincrypt.h>
#include <sysinfoapi.h>
#include <winternl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
as i tried to compile with gcc main.c, I got this error
main.c:8:10: fatal error: ws2ipdef.h: No such file or directory
8 | #include <ws2ipdef.h>
| ^~~~~~~~~~~~
compilation terminated.
How can I find this header file? If I just find it in github is it enough to add it to C:\TDM-GCC-32\include ?
another way to ask, how can I add ws2 to tdm gcc, or how to install tdm gcc alongwith?

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?

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).

C pre processor not processing header files includes in form #include <header.h>

C pre processor not processing header files includes in form #include . It gives error: No such file or directory. The files that are included in form #include "header.h" are pre processed properly. How do solve this. I am using command:
cpp -P -I.PWD file.c
#include "filename" is different from #include <filename>.
See (What is the difference between #include <filename> and #include "filename"?). `
Gist: #include <filename> does NOT search in ..

term.h : header not found

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

Resources