Undefined symbol when load a module to the target - undefined

I got some errors when I try to load a lib to the target system with loadModule function.
Some symbols are undefined
Undefined symbol: __divdi3 (binding 1 type 0)
Undefined symbol: __floatdidf (binding 1 type 0)
Undefined symbol: recv (binding 1 type 0)
Undefined symbol: connect (binding 1 type 0)
Undefined symbol: taskSpawn (binding 1 type 0)
Undefined symbol: __gtdf2 (binding 1 type 0)
Undefined symbol: __floatsidf (binding 1 type 0)
Undefined symbol: __ltdf2 (binding 1 type 0)
Undefined symbol: recvfrom (binding 1 type 0)
Undefined symbol: socket (binding 1 type 0)
Undefined symbol: __adddf3 (binding 1 type 0)
Undefined symbol: __umoddi3 (binding 1 type 0)
Undefined symbol: __udivdi3 (binding 1 type 0)
Undefined symbol: send (binding 1 type 0)
Undefined symbol: accept (binding 1 type 0)
Undefined symbol: __fixdfsi (binding 1 type 0)
Undefined symbol: taskDelay (binding 1 type 0)
Undefined symbol: bind (binding 1 type 0)
Undefined symbol: inet_addr (binding 1 type 0)
Undefined symbol: setsockopt (binding 1 type 0)
Undefined symbol: sendto (binding 1 type 0)
Undefined symbol: __negdf2 (binding 1 type 0)
Undefined symbol: listen (binding 1 type 0)
Undefined symbol: __divdf3 (binding 1 type 0)
Undefined symbol: __muldf3 (binding 1 type 0)
Undefined symbol: taskIdSelf (binding 1 type 0)
Undefined symbol: shutdown (binding 1 type 0)
Undefined symbol: gethostname (binding 1 type 0)
Undefined symbol: __fixdfdi (binding 1 type 0)
Undefined symbol: getpeername (binding 1 type 0)
Undefined symbol: getsockopt (binding 1 type 0)
Undefined symbol: __gedf2 (binding 1 type 0)
Undefined symbol: __subdf3 (binding 1 type 0)
Undefined symbol: soo_ioctl (binding 1 type 0)
Undefined symbol: tickGet (binding 1 type 0)
Undefined symbol: getsockname (binding 1 type 0)
But all of those symbols can be find in the symbol table of the target
Any advice will be appreciated

Related

Error in Julia: LoadError: MethodError: no method matching isless(::Vector{Int64}, ::Int64)

I am writing a code in julia but I am getting this error: LoadError: MethodError: no method matching isless(::Vector{Int64}, ::Int64). The part of mu code is:
X = []
function form(;a, b, c, d,e)
if a == 1 && b == 0
#assert c <= 1000 "error."
else
#error failed"
end
.....
push!(x, form(a=2, b=5, c=[0,0], d=[0,1], e=[0,0]))
The error is telling you that there is no method for checking if a vector is less than an integer. You can write .<= to broadcast the less-than comparison, which will perform the comparison element by element, but then you will want any or all or some other logic to transform that comparison output into a single true/false.
julia> [0, 0] <= 1000
ERROR: MethodError: no method matching isless(::Vector{Int64}, ::Int64)
Closest candidates are:
isless(::AbstractVector, ::AbstractVector) at abstractarray.jl:2612
isless(::AbstractFloat, ::Real) at operators.jl:186
isless(::Real, ::Real) at operators.jl:434
...
Stacktrace:
[1] <(x::Vector{Int64}, y::Int64)
# Base .\operators.jl:356
[2] <=(x::Vector{Int64}, y::Int64)
# Base .\operators.jl:405
[3] top-level scope
# REPL[1]:1
julia> [0, 0] .<= 1000
2-element BitVector:
1
1
julia> any([0, 1003] .<= 1000)
true
julia> all([0, 0] .<= 1000)
true

OCaml 5.0.0~beta1: How to use an argument of Effect when their effect handler is not specified (Using Unhandled Exception)

