0

I'm new to using wolfSSL. I am trying to compile a set of codes using gcc. gcc -o main main.c -lwolfssl

I encounter an error of main.c:(.text+0x47b): undefined reference to 'wolfSSL_get_peer_certificate' collect2: error: ld returned 1 exit status upon entering the statement.

A snippet of the code shows the error location:

        fprintf(stderr, "ERROR: failed to connect to wolfSSL\n");
        return -1;
    }   
    ret = certverify(CERT_FILE,verifyCert);
    WOLFSSL_X509* webCert = wolfSSL_get_peer_certificate(ssl);

I have tried modifying the WOLFSSL_X509* webCert = wolfSSL_get_peer_certificate(ssl); command but it seems to be correct.

I am not too sure why this error is occuring. Can someone please help me with this?

I am using Kali Linux 2019.4 to compile this set of codes.

UBUNTU_new
  • 43
  • 1
  • 8

1 Answers1

1

@wolfSSL_new,

It sounds like the application is failing to link the library so while the right headers are in place to locate the function definitions the final step to link the function is what is failing. Where is libwolfssl.so or libwolfssl.a located on your system? Is it in /usr/local/lib/libwolfssl.so or /usr/local/lib/libwolfssl.a?

(.a is a static library, .so is a shared object library it can be either or)

Once you located where it is try this build command instead (For the sake of an example I am going to assume it is in /usr/local/lib):

gcc main.c -o main -I/usr/local/include -L/usr/local/lib -lwolfssl

Let me know if that resolves the linker error you are seeing.

[UPDATE]

This was resolved by adding the configure setting --enable-opensslextra

[END UPDATE]

Regards,

K

Kaleb
  • 591
  • 4
  • 17
  • 1
    Hi Kaleb, thanks for your prompt reply. Apologies as I was busy with another project. I have located the source ofthe file libwolfss.so, it is located at /usr/local/lib . I am also seeing ```libwolfssl.la libwolfssl.so.19 pkgconfig python3.7 libwolfssl.so libwolfssl.so.19.1.0 python2.7 x86_64-linux-gnu ``` these files. – UBUNTU_new Feb 09 '20 at 18:00
  • 1
    Upon trying the ```gcc main.c -o main -I/usr/local/include -L/usr/local/lib -lwolfssl``` code, I get ```root@kali:~/Desktop/2/Project# gcc main.c -o main -I/usr/local/include -L/usr/local/lib -lwolfssl /usr/bin/ld: /tmp/cchLwxC1.o: in function `start_WolfSSL': main.c:(.text+0x47b): undefined reference to `wolfSSL_get_peer_certificate' collect2: error: ld returned 1 exit status ``` – UBUNTU_new Feb 09 '20 at 18:01
  • 1
    @wolfSSL_new, Please double check that you have included and that it is included first before any other wolfSSL headers. Lastly make sure you configured with the option ./configure CFLAGS="-DWOLFSSL_KEEP_PEER_CERT" and that define is in /usr/local/include/wolfssl/options.h, let me know if that helps. – Kaleb Feb 10 '20 at 14:13
  • 1
    Hi @Kaleb, I still can't seem to get it to work after making sure that wolfssl/options.h is at the top of all headers of my code. ```/* socket includes */ #include #include #include #include /* wolfSSL */ #include #include #include #include //#include ``` After running the ./configure CFLAGS -DWOLFSSL_KEEP_PEER_CERT and retrying, I still meet the same error. – UBUNTU_new Feb 11 '20 at 15:27
  • 1
    ```root@kali:~/Desktop# gcc main.c -o main -I/usr/local/include -L/usr/local/lib -lwolfssl /usr/bin/ld: /tmp/cct4jJgL.o: in function `start_WolfSSL': main.c:(.text+0x47b): undefined reference to `wolfSSL_get_peer_certificate' collect2: error: ld returned 1 exit status ``` This is the error I face when using GCC to compile it – UBUNTU_new Feb 11 '20 at 15:30
  • 1
    ```* C Flags: -DWOLFSSL_KEEP_PEER_CERT -Wno-pragmas -Wall -Wno-strict-aliasing -Wextra -Wunknown-pragmas --param=ssp-buffer-size=1 -Waddress -Warray-bounds -Wbad-function-cast -Wchar-subscripts -Wcomment -Wfloat-equal -Wformat-security -Wformat=2 -Wmaybe-uninitialized -Wmissing-field-initializers -Wmissing-noreturn -Wmissing-prototypes -Wnested-externs -Wnormalized=id -Woverride-init -Wpointer-arith -Wpointer-sign -Wredundant-decls -Wshadow -Wsign-compare -Wstrict-overflow=1 -Wswitch-enum -Wundef -Wunused -Wunused-result -Wunused-variable -Wwrite-strings -fwrapv``` config – UBUNTU_new Feb 11 '20 at 15:30
  • 1
    Could you shoot me an email at support [at] wolfssl [dot] com with the series of commands you are using from start to error IE starting with unzipping the wolfSSL download and finishing with building your application and seeing the error? (did you re-run make install after re-configuring and double check that setting was in the installed header location /usr/local/include/wolfssl/options.h?) – Kaleb Feb 11 '20 at 15:48
  • 1
    Just got your email! I'll respond to you directly. Cheers, K – Kaleb Feb 11 '20 at 16:00