Openssl compile error - c

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

Related

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 ?

How to fix error message "Undefined symbols for architecture x86_64:" in C?

I'm currently getting the error:
Undefined symbols for architecture x86_64:
"_makeContext", referenced from:
_main in myThread-68b6d3.o
ld: symbol(s) not found for architecture x86_64
This error only occurs when I use the function makeContext or swapContext from ucontext.h
Here's what the head of my code looks like:
#define _XOPEN_SOURCE 600
#include <unistd.h>
#include <ucontext.h>
//#include <sys/ucontext.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
I'm in terminal and I'm using this to compile:
gcc -w myThread.c -o myThread
My code will compile if I comment out all makeContext and swapContext functions. It works fine for the other function in like getContext and setContext.
Any idea on how to remove this error?

Getting error while running opencv code in 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`

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

Resources