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 |