Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

OpenSSL is able to access other BIO functions but not BIO_hex_string

I'm trying to do some debugging with BIO_hex_string but when I call it I get the following error:

Undefined symbols for architecture x86_64:
  "_BIO_hex_string", referenced from:
      _log_bytes in main.o
ld: symbol(s) not found for architecture x86_64

Other BIO functions, like BIO_printf are able to be called fine.

Version of OpenSSL: OpenSSL 1.0.2p 14 Aug 2018

I have #include <openssl/bio.h> in my file.

I am very new to C so this is almost certainly user error.

Example Code

Calling make test -f Makefile.osx

With this makefile:

OPENSSL_PATH=$(HOME)/Projects/openssl-1.0.2q
OPENSSL_INCLUDE=$(OPENSSL_PATH)/include
OPENSSL_LIB=$(OPENSSL_PATH)

SRC = $(shell find . -name *.c)
OBJS = $(SRC:%.c=%.o)
TOP = $(dir $(lastword $(MAKEFILE_LIST)))
BINDIR = $(TOP)bin
PRODUCT = $(BINDIR)/bio

all: $(PRODUCT)

%.o: %.c
    cc -g -Wall -I$(OPENSSL_INCLUDE) -c $< -o $@

$(PRODUCT): $(OBJS)
    rm -fr $(BINDIR)
    mkdir $(BINDIR)
    ld -arch x86_64 -macosx_version_min 10.13 -lc -L$(OPENSSL_LIB) -lcrypto -lssl $(OBJS) -o $(PRODUCT)

clean:
    rm -fr $(PRODUCT) $(BINDIR) $(OBJS)

test: all
    $(PRODUCT)

And this main.c file:

#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <openssl/opensslv.h>
#include <openssl/conf.h>
#include <openssl/err.h>
#include <openssl/pem.h>
#include <openssl/bio.h>

#if (OPENSSL_VERSION_NUMBER < 0x1000204fL)
#error OpenSSL 1.0.2q or later required.
#endif

int main(int argc, const char * argv[]) {
    int exit_code;

    if (argc != 4) {
        exit_code = -1;
    } else {
      uint8_t *payload = (uint8_t *) OPENSSL_malloc(128);
      BIO *payload_bio = BIO_new_file(argv[3], "r");
      int payload_len = BIO_read(payload_bio, payload, 128);

      BIO *bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
      BIO_printf(bio_out, "%s\n", OPENSSL_VERSION_TEXT);
      BIO_hex_string(bio_out, 4, 32, payload, payload_len);
    }

    return exit_code;
}

Generates this output:

rm -fr ./bin
mkdir ./bin
ld -arch x86_64 -macosx_version_min 10.13 -lc -L/Users/toby.osbourn/Projects/openssl-1.0.2q -lcrypto -lssl ./bio/main.o -o ./bin/bio
Undefined symbols for architecture x86_64:
  "_BIO_hex_string", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
make: *** [bin/bio] Error 1

Comments