Importing CUnit sources - c

i'm having a problem to use Unit test in C, i've tried to install CUnit in my computer and after include the lib.
i've followed steeps to install the CUnit:
1 - download the sources
2 - configure it using "./configure --prefix='/lib' "
3 - make (only make)
4 - sudo make install
and this is my test source file, it's not making tests, but i can't compile this, i got this error before "CUnit.h: No such file or directory":
#include "CUnit.h"
#include <stdlib.h>
#include <stdio.h>
int main(){
print("Hello");
return 0;
}
I want to know, how can i install CUnit to use in my test source files!
Thanks in advance.
EDIT
HAHA, i got this!
i just run configure without parameters, like that:
"./configure"

As shown in the code example you should use something like this :
#include <CUnit/CUnit.h>
because every CUnit includes are located in a CUnit subdirectory (in general in /usr/local/include/CUnit)

What about adding -I/lib/include flag to include header files installed in /lib/include/CUnit and -lcunit -L/lib/CUnit/lib for linking with the installed libraries?
gcc test_file_source.c -I/lib/include -lcunit -L/lib/CUnit/lib -o testing

Related

Is there any way that I can include my own function file under any file? [duplicate]

I have the following code in a sample file:
#include "SkCanvas.h"
#include "SkDevice.h"
#include "SkGLCanvas.h"
#include "SkGraphics.h"
#include "SkImageEncoder.h"
#include "SkPaint.h"
#include "SkPicture.h"
#include "SkStream.h"
#include "SkWindow.h"
However, this code is located in various folders within /home/me/development/skia (which includes core/ animator/ images/ ports/ svg/ and a lot more.)
How can I make GCC recognize this path?
Try gcc -c -I/home/me/development/skia sample.c.
The -I directive does the job:
gcc -Icore -Ianimator -Iimages -Ianother_dir -Iyet_another_dir my_file.c
Using environment variable is sometimes more convenient when you do not control the build scripts / process.
For C includes use C_INCLUDE_PATH.
For C++ includes use CPLUS_INCLUDE_PATH.
See this link for other gcc environment variables.
Example usage in MacOS / Linux
# `pip install` will automatically run `gcc` using parameters
# specified in the `asyncpg` package (that I do not control)
C_INCLUDE_PATH=/home/scott/.pyenv/versions/3.7.9/include/python3.7m pip install asyncpg
Example usage in Windows
set C_INCLUDE_PATH="C:\Users\Scott\.pyenv\versions\3.7.9\include\python3.7m"
pip install asyncpg
# clear the environment variable so it doesn't affect other builds
set C_INCLUDE_PATH=

fatal error: editline/readline.h: No such file or directory compilation terminated

