Anonymous user
Call a function in a shared library: Difference between revisions
Call a function in a shared library (view source)
Revision as of 01:31, 11 January 2021
, 3 years ago→{{header|Crystal}}: added second part of the problem, falling back to a different function
(→{{header|Crystal}}: add crystal implementation) |
(→{{header|Crystal}}: added second part of the problem, falling back to a different function) |
||
Line 277:
=={{header|Crystal}}==
<lang ruby>libm = LibC.dlopen("libm.so.6", LibC::RTLD_LAZY)
sqrtptr = LibC.dlsym(libm, "sqrt") unless libm.null?▼
if sqrtptr
▲sqrtptr = LibC.dlsym(libm, "sqrt")
sqrtproc = Proc(Float64, Float64).new sqrtptr, Pointer(Void).null▼
else
sqrtproc = ->Math.sqrt(Float64)
end
puts "the sqrt of 4 is #{sqrtproc.call(4.0)}"</lang>▼
▲sqrtproc = Proc(Float64, Float64).new sqrtptr, Pointer(Void).null
▲puts "the sqrt of 4 is #{sqrtproc.call(4.0)}"
▲LibC.dlclose(libm)</lang>
=={{header|D}}==
|