0

I am running into an issue building my program.

I installed openssl from git source using

./config
make
sudo make install

which created the directory in /usr/local/ssl, I then used in my Makefile:


all: amalgam clean

security.o: security.cpp
    g++ $< -I/usr/local/ssl/include -c -o $@ -L/usr/local/ssl/lib -lssl -lcrypto 

amalgam.o: amalgam.cpp
    g++ $< -c -o $@

amalgam: security.o amalgam.o
    g++ $^ -o $@

clean: 
    -rm *.o

What is odd is the build for security.o goes fine, but I get an issue when it tries to build the final program (amalgam).

g++ security.cpp -I/usr/local/ssl/include -c -o security.o -L/usr/local/ssl/lib -lssl -lcrypto 
g++ amalgam.cpp -c -o amalgam.o
g++ security.o amalgam.o -o amalgam
security.o: In function `amal_sec::genkey()':
security.cpp:(.text+0x2b): undefined reference to `EVP_PKEY_CTX_new_id'
collect2: error: ld returned 1 exit status
Makefile:11: recipe for target 'amalgam' failed
make: *** [amalgam] Error 1

amalgam.cpp

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <fstream>

#include "security.h"


using namespace std; 
int main (int argc, char ** argv){
    amal_sec new_sec;
    new_sec.genkey();

}

security.h

 #include <openssl/evp.h>
 #include <openssl/rsa.h>

class amal_sec
{   
    public:
        bool genkey();
}; 

and security.cpp


#include "security.h"

bool amal_sec::genkey(){ 
    printf("Generating a Key\n");

    EVP_PKEY_CTX *ctx;
    EVP_PKEY *pkey = NULL;

    ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL);
 }

Any help would be greatly appreciated!

Equinox
  • 15
  • 1
  • 6

1 Answers1

0

You're almost there. In the makefile the -L/usr/local/ssl/lib -lssl -lcrypto needs to be added to the linker command line in the amalgam rule to specify the additional libraries to be linked in, rather than the compiler command line for the security.o rule.

user4581301
  • 33,082
  • 7
  • 33
  • 54