Getting error while running opencv code in C - c

I am having a opencv code in C:
#ifdef _CH_
#pragma package <opencv>
#endif
#ifndef _EiC
// motion templates sample code
#include "cv.h"
#include "highgui.h"
#include <time.h>
#include <math.h>
#include <ctype.h>
#include <stdio.h>
#endif
with these header files.
if I run it using
gcc `pkg-config --cflags --libs opencv` motempl_temp.c -o opencv
I get error:
/tmp/cc2rKXbX.o: In function `cvDecRefData':
motempl_temp.c:(.text+0xac2): undefined reference to `cvFree_'
motempl_temp.c:(.text+0xb4b): undefined reference to `cvFree_'
/tmp/cc2rKXbX.o: In function `cvGetRow':
motempl_temp.c:(.text+0xc63): undefined reference to `cvGetRows'
/tmp/cc2rKXbX.o: In function `cvGetCol':
motempl_temp.c:(.text+0xc91): undefined reference to `cvGetCols'
/tmp/cc2rKXbX.o: In function `cvReleaseMatND':
motempl_temp.c:(.text+0xcab): undefined reference to `cvReleaseMat'
/tmp/cc2rKXbX.o: In function `cvSubS':
motempl_temp.c:(.text+0xe08): undefined reference to `cvAddS'
/tmp/cc2rKXbX.o: In function `cvCloneSeq':
motempl_temp.c:(.text+0xe5a): undefined reference to `cvSeqSlice'
/tmp/cc2rKXbX.o: In function `cvSetNew':
motempl_temp.c:(.text+0xed6): undefined reference to `cvSetAdd'
/tmp/cc2rKXbX.o: In function `cvGetSetElem':
motempl_temp.c:(.text+0xf93): undefined reference to `cvGetSeqElem'
/tmp/cc2rKXbX.o: In function `cvEllipseBox':
motempl_temp.c:(.text+0x1062): undefined reference to `cvEllipse'
/tmp/cc2rKXbX.o: In function `cvFont':
motempl_temp.c:(.text+0x10ce): undefined reference to `cvInitFont'
/tmp/cc2rKXbX.o: In function `cvReadIntByName':
motempl_temp.c:(.text+0x11d8): undefined reference to
`cvGetFileNodeByName'
/tmp/cc2rKXbX.o: In function `cvReadRealByName':
motempl_temp.c:(.text+0x1277): undefined reference to
`cvGetFileNodeByName'
/tmp/cc2rKXbX.o: In function `cvReadStringByName':
motempl_temp.c:(.text+0x1306): undefined reference to
`cvGetFileNodeByName'
/tmp/cc2rKXbX.o: In function `cvReadByName':
motempl_temp.c:(.text+0x1349): undefined reference to
`cvGetFileNodeByName'
collect2: error: ld returned 1 exit status
All the header files are in the path /usr/local/include/opencv folder and this is included in the path variable.

The OpenCV C API is deprecated. You should use the C++ API.
You can compile your code with g++:
g++ motempl_temp.c -o opencv `pkg-config opencv --cflags --libs`

Related

Undefined references when building GLFW/OpenGL program?

I am trying to use C, MINGW and GLFW to create a program and I keep on getting this error when compiling.
cc1.exe: warning: unrecognized gcc debugging option: y
cc1.exe: warning: unrecognized gcc debugging option: n
cc1.exe: warning: unrecognized gcc debugging option: m
cc1.exe: warning: unrecognized gcc debugging option: i
cc1.exe: warning: unrecognized gcc debugging option: c
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x127): undefined reference to `CreateDCW#16'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x160): undefined reference to `GetDeviceCaps#8'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x179): undefined reference to `GetDeviceCaps#8'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x1ca): undefined reference to `GetDeviceCaps#8'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x24b): undefined reference to `GetDeviceCaps#8'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x291): undefined reference to `DeleteDC#4'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x9ee): undefined reference to `GetDeviceCaps#8'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xa07): undefined reference to `GetDeviceCaps#8'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xe9f): undefined reference to `CreateDCW#16'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xeba): undefined reference to `GetDeviceGammaRamp#8'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xec8): undefined reference to `DeleteDC#4'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x100e): undefined reference to `CreateDCW#16'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x1029): undefined reference to `SetDeviceGammaRamp#8'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x1037): undefined reference to `DeleteDC#4'
./libs/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x1f3): undefined reference to `CreateDIBSection#24'
./libs/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x262): undefined reference to `CreateBitmap#20'
./libs/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x28d): undefined reference to `DeleteObject#4'
./libs/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x37b): undefined reference to `DeleteObject#4'
./libs/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x389): undefined reference to `DeleteObject#4'
./libs/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0xb55): undefined reference to `CreateRectRgn#16'
./libs/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0xc2c): undefined reference to `DeleteObject#4'
./libs/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x6c4): undefined reference to `DescribePixelFormat#16'
./libs/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xbbd): undefined reference to `DescribePixelFormat#16'
./libs/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xf46): undefined reference to `SwapBuffers#4'
./libs/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x1254): undefined reference to `ChoosePixelFormat#8'
./libs/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x126f): undefined reference to `SetPixelFormat#12'
./libs/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x1592): undefined reference to `DescribePixelFormat#16'
./libs/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x15d9): undefined reference to `SetPixelFormat#12'
collect2.exe: error: ld returned 1 exit status
This is my code
#include "GLFW/glfw3.h"
#include <stdio.h>
#define GLFW_INCLUDE_GLCOREARB
int main() {
GLFWwindow* window;
if (!glfwInit()) return -1;
window = glfwCreateWindow(640, 480, "Test", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window))
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
So its basically just the given example on glfw website.
I use this command to build:
gcc -o Test.o Main.c -IGLFW -IGL -dynamic ./libs/glfw3.dll ./libs/glew32.dll -lopengl32 -static ./libs/libglfw3.a ./libs/glew32.lib ./libs/glew32s.lib
I dont have any issues with compiling the glfw but I have problems with GLEW, maybe it is because it is lib files instead of a.

