Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Cloud_Strife_Han on March 20, 2019, 11:27:45 am

Title: [OpenSSL] - ld returned 1 exit status
Post by: Cloud_Strife_Han 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!
Title: Re: [OpenSSL] - ld returned 1 exit status
Post by: Miguel Gimenez 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.
Title: Re: [OpenSSL] - ld returned 1 exit status
Post by: stahta01 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.