Hi,
I was trying to run the port driver example but am not having much luck loading the driver.
It fails to load the driver. I tried running load_driver
from the shell and get {error,{open_error,-203}}
. Translating that with erl_ddll:format_error({open_error, -203})
, gives 'Unspecified error'
. It is finding the .dll, because if I put the wrong name in it says 'The specified module could not be found.'
I tried setting ERL_LIBS
to include this directory.
I tried setting the below as per this post:
ERL_INTERFACE_INCLUDE_DIR="c:/Program Files/erl-24.1.2/lib/erl_interface-5.1/include"
ERL_INTERFACE_LIB_DIR="c:/Program Files/erl-24.1.2/lib/erl_interface-5.1/lib"
ERTS_INCLUDE_DIR="c:/Program Files/erl-24.1.2/erts-12.1.2/include"```
I tried adding #define __WIN32__
to the c file.
I tried using the echo_drv from erlang tests instead, with the same result.
I tried adding the path as per this SO with no luck.
start(SharedLib) ->
{ok,Cwd} = file:get_cwd(),
code:add_path(Cwd),
case erl_ddll:load_driver(Cwd, SharedLib) of
ok -> ok;
{error, already_loaded} -> ok;
{error, Error} ->
erlang:display(erl_ddll:format_error(Error)),
exit({error, could_not_load_driver})
end,
spawn(?MODULE, init, [SharedLib]).
Running .\dumpbin.exe /dependents example_drv.dll
gives:
Microsoft (R) COFF/PE Dumper Version 14.27.29112.0
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file C:\Users\simon\code\ctapinif\example_drv.dll
File Type: DLL
Image has the following dependencies:
KERNEL32.dll
VCRUNTIME140.dll
api-ms-win-crt-runtime-l1-1-0.dll
Summary
1000 .data
1000 .rdata
1000 .reloc
1000 .text
I tried copying them to the cwd. Is there anything I need to do with regards to the dependant dlls?
As an aside,
In port_driver.c
, the includes are:
#include <stdio.h>
#include "erl_driver.h"
which means you need to include the path to erl_driver.h
and cl
in VS 2019 docs use /
instead of -
, so I ended running the following in VS2019 dev console:
cl /I"C:\Program Files\erl-24.1.2\usr\include" /LD /MD /Feexample_drv.dll complex.c port_driver.c