Using SDL(Simple DirectMedia Layer) Libraries in Ubuntu

i'm trying to include all SDL libraries that i have already installed and exist in '/usr/include/SDL' this directory contains all .h files
#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>
int main ()
{
SDL_Surface *screen=NULL ;
SDL_Init (SDL_INIT_VIDEO);
if (SDL_Init(SDL_INIT_VIDEO !=0))
{
printf("erreur");
return 1 ;
}
screen=SDL_SetVideoMode (400,400,32,SDL_HWSURFACE | SDL_DOUBLEBUF);
if (screen== NULL)
{
printf("Unable to set video mode : %s \n",SDL_GetError() );
return 1;
}
SDL_Flip (screen);
SDL_Quit ();
return 0;
}
when i compile code above that exists in main.c in terminal using this command:
gcc main.c -o program -LSDL
i get this :
axemaster#ubuntu:~/Desktop/stackoverflow$ gcc main.c -o program -LSDL
/tmp/ccMx1per.o: In function `main':
main.c:(.text+0x16): undefined reference to `SDL_Init'
main.c:(.text+0x20): undefined reference to `SDL_Init'
main.c:(.text+0x53): undefined reference to `SDL_SetVideoMode'
main.c:(.text+0x63): undefined reference to `SDL_GetError'
main.c:(.text+0x88): undefined reference to `SDL_Flip'
main.c:(.text+0x8d): undefined reference to `SDL_Quit'
collect2: error: ld returned 1 exit status
How can i solve this ?

Getting undefined reference errors in c compiling via gcc

Already fixed it thx
I got 5 files:
cdouble.c cdouble.h cmatrix.c cmatrix.h and main.c
in my cdouble.c I have:
#include "cdouble.h"
in my cmatrix.c I have:
#include "cmatrix.h"
(in my cmatrix.h file i got: #include "cdouble.h"
And in my main file I have:
#include "cmatrix.h"
I need to compile it on my university's unix(?) server.
I tried:
gcc -c cmatrix.c
gcc cmatrix.o main.c
but I got many "undefined reference errors"
$ gcc -c cmatrix.c
gcc cmatrix.o main.c:
/tmp/ccZD6esL.o: In function ishermitian:
main.c:(.text+0x7b): undefined reference to cConj
main.c:(.text+0x8b): undefined reference to getCDoubleImag
main.c:(.text+0xa0): undefined reference to getCDoubleReal
main.c:(.text+0xde): undefined reference to getCDoubleImag
main.c:(.text+0xef): undefined reference to getCDoubleImag
main.c:(.text+0x111): undefined reference to getCDoubleReal
main.c:(.text+0x122): undefined reference to getCDoubleReal
/tmp/ccZD6esL.o: In function scancdouble:
main.c:(.text+0x203): undefined reference to newCDouble
/tmp/ccZD6esL.o: In function main:
main.c:(.text+0x2d8): undefined reference to getCDoubleImag
main.c:(.text+0x2fc): undefined reference to getCDoubleReal
collect2: error: ld returned 1 exit status
You need to compile cdouble.c and link its .o file as well. E.g:
gcc -c cmatrix.c
gcc -c cdouble.c
gcc main.c cmatrix.o cdouble.o
or, more simply:
gcc main.c cmatrix.c cdouble.c

Compile Open SSL Dependent C Program with GCC

I have to compile a C program on linux(ubuntu) with gcc. Which is dependent to openssl libraries.
#include <openssl/crypto.h>
#include <openssl/pem.h>
#include <openssl/err.h>
#include <openssl/bio.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <openssl/err.h>
I've downloaded libcrypto and libopenssl package from repository. But still I'm getting this error
root#kali:~/openssl# gcc opensslhello.c
/tmp/ccTahV7g.o: In function `pem2X509':
opensslhello.c:(.text+0x15): undefined reference to `BIO_s_mem'
opensslhello.c:(.text+0x1d): undefined reference to `BIO_new'
opensslhello.c:(.text+0x4e): undefined reference to `BIO_write'
opensslhello.c:(.text+0x71): undefined reference to `PEM_read_bio_X509'
opensslhello.c:(.text+0x7f): undefined reference to `BIO_free'
/tmp/ccTahV7g.o: In function `sendHelloFunction':
opensslhello.c:(.text+0xb9): undefined reference to `X509_STORE_new'
opensslhello.c:(.text+0xe2): undefined reference to `X509_STORE_add_cert'
opensslhello.c:(.text+0x106): undefined reference to `X509_STORE_add_cert'
opensslhello.c:(.text+0x113): undefined reference to `sk_new_null'
opensslhello.c:(.text+0x13c): undefined reference to `sk_push'
opensslhello.c:(.text+0x160): undefined reference to `sk_push'
opensslhello.c:(.text+0x187): undefined reference to `X509_STORE_CTX_new'
opensslhello.c:(.text+0x1b0): undefined reference to `X509_STORE_CTX_init'
opensslhello.c:(.text+0x1bf): undefined reference to `X509_verify_cert'
opensslhello.c:(.text+0x1d3): undefined reference to `X509_STORE_CTX_get_error'
opensslhello.c:(.text+0x1e3): undefined reference to `X509_STORE_CTX_get_error'
opensslhello.c:(.text+0x215): undefined reference to `X509_STORE_CTX_free'
opensslhello.c:(.text+0x220): undefined reference to `X509_free'
opensslhello.c:(.text+0x22b): undefined reference to `BIO_free'
opensslhello.c:(.text+0x233): undefined reference to `X509_free'
opensslhello.c:(.text+0x23e): undefined reference to `sk_pop_free'
opensslhello.c:(.text+0x249): undefined reference to `X509_STORE_free'
/tmp/ccTahV7g.o: In function `main':
opensslhello.c:(.text+0x291): undefined reference to `EVP_cleanup'
opensslhello.c:(.text+0x29d): undefined reference to `ERR_remove_state'
opensslhello.c:(.text+0x2a2): undefined reference to `ERR_free_strings'
collect2: error: ld returned 1 exit status
root#kali:~/openssl#
Can anyone please tell me what I should do to, get rid of this error.?
Thanks,
You haven't linked the crypto and openssl libraries:
gcc opensslhello.c -lssl -lcrypto

Openssl compile error

I have included the following header files in a C code using openssl libraries.
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#ifdef __VMS
#include <in.h>
#include <inet.h>
#else
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
#include <openssl/crypto.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
Then I compiled the program using gcc -o openssl -lssl -lcrypt openssl.c
In my office this code compiled and run fine but in my house system(both are linux- debian 6 in office and Ubuntu 12.04 at home), it gave the following error:
/tmp/ccZcmLk4.o: In function `main':
server.c:(.text+0x3d): undefined reference to `SSL_library_init'
server.c:(.text+0x42): undefined reference to `SSL_load_error_strings'
server.c:(.text+0x47): undefined reference to `SSLv3_method'
server.c:(.text+0x57): undefined reference to `SSL_CTX_new'
server.c:(.text+0x6f): undefined reference to `ERR_print_errors_fp'
server.c:(.text+0x97): undefined reference to `SSL_CTX_use_certificate_file'
server.c:(.text+0xa8): undefined reference to `ERR_print_errors_fp'
server.c:(.text+0xd0): undefined reference to `SSL_CTX_use_PrivateKey_file'
server.c:(.text+0xe1): undefined reference to `ERR_print_errors_fp'
server.c:(.text+0xf9): undefined reference to `SSL_CTX_check_private_key'
server.c:(.text+0x154): undefined reference to `SSL_CTX_load_verify_locations'
server.c:(.text+0x165): undefined reference to `ERR_print_errors_fp'
server.c:(.text+0x18d): undefined reference to `SSL_CTX_set_verify'
server.c:(.text+0x1a1): undefined reference to `SSL_CTX_set_verify_depth'
server.c:(.text+0x397): undefined reference to `SSL_new'
server.c:(.text+0x3c2): undefined reference to `SSL_set_fd'
server.c:(.text+0x3ce): undefined reference to `SSL_accept'
server.c:(.text+0x3e6): undefined reference to `ERR_print_errors_fp'
server.c:(.text+0x3fe): undefined reference to `SSL_get_current_cipher'
server.c:(.text+0x406): undefined reference to `SSL_CIPHER_get_name'
server.c:(.text+0x42e): undefined reference to `SSL_get_peer_certificate'
server.c:(.text+0x455): undefined reference to `X509_get_subject_name'
server.c:(.text+0x46d): undefined reference to `X509_NAME_oneline'
server.c:(.text+0x4b1): undefined reference to `X509_get_issuer_name'
server.c:(.text+0x4c9): undefined reference to `X509_NAME_oneline'
server.c:(.text+0x50d): undefined reference to `X509_free'
server.c:(.text+0x593): undefined reference to `SSL_write'
server.c:(.text+0x5ab): undefined reference to `ERR_print_errors_fp'
server.c:(.text+0x5d3): undefined reference to `SSL_read'
server.c:(.text+0x5eb): undefined reference to `ERR_print_errors_fp'
collect2: ld returned 1 exit status
I understand that this is due to the absence of certain libraries in my home PC. But can anyone tell me which libraries I need to install for this? Thanks in advance.
Put the libraries after the source file:
gcc -o openssl openssl.c -lssl -lcrypto
See: http://www.network-theory.co.uk/docs/gccintro/gccintro_18.html
put the file name before -l option

Resources