I am using opam switch: 5.0.0~beta1
I was playing around with some simple functions (on utop):
type _ Effect.t += Foo : (unit -> unit) -> unit Effect.t
let a = try perform (Foo (fun () -> Printf.printf "Hello from Foo\n ")) with
| Unhandled (Foo f) -> f ();;
Output: Hello from Foo
val a: unit = ()
This works well.
But when we change the definition of Foo effect,
type _ Effect.t += Foo : ('a -> unit) -> unit Effect.t
let a = try perform (Foo (fun n -> Printf.printf "Hello from Foo\n ")) with
| Unhandled (Foo f) -> f 45;;
Error: This expression has type int but an expression was expected of type
$Foo_'a
Here I understand that it needs 'a as an input, but while calling the function, shouldnt it infer the type as int and replace 'a with int and execute the function accordingly? I want to call function f from Foo effect with different argument.
Here is the another example:
type _ Effect.t += Suspend : 'a -> unit Effect.t
let a = try perform (Suspend 32) with
| Unhandled (Suspend x) -> x;;
Error: This expression has type $Suspend_'a
but an expression was expected of type $Unhandled_'a
Here, I understand that return value of (try _ with) i.e. (unit) should be the type of $Unhandled_ 'a.
But I also want to know, what is $Unhandled_ 'a type? How is normal 'a is different from $Unhandled_ 'a? How to return $Unhandled_ 'a here? Why there is this special use of $Unhandled?
What will be its scope (In some examples where I was using following code,
type _ Effect.t += Foo : ('a -> unit) -> unit Effect.t
let p = try Lwt.return (some_function x) with
| Unhandled (Foo f) -> let (pr, res) = Lwt.task () in
let wkup v = (Lwt.wakeup res v; ()) in
f wkup;
pr
I also got error as :
This expression has type $Unhandled_'a Lwt.t
but an expression was expected of type 'a Lwt.t
The type constructor $Unhandled_'a would escape its scope
)?
Why there is
The type constructor $Unhandled_'a would escape its scope
error?
The effect part is a red-herring here, the root issue stems from the notion of existentially-quantified types in GADTs.
When you have a GADT which is defined as
type t = Foo : ('a -> unit) -> t
the type of Foo means that you can construct a t for any type 'a and any function of type 'a -> unit. For instance:
let l = [Foo ignore; Foo print_int]
However, once you have constructed such value, you can no longer knows which type was used to construct the value. If you have a value
let test (Foo f) = ...
you only know that there exists some type 'a such that f has type 'a -> unit. This why the type 'a is called an existentially type (aka a type such that we only know that it exists). The important things to remember is that you don't know which 'a. Consequently you cannot apply the function because applying to the wrong 'a would be a type error.
In other words, the function boxed in Foo f can never be called on any value.
This is slightly more subtle variant than the any type
type any = Any: 'a -> any
where the constructor Any takes a value of any type and put it in a black box from which it can never be extracted.
In a way existentially-quantified type variables in a GADT lives in their own world and they cannot escape it. But they can be still be useful if this inner world is large enough. For instance, I can bundle a value with a function that prints that value and then forget the type of this value with:
type showable = Showable: {x:'a; print:'a -> unit} -> showable
Here, I can call the function print on the value x because I know that whatever is 'a it is the same 'a for both x and print:
let show (Showable {x;print}) = print x
Thus I can store few showable values in a list
let l = [ Showable(0, print_int), Showable("zero", print_string)]
and print them later
let () = List.iter show l

F# using inline: still fail to match different type for generic function

I tried to use "inline" to define a function that would fit into different input parameter types:
> let x=2.0
- let inline f x=x+1
- f x;;
f x;;
--^
stdin(6,3): error FS0001: This expression was expected to have type
int
but here has type
float
I expect that after applying "inline" on f, I got a generic function call "f". but seems failed.
How to correct it?
The best way is to use genericOne like so:
let inline f x = x + LanguagePrimitives.GenericOne
This is because when you have used 1, the compiler has infered that the function argument must be an int as you can only add ints to other ints
then you can call it with
> f 1;;
val it : int = 2
> f 1.0;;
val it : float = 2.0
That's because you're adding 1 in your function. Because of that x has to be an int.
inline would work if you provide both sides of + as parameters:
> let inline f x y = x + y;;
val inline f :
x: ^a -> y: ^b -> ^c
when ( ^a or ^b) : (static member ( + ) : ^a * ^b -> ^c)
As you can see, it's type is resolved as any type with +. You can use it to add two intsor twofloat`s together:
> f 1 2;;
val it : int = 3
> f 1. 2.;;
val it : float = 3.0
You can't however use it to add an int to a float:
> f 1. 2;;
f 1. 2;;
-----^
stdin(9,6): error FS0001: The type 'int' does not match the type 'float'

returning a function returning bool VS returning bool (OCaml)

type form = TRUE
|FALSE
|NOT of form
let rec check x = function
TRUE -> true
|FALSE -> false
|NOT(y) -> not eval y
(*where TRUE, FALSE and NOT all custom type 'form'*)
I tried to define a function form -> bool, but I got an compile error for
|NOT(y) -> not eval y
line. The error message says
This expression type form -> bool, but an expression was expected of type bool
though the function 'eval' returns type 'bool', what's the reason it can't be a return value for a function returning bool?
The type of the function you defined (check or eval) is 'a -> form -> bool. You match against implicit input parameter introduced by function keyword. First parameter x is not used (but expected).
As eval has two input parameters, (eval y) expression has type form -> bool. This is what the error message about.
Try this:
let rec eval = function
| TRUE -> true
| FALSE -> false
| NOT(y) -> not (eval y)
Alternative form with explicit input parameter x:
let rec eval x = match x with
| TRUE -> true
| FALSE -> false
| NOT(y) -> not (eval y)

FSharpTypeFunc.Specialize causing TypeLoadException

I'm getting the following run-time exception:
System.TypeLoadException was unhandled
Message=Method 'Specialize' on type [...] tried to implicitly override a method with weaker type parameter constraints.
This inner function appears to be the problem:
let getKey (r: IDictionary<_,_>) =
match r.TryGetValue(keyCol.Name) with
| true, k when not (isNull k) -> Some k
| _ -> None
The signature is IDictionary<string,'a> -> 'a option (requires 'a : null). The constraint is propagated from isNull.
Looking in ILSpy, getKey is compiled to a sub-type of FSharpTypeFunc that overrides Specialize<T>().
Is this a bug? I can work around it by boxing k in the call to isNull, which removes the constraint.
EDIT
Here's a full repro:
open System.Collections.Generic
let isNull = function null -> true | _ -> false
type KeyCol = { Name : string }
let test() =
seq {
let keyCol = { Name = "" }
let getKey (r: IDictionary<_,_>) =
match r.TryGetValue(keyCol.Name) with
| true, k when not (isNull k) -> Some k
| _ -> None
getKey (dict ["", box 1])
}
test() |> Seq.length |> printfn "%d"
This is a console app in Visual Studio 2008, targeting .NET 4.0. Strangely, the code works in FSI.
Here's PEVerify output for the assembly:
[token 0x02000004] Type load failed.
[IL]: Error: [D:\TEST\bin\Debug\TEST.exe : Test+test#10[a]::GenerateNext] [mdToken=0x6000012][offset 0x00000031] Unable to resolve token.
2 Error(s) Verifying D:\TEST\bin\Debug\TEST.exe
Sent it to fsbugs and received a reply that it's been fixed.