Author Topic: [OpenSSL] - ld returned 1 exit status  (Read 6211 times)

Offline Cloud_Strife_Han

  • Single posting newcomer
  • *
  • Posts: 8
[OpenSSL] - ld returned 1 exit status
« on: March 20, 2019, 11:27:45 am »
Dear there,
I am testing a snippet to compute hash of file using openssl.
My snippet below:
Code
#include <openssl/sha.h>
#include <stdio.h>

int main()
{
  const unsigned char str[] = "Original String";
  unsigned char hash[SHA_DIGEST_LENGTH]; // == 20

  SHA1(str, sizeof(str)-1, hash);

//  puts(hash);

  return 0;
}


I added lib of openssl but when compiling I got this message in build log.
Quote

-------------- Clean: Debug in ComputeHash (compiler: GNU GCC Compiler)---------------

Cleaned "ComputeHash - Debug"

-------------- Build: Debug in ComputeHash (compiler: GNU GCC Compiler)---------------

g++.exe -Wall -g -IC:\Users\%username%\Documents\CodeBlock\ComputeHash\ -c C:\Users\%username%\Documents\CodeBlock\ComputeHash\HashComputing.cpp -o obj\Debug\HashComputing.o
g++.exe  -o bin\Debug\ComputeHash.exe obj\Debug\HashComputing.o  -static  lib\libcrypto.lib
lib\libcrypto.lib: error adding symbols: File in wrong format
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))


I use Code::Blocks 17.12 recv 11256. Openssl 1.1.1b
How can I fix this? Any idea?

Thanks!

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1564
Re: [OpenSSL] - ld returned 1 exit status
« Reply #1 on: March 20, 2019, 12:52:41 pm »
libcrypto must be compiled with g++, and probably it will be called libcrypto.a instead of libcrypto.lib.
In general you can't mix objects from two different compilers.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: [OpenSSL] - ld returned 1 exit status
« Reply #2 on: March 20, 2019, 04:16:41 pm »
libcrypto must be compiled with g++, and probably it will be called libcrypto.a instead of libcrypto.lib.
In general you can't mix objects from two different compilers.

To be more specific (the compiler version matters sometimes); you can most of the times use C compiled library and you can almost never use C++ compiled libraries with different compilers.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org