# SSL compile error

**URL:** <https://mangoh.discourse.group/t/ssl-compile-error/1619>\
**Category:** mangOH Green\
**Created:** [June 26, 2018, 8:28am UTC](https://mangoh.discourse.group/t/ssl-compile-error/1619 "2018-06-26T08:28:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![manoj.p0489](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@manoj.p0489](https://mangoh.discourse.group/u/manoj.p0489)\
**Post date:** [June 26, 2018, 8:28am UTC](https://mangoh.discourse.group/t/ssl-compile-error/1619/1 "2018-06-26T08:28:18Z")

</div>

I am getting compilation error. how to include a file available in toolchain. please find my source code below with errors.

#include “legato.h”  
#include \<openssl/ssl.h\>  
#include \<openssl/err.h\>  
//#include \<openssl/applink.c\>  
#include \<stdio.h\>  
#include \<errno.h\>  
#include \<unistd.h\>  
#include \<malloc.h\>  
#include \<string.h\>  
#include \<sys/socket.h\>  
#include \<resolv.h\>  
#include \<netdb.h\>

#define FAIL -1

int sockfd, newsockfd;  
SSL\_CTX \*sslctx;  
SSL \*cSSL;

int OpenConnection(const char \*hostname, int port)  
{ int sd;  
struct hostent \*host;  
struct sockaddr\_in addr;

```
if ( (host = gethostbyname(hostname)) == NULL )
{
    perror(hostname);
    abort();
}
sd = socket(PF_INET, SOCK_STREAM, 0);
bzero(&addr, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = *(long*)(host->h_addr);
if ( connect(sd, (struct sockaddr*)&addr, sizeof(addr)) != 0 )
{
    close(sd);
    perror(hostname);
    abort();
}
return sd;

```

}

SSL\_CTX\* InitCTX(void)  
{ const SSL\_METHOD \*method;  
SSL\_CTX \*ctx;

```
OpenSSL_add_all_algorithms(); /* Load cryptos, et.al. */
SSL_load_error_strings(); /* Bring in and register error messages */
method = TLSv1_2_client_method(); /* Create new client-method instance */
ctx = SSL_CTX_new(method); /* Create new context */
if ( ctx == NULL )
{
    ERR_print_errors_fp(stderr);
    abort();
}
return ctx;

```

}

void ShowCerts(SSL\* ssl)  
{ X509 \*cert;  
char \*line;

```
cert = SSL_get_peer_certificate(ssl); /* get the server's certificate */
if ( cert != NULL )
{
    printf("Server certificates:\n");
    line = X509_NAME_oneline(X509_get_subject_name(cert), 0, 0);
    printf("Subject: %s\n", line);
    free(line); /* free the malloc'ed string */
    line = X509_NAME_oneline(X509_get_issuer_name(cert), 0, 0);
    printf("Issuer: %s\n", line);
    free(line); /* free the malloc'ed string */
    X509_free(cert); /* free the malloc'ed certificate copy */
}
else
    printf("Info: No client certificates configured.\n");

```

}

int main(int count, char \*strings[])  
{ SSL\_CTX \*ctx;  
int server;  
SSL \*ssl;  
char buf[1024];  
int bytes;  
char \*hostname, \*portnum;

```
if ( count != 3 )
{
    printf("usage: %s <hostname> <portnum>\n", strings[0]);
    exit(0);
}
SSL_library_init();
hostname=strings[1];
portnum=strings[2];

ctx = InitCTX();
server = OpenConnection(hostname, atoi(portnum));
ssl = SSL_new(ctx); /* create new SSL connection state */
SSL_set_fd(ssl, server); /* attach the socket descriptor */
if ( SSL_connect(ssl) == FAIL ) /* perform the connection */
    ERR_print_errors_fp(stderr);
else
{ char *msg = "Hello???";

    printf("Connected with %s encryption\n", SSL_get_cipher(ssl));
    ShowCerts(ssl); /* get any certs */
    SSL_write(ssl, msg, strlen(msg)); /* encrypt & send message */
    bytes = SSL_read(ssl, buf, sizeof(buf)); /* get reply & decrypt */
    buf[bytes] = 0;
    printf("Received: \"%s\"\n", buf);
    SSL_free(ssl); /* release connection state */
}
close(server); /* close socket */
SSL_CTX_free(ctx); /* release context */
return 0;

```

}  
COMPONENT\_INIT  
{  
LE\_INFO(“Hello, world.”);  
}

Errors:

13:48:46 \*\*\*\* Incremental Build of configuration Target\_Legato\_Debug for project helloworld \*\*\*\*  
make -I /home/datta/legato/packages/legato.framework.16.10.1.wp85-wp750x-201701111029/resources/legato -C Target\_Legato\_Debug all  
make: Entering directory ‘/home/datta/Downloads/legato\_rel15\_16.10.4\_wpx5/workspace/helloworld/Target\_Legato\_Debug’  
cd …;mkapp -t wp85 -o Target\_Legato\_Debug -w Target\_Legato\_Debug -i “/home/datta/legato/packages/legato.framework.16.10.1.wp85-wp750x-201701111029/resources/legato/interfaces/modemServices” -i “/home/datta/legato/packages/legato.framework.16.10.1.wp85-wp750x-201701111029/resources/legato/interfaces/wifi” -i “/home/datta/legato/packages/legato.framework.16.10.1.wp85-wp750x-201701111029/resources/legato/interfaces/atServices” -i “/home/datta/legato/packages/legato.framework.16.10.1.wp85-wp750x-201701111029/resources/legato/interfaces/positioning” -i “/home/datta/legato/packages/legato.framework.16.10.1.wp85-wp750x-201701111029/resources/legato/interfaces/secureStorage” -i “/home/datta/legato/packages/legato.framework.16.10.1.wp85-wp750x-201701111029/resources/legato/interfaces/airVantage” -i “/home/datta/legato/packages/legato.framework.16.10.1.wp85-wp750x-201701111029/resources/legato/interfaces” -i “/home/datta/legato/packages/legato.framework.16.10.1.wp85-wp750x-201701111029/resources/legato/interfaces/logDaemon” -i “/home/datta/legato/packages/legato.framework.16.10.1.wp85-wp750x-201701111029/resources/legato/interfaces/supervisor” -s “.” -s “/home/datta/legato/packages/legato.framework.16.10.1.wp85-wp750x-201701111029/resources/legato/components” -C -g -X -g -L -g helloworld.adef  
[1/7] Compiling C source  
[2/7] Compiling C source  
[3/7] Linking C library  
[4/7] Linking C executable  
[5/7] Creating hard link  
FAILED: /home/datta/legato/packages/legato.toolchain.1.7.3.SWI9X15Y\_07112100-wp85-wp750x-native-x86\_64-201701091132/resources/native/sysroots/x86\_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc --sysroot=/home/datta/legato/packages/legato.toolchain.1.7.3.SWI9X15Y\_07112100-wp85-wp750x-native-x86\_64-201701091132/resources/native/sysroots/armv7a-vfp-neon-poky-linux-gnueabi -o Target\_Legato\_Debug/app/helloworld/staging/read-only/bin/helloworld Target\_Legato\_Debug/app/helloworld/obj/helloworld/\_main.c.o -rdynamic -Wl,–enable-new-dtags,-rpath="$ORIGIN/…/lib" -LTarget\_Legato\_Debug/staging/read-only/lib “-LTarget\_Legato\_Debug/staging/read-only/lib” -lComponent\_helloworldComponent “-LTarget\_Legato\_Debug/staging/read-only/lib” -lComponent\_helloworldComponent “-L$LEGATO\_BUILD/framework/lib” -llegato -lpthread -lrt -ldl -lm -g  
Target\_Legato\_Debug/staging/read-only/lib/libComponent\_helloworldComponent.so: undefined reference to `SSL_write' Target_Legato_Debug/staging/read-only/lib/libComponent_helloworldComponent.so: undefined reference to`SSL\_free’  
Target\_Legato\_Debug/staging/read-only/lib/libComponent\_helloworldComponent.so: undefined reference to `SSL_set_fd' Target_Legato_Debug/staging/read-only/lib/libComponent_helloworldComponent.so: undefined reference to`X509\_NAME\_oneline’  
Target\_Legato\_Debug/staging/read-only/lib/libComponent\_helloworldComponent.so: undefined reference to `X509_get_subject_name' Target_Legato_Debug/staging/read-only/lib/libComponent_helloworldComponent.so: undefined reference to`X509\_get\_issuer\_name’  
Target\_Legato\_Debug/staging/read-only/lib/libComponent\_helloworldComponent.so: undefined reference to `SSL_library_init' make: *** [target] Error 1 Target_Legato_Debug/staging/read-only/lib/libComponent_helloworldComponent.so: undefined reference to`SSL\_read’  
Target\_Legato\_Debug/staging/read-only/lib/libComponent\_helloworldComponent.so: undefined reference to `SSL_get_current_cipher' Target_Legato_Debug/staging/read-only/lib/libComponent_helloworldComponent.so: undefined reference to`SSL\_new’  
Target\_Legato\_Debug/staging/read-only/lib/libComponent\_helloworldComponent.so: undefined reference to `OPENSSL_add_all_algorithms_noconf' Target_Legato_Debug/staging/read-only/lib/libComponent_helloworldComponent.so: undefined reference to`SSL\_CTX\_new’  
Target\_Legato\_Debug/staging/read-only/lib/libComponent\_helloworldComponent.so: undefined reference to `SSL_get_peer_certificate' Target_Legato_Debug/staging/read-only/lib/libComponent_helloworldComponent.so: undefined reference to`X509\_free’  
Target\_Legato\_Debug/staging/read-only/lib/libComponent\_helloworldComponent.so: undefined reference to `SSL_connect' Target_Legato_Debug/staging/read-only/lib/libComponent_helloworldComponent.so: undefined reference to`SSL\_CTX\_free’  
Target\_Legato\_Debug/staging/read-only/lib/libComponent\_helloworldComponent.so: undefined reference to `SSL_load_error_strings' Target_Legato_Debug/staging/read-only/lib/libComponent_helloworldComponent.so: undefined reference to`TLSv1\_2\_client\_method’  
Target\_Legato\_Debug/staging/read-only/lib/libComponent\_helloworldComponent.so: undefined reference to `SSL_CIPHER_get_name' Target_Legato_Debug/staging/read-only/lib/libComponent_helloworldComponent.so: undefined reference to`ERR\_print\_errors\_fp’  
collect2: error: ld returned 1 exit status  
ninja: build stopped: subcommand failed.  
Makefile:44: recipe for target ‘target’ failed  
make: Leaving directory ‘/home/datta/Downloads/legato\_rel15\_16.10.4\_wpx5/workspace/helloworld/Target\_Legato\_Debug’

13:48:46 Build Finished (took 531ms)

Problems:

| Description | Path | Resource | Location | Type |
| --- | --- | --- | --- | --- |
| undefined reference to `X509\_NAME\_oneline’ | | helloworld | line 0 | C/C++ Problem |
| undefined reference to `X509\_get\_subject\_name’ | | helloworld | line 0 | C/C++ Problem |
| undefined reference to `X509\_get\_issuer\_name’ | | helloworld | line 0 | C/C++ Problem |
| undefined reference to `X509\_free’ | | helloworld | line 0 | C/C++ Problem |
| undefined reference to `TLSv1\_2\_client\_method’ | | helloworld | line 0 | C/C++ Problem |
| undefined reference to `SSL\_write’ | | helloworld | line 0 | C/C++ Problem |
| undefined reference to `SSL\_set\_fd’ | | helloworld | line 0 | C/C++ Problem |
| undefined reference to `SSL\_read’ | | helloworld | line 0 | C/C++ Problem |
| undefined reference to `SSL\_new’ | | helloworld | line 0 | C/C++ Problem |
| undefined reference to `SSL\_load\_error\_strings’ | | helloworld | line 0 | C/C++ Problem |
| undefined reference to `SSL\_library\_init’ | | helloworld | line 0 | C/C++ Problem |
| undefined reference to `SSL\_get\_peer\_certificate’ | | helloworld | line 0 | C/C++ Problem |
| undefined reference to `SSL\_get\_current\_cipher’ | | helloworld | line 0 | C/C++ Problem |
| undefined reference to `SSL\_free’ | | helloworld | line 0 | C/C++ Problem |
| undefined reference to `SSL\_CTX\_new’ | | helloworld | line 0 | C/C++ Problem |
| undefined reference to `SSL\_CTX\_free’ | | helloworld | line 0 | C/C++ Problem |
| undefined reference to `SSL\_connect’ | | helloworld | line 0 | C/C++ Problem |
| undefined reference to `SSL\_CIPHER\_get\_name’ | | helloworld | line 0 | C/C++ Problem |
| undefined reference to `OPENSSL\_add\_all\_algorithms\_noconf’ | | helloworld | line 0 | C/C++ Problem |
| undefined reference to `ERR\_print\_errors\_fp’ | | helloworld | line 0 | C/C++ Problem |
| recipe for target ‘target’ failed | /helloworld/Target\_Legato\_Debug | Makefile | line 44 | C/C++ Problem |
