0

I am using Bloodshed DevC++ in windows 7. I installed the OpenSSL library package using the package installation feature in DEV.

I started with a simple C code to find the SHA. I am sure that the libraries are connecting correctly. But for some odd reason I am getting a linker error i.e. [linker error] Undefined reference to 'SHA1'

I have seen other sites including SOF but I am unable to figure out the source of the problem. I have seen various posts on SOF that address this issue but non of the comments address the problem I encounter. Any assistance will be highly appreciated. I have seen some people say that you need to use -lcrypto but I am confused what they are referring to.

[EDIT]

I give the code as follows:

#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <openssl/sha.h>

int main ()
{
 unsigned char ibuf[] = "compute sha1";  
 unsigned char obuf[20];  
 SHA1(ibuf,strlen(ibuf),obuf); 
 int i=0;  
 for (i = 0; i < 20; i++)  
 {  
   printf("%02x ", obuf[i]);  
 }  
 printf("\n");  
 getch();  
}   
  • 1
    You should post more information about the error encountered : edit your post and give the failed compilation log – Benjamin Debotté Nov 04 '15 at 10:06
  • *I have seen some people say that you need to use -lcrypto but I am confused what they are referring to* <- this is the solution to your problem – el.pescado - нет войне Nov 04 '15 at 10:07
  • 1
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Emil Laine Nov 04 '15 at 10:23
  • I might sound silly but I dont know what -lcrypto is and how I am supposed to use it. I thought maybe this is a header file but no. What do you suggest. – The Nutty Professor Nov 04 '15 at 10:25
  • You need to add a compilation flag to tell your compiler "Hey man, you need 'crypto' to build my program". This is done by adding -lcrypto. You should read some documentation about how a C program works and how it is compiled – Benjamin Debotté Nov 04 '15 at 10:31
  • Zenith I went through your refereed post but could not locate a possible solution in the added link – The Nutty Professor Nov 04 '15 at 10:45
  • Ben: could you please elaborate briefly: "you need crypto". The other problem is that I think it is not possible to add compilation flags in DevC++. correct me if I am wrong. – The Nutty Professor Nov 04 '15 at 11:34
  • "I think it is not possible to add compilation flags in DevC++. correct me if I am wrong.". I'm correcting you. You are wrong. – n. m. could be an AI Nov 04 '15 at 11:49

2 Answers2

0

in your project options, in the Parameters tab you have three boxes for options, one specifies C compiler, the second specifies C++ Compiler the third specifies Linker.

In the Linker box you need to add -lcrypto and rebuild your project.

This is specific to the Dev-C++ development environment, but duplicates what people are telling you in the comments.

I presume you're using the Dev-C++ v5.11 version as the last one available on the bloodshed website is a beta and doesn't work on my system, which is Win 10.

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
  • I followed your exact step. Now I am getting the error "cannot find -lcrypto" – The Nutty Professor Nov 04 '15 at 13:17
  • Is the error just `cannot find -lcrypto` or are there some `skipping incompatible ...` messages before it? If it's just missing, then you need to add the path to the library in the `Library Directories` option of the `Directories` tab of the project properties. On my system this directory is `C:\Program Files (x86)\Dev-cpp\lib`, it may be different for you. If the error is about incompatible libraries, then it's likely that you're compiling in 64bit, while the dev package is 32bit. If that's the case, then you can choose to compile in 32bit, or find/obtain a 64bit copy of the devpack – Anya Shenanigans Nov 04 '15 at 13:44
0

Thanks to all those who have contributed and assisted in solving the problem. Special thanks to Prof Petesh ;) without whos help I would have wasted another week.

I will provide the details as follows:

  • First of all download the latest DEVC++ preferably 5.11. Make sure you use the correct 32/64 bit version of the compiler otherwise you will encounter linking/ build errors.

  • -lcrypto and other libraries need to be added to the project by going to project options->Parameters-> Linker. The files can be added by
    using the add library or object button.

  • Ensure that the include directory holds the link to the openssl
    folder. In my system the path was "C:\Program Files
    (x86)\Dev-Cpp\include"