Fatal Error
I am working on makeyourownlisp,where in editline/readline.h and
editline/history.h have to be added to the program.
Following is the code snippet
#include<stdio.h>
#include<stdlib.h>
#include<editline/readline.h>
#include<editline/history.h>
static char input[2048];
int main(int argc, char** argv)
{
printf("CLISP version 1.02\n");
printf("Ctrl + c to exit\n");
while(1)
{
char * input = readline(">>> \n");
add_history(input);
printf("%s", input);
free(input);
}
}
I have already installed libedit-20170329-3.1(containing the above mentioned header files) but how to use the files and get the code rolling is something I need help about.
On Debian Buster 10, I had to install the package with:
sudo apt install libeditline-dev
Instead of:
#include <editline/readline.h>
#include <editline/history.h>
I just included:
#include <editline.h>
ran the program with -leditline flag and worked perfectly.
Note that I was executing the portable program for both Windows and UNIX systems. Following the tutorial, that piece of my code would look like:
// otherwise include the editline headers
#else
#include <editline.h>
#endif
Hope that helped. Awesome tutorial btw.
I faced this issue in the ubuntu 18.04 version, installing the following packages worked for me
sudo apt install libeditline-dev
sudo apt-get install libedit-dev
I refer to the following thread Readline-Issue
An answer from future.
I am also working on same tutorial. And I also get stuck at that point. Then removing #include<editline/history.h> solved my issue.
Thanks to that thread https://github.com/fabianishere/brainfuck/issues/57
P.S. I am using Archlinux
to install editline header file use,
sudo apt-get install libedit-dev
or for fedora use,
su -c "yum install libedit-dev*"
then proceed to add the header files like this
#include <stdio.h>
#include <stdlib.h>
#include <editline/readline.h>
#include <editline/history.h>
use them as the Header files and then use the History and readline command as usual as given in the tutorial.
Then when compiling use (assuming your file name is "prompt.c" and the output compiled file is "PromptOutput"
gcc prompt.c -ledit -o PromptOutput
instead of
gcc prompt.c -o PromptOutput
this is because we haven't previously linked the program to "editline".
I am using Ubuntu 20.X.
for Arch, use
histedit.h
I hope that clears the query

C: How to include the squash compression library?

I'm fairly new to programming with c and i am having a hard time including the squash library into my program.
I cloned the repository and ran ./configure and make sudo make install.
That installed the files:
/usr/local/lib/pkgconfig/squash-0.8.pc
/usr/local/lib/libsquash0.8.so.0.8
/usr/local/lib/libsquash0.8.so.0.8.0
/usr/local/lib/libsquash0.8.so
/usr/local/lib/cmake/Squash-0.8.0/SquashConfig.cmake
/usr/local/bin/squash
And some more files in this directories:
/usr/local/include/squash-0.8/
/usr/local/lib/squash/0.8/plugins/
In the squash examples the library is included by #include <squash/squash.h> but when i am trying to compile it i get fatal error: squash/squash.h: No such file or directory
Also #include <squash-0.8/squash.h> doesnt work because then i get fatal error: hedley/hedley.h: No such file or directory That file is located at
/usr/local/include/squash-0.8/squash/hedley/hedley.h
I guess the solution is pretty simple for an experienced c programmer but i am failing here..
Do i need to set some sort of environment variable to let the compiler find the library?
And how do i link the library to the compiler anyway?
I found something like:
-rdynamic ../squash/libsquash0.8.so.0.8 but could not test it yet because of the error above.
Try to change
#include <squash/squash.h>
to
#include "squash/hedley/hedley.h"
or
#include "<squash-0.8/squash/hedley/hedley.h>"
easier and faster solution would be adding the path to your includes during compilation:
-I/usr/local/include/squash-0.8/squash/

How to include libssh to my project

I've installed libssh following the instructions and even though everything seems to be OK my compiler still returns the error "file not found" in the line "#include ". I guess it has something to do with directories or links (I have "make install" in the same folder where I downloaded it) but I don't know where should I put it so I can #include it in any project.
This is how I installed it:
I downloaded it and unzip it into the folder "libssh" on my Desktop (Mac).
Then I did
cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug ..
make
and finally:
sudo make install
Then in my program I have:
#include <libssh/sftp.h>
And XCode returns: "libssh/sftp.h file not found". I tried adding the libssh folder in the Desktop to the project, but I still have similar problems.
I guess I should install it (somehow) to the /usr/include folder, so that any project can use it (like pthread or many others), but I don't know how to do this.
If I include any other file in /usr/include it works fine (like ) but when I #include it returns file not found, even though if I cd to /usr/include/libssh the file libssh.h does exist.
This is the very simple sample code:
#include <stdio.h>
#include <pthread.h> //OK
#include <libssh/libssh.h> //Not OK, file not found.
int main(int argc, const char * argv[])
{
printf("Hello World!");
return 0;
}
In the tutorial is described how you have to link the library
You have two possibilities here:
As described you have to add those two lines to your code
#define LIBSSH_STATIC 1
#include <libssh/libssh.h>
You compile your code with the LIBSSH_STATIC flag.
gcc -DLIBSSH_STATIC test.c -o test.o
I thought that if you have the library in /usr/include the compiler will automatically link it. For instance, the pthread.h file is included properly without doing anything.
This is a system library which gets linked automatically most of the time. libssh is not. Thats why you have to be more specific on how to compile/link it.
Ive had a very similar problem several times and I have solved it by removing the ≤ ≥ symbols from around my header files and using ""s and the absolute path to the header file you're including. Now this doesn't solve your libssh install problems but it will allow you to compile just the way you have it as long as you know the absolute path of your header file and all of your header's dependencies are in the respective locations that they were inteded to look for them in. Hope this helps.

FFMpeg sample program

I am currently learning ffmpeg tutorial of Martin Bohme Tutorial Here
and I want to compile an ffmpeg sample program using Code Block IDE but, it can't
#include <stdio.h>
#include <stdlib.h>
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
int main(int argc, char *argv[])
{
av_register_all();
return 0;
}
Please help me. How to compile it. I am using Linux (Ubuntu)
You have to tell the compiler where the header and library files are. This is done by the -I flag to tell which directories contain header files, and -L to tell which directories contains libraries. You will also need -l to tell which libraries to link with.
The flags can be used like this:
$ g++ -I/path/to/headers myprogram.cpp -L/path/to/libraries -lthelibrary
A note about libraries: On Linux (and UNIX systems) they are files with names that start with "lib" and end with the extension ".a" or ".so". When specifying the library with the -l flag you do not write those. So for a library file "libfoo.a", you only use -lfoo to link with it.
For more information about the options of gcc and g++, see http://gcc.gnu.org/onlinedocs/gcc/Invoking-GCC.html.
Edit: For an IDE like Code::Blocks there most likely is some project setting where you can add include and library directories and link libraries. Check the "Project" menu for a "Settings" or "Properties" alternative.
Edit2: See for example this FAQ where to find linker settings in Code::Blocks, the pre-processor settings should be close by.
you can try following command to compile in Linux.
gss <program-name.c>
For IDE like eclipse follow FFMPEG - Eclipse Setup Guide[Linux] official

Resources