Why gcc give me math.wrap error with OPENCV 3.4 - c

Hi i need to convert an image to b&w with C.
I'm on MXLinux.
And my idea is to use opencv api. I search on web and i found this way to gain b&w foto.
The problem is only when i try to compile it with gcc. It can't found the library opencv, how i can link (permanently not only local) this library?
#include <string.h>
#include <cv.h>
#include <highgui.h>
int main(int argc, char** argv){
//read and convert to greyscale
IplImage* im_rgb = cvLoadImage("home.jpg");
IplImage* im_gray = cvCreateImage(cvGetSize(im_rgb),IPL_DEPTH_8U,1);
cvCvtColor(im_rgb,im_gray,CV_RGB2GRAY);
//to black and white
IplImage* im_bw = cvCreateImage(cvGetSize(im_gray),IPL_DEPTH_8U,1);
cvThreshold(im_gray,im_bw,128,255,CV_THRESH_BINARY | CV_THRESH_OTSU);
//save the image
cvSaveImage("image_bw.png",im_bw);
cvSaveImage("image_grey.png",im_gray);
}
The other question is, why doesn't gcc see automatically the library ? After the installation i see the /usr/local/bin and the library are on it!
-----UPDATE1----- 25-02-2021 -----
Yes, after OpenCV 3.x library C seems doesn't exist or maybe doesn't work.
Problem solved by install OpenCV 3.4.3.
Compile in this way:
gcc NameFile.cpp -o NameFile $ ( pkg-config --cflags --libs opencv )
I obtain an error (i think is caused by cvSaveImage) :
what(): OpenCV(3.4.3) /home/pi/opencv-3.4.3/modules/core/src/matrix_wrap.cpp: 800: error: (-215:Assertion failed) (flags & FIXED_TYPE) != 0 in function 'type'
--SOLVED--
I solved all problem by installing an other version of OpenCV, via web i found that the 3.4.3 version has a bug with matrix_wrap i really don't understand very well the problem but with a clean installation of opencv 3.0.0 all works fine.
I get only few error on cmake and make but all are easy to resolve by web.
Thanks to all.

Related

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

Correct command line parameters for gcc compilation of SDL

I recently started SDL2.0 programming.
I did a lot of researches and i tried all but i still get those "undefined reference" errors for all the SDL functions:
undefined reference to `SDL_Init'|
undefined reference to `SDL_GetError'|
undefined reference to `SDL_Quit'|
||=== Build finished: 3 errors, 0 warnings ===|
on that simple test program:
#include <stdlib.h>
#include <stdio.h>
#include "SDL.h"
int main(int argc, char* argv[])
{
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0) {
fprintf(stderr, "\nUnable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
atexit(SDL_Quit);
return 0;
}
If i have to guess the problem occurs due to the wrong command line syntax.
In this case what should be the correct one?
You aren't linking to the SDL libraries correctly.
Add the following lines int Other Linker Option
-lSDL -lSDLmain
mingw32
SDLmain
SDL
Also You need to check setup for how to compile SDL in codeblock
http://wiki.codeblocks.org/index.php?title=Using_SDL_with_Code::Blocks
http://lazyfoo.net/SDL_tutorials/lesson01/windows/codeblocks/
If it's not too late then try from the beginging to how to set up SDL in codeblock and successfully run it? Below link provide you exact steps for it.
http://www.dreamincode.net/forums/topic/57275-setting-up-codeblocks-to-work-with-sdl/
You might have not linked SDL2 correctly to your CodeBlocks project and not referred to SDL2 correctly in your code.
1:
Go to "Linker options" in "Build Options" menu and make sure you have added these library's to your project like this:
Library's to include in linker options
Importent!: save project before running it after adding/changeing library's.
2:
Change:
#include "SDL.h"
to this:
#include <SDL2/SDL.h>
if you still encounter problems compiling and running it, it's most likely either, your SDL2 files not placed correctly in the compiler's folders, or your using an version of gcc with some missing tools.
These Youtube video's explain everything in great detail:
1: https://www.youtube.com/watch?v=x0LUf7Ibpi0
2: https://www.youtube.com/watch?v=EtUw_7CvRRo

Including a static library in a C project (Eclipse)

I'm currently developing an application using SDL. In order to utilize it, I have already added the library and header files in the project's settings under C/C++ Build -> Settings -> Tool Settings -> Libraries/Includes. However, when I try to build a test program like
#include <stdio.h>
#include <SDL/SDL.h>
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Quit();
return 0;
}
I get this beautiful error message during the link process:
d:/programme/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../libmingw32.a(main.o): In function main':
C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference toWinMain#16'
Which is rather weird, given that the directory C:\MinGW doesn't even exist at all.
The command used for linking is this one:
gcc "-LD:\Programme\SDL\lib" -o test.exe test.o -lsdl
After two hours of trying to get a library link to work, I'm pretty confused and have no idea what I'm doing wrong. Help would be appreciated.
It looks like you are building a Windows GUI application, which requires a WinMain, while your code only provides a main function which would be for console applications.
So if this is supposed to be a console application, you must adjust your linker settings accordingly, or you must declare a WinMain.

Importing CUnit sources

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

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