[Ur] C FFI and openssl

Todd Roth toddjroth at gmail.com
Sun Jul 26 17:26:10 EDT 2015


I’m getting the following error when compiling a project which uses the C FFI and links to the openssl library.  A similar post (http://www.impredicative.com/pipermail/ur/2012-October/001241.htm <http://www.impredicative.com/pipermail/ur/2012-October/001241.htm>) mentioned linking lpq at the end of the commands but this sample project doesn’t include lpq. Any ideas on what I might be doing wrong?  Thanks!

th at ubuntu:~/Documents/urwebapps/sample$ urweb sample -debug
gcc  -pthread -Wimplicit -Werror -Wno-unused-value -I /usr/local/include/urweb  -c "/tmp/webapp.c" -o "/tmp/webapp.o" -g
gcc -Werror  -pthread  "/tmp/webapp.o" -L/usr/local/lib -lurweb_http -lurweb -lm -lcrypto -lssl  -o "/home/toddroth/Documents/urwebapps/sample/sample.exe" -g /home/toddroth/Documents/urwebapps/sample/crypt/crypt.o
/usr/bin/ld: /home/toddroth/Documents/urwebapps/sample/crypt/crypt.o: undefined reference to symbol 'SHA256@@OPENSSL_1.0.0'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libcrypto.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status




Library Files

crypt.urs
--------------------------------------------------------------------------------------------------------------
val hello : unit -> string
val sha256 : string -> string


crypt.h
--------------------------------------------------------------------------------------------------------------
#include <urweb.h>

uw_Basis_string uw_Crypt_hello(uw_context, uw_unit);
uw_Basis_string uw_Crypt_sha256(uw_context ctx, uw_Basis_string data);


crypt.c
--------------------------------------------------------------------------------------------------------------
#include <string.h>
#include <stdio.h>
#include <openssl/evp.h>
#include <openssl/sha.h>
#include <urweb.h>

uw_Basis_string uw_Crypt_hello(uw_context ctx, uw_unit u) {
  return "Hello";
}

uw_Basis_string uw_Crypt_sha256(uw_context ctx, uw_Basis_string data) {
  unsigned char dataBin[128], out[EVP_MAX_MD_SIZE];
  int len;
  
  len = unbase64((unsigned char *)data, strlen(data), dataBin, sizeof dataBin);
      
  SHA256(dataBin, len, out);
  return base64(ctx, out, SHA256_DIGEST_LENGTH);
}


lib.urp
--------------------------------------------------------------------------------------------------------------
ffi crypt
include crypt.h
link crypt.o


Makefile
--------------------------------------------------------------------------------------------------------------
CFLAGS := -I/usr/local/include/urweb

all: crypt.o


Project Files

sample.urp
--------------------------------------------------------------------------------------------------------------
library crypt/lib

sample
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.impredicative.com/pipermail/ur/attachments/20150726/0598f87f/attachment.html>


More information about the Ur mailing list