How to choose a specific msvcr.dl in Nim? - nim-lang

I would like to use an old msvcr71.dll when compiling Nim.
Is there a way to do so? If yes, how?

This is explained in the manual, right here. As StackOverflow doesn't like link responses, a copy-paste:
proc imported_proc(): ReturnType
{.cdecl, dynlib: "msvcr71.dll", importc.}
This asumes there is a function in msvcf71.dll called imported_proc that you want to wrap in your Nim code without changing the name.
You can also tweak which libraries to load when compiling, as explained here:
$ nim c --dynlibOverride:msvcr71 --passL:msvcr71.dll program.nim
Didn't test any of the code, hope it helps. You can always try to find some code that does this kind of linking, for example https://github.com/khchen/wNim/blob/master/wNim/private/winimx.nim or maybe https://github.com/brentp/hts-nim/blob/master/src/hts/private/hts_concat.nim

Related

Emit ASM from Cranelift

Is there the possibility to emit ASM when compiling something using Cranelift? By "ASM" I mean the assembler text-representation, in e.g. Intel-Syntax or similar
Now I was planing on implementing this myself using a dissasembler-library like Capstone or Iced, but then I found Context::set_disasm(bool) which apparently does exactly what I need. The problem is I'm unable to find where to extract this assembler-code from. There's no function like get_disasm as far as I looked.
If it's relevant, I'm building both a JIT and an AOT compiler and I want the dissasembler to work when using either.
Can one help me out?
Retrieve the disasm field of CompiledCode. It is in CompiledCodeBase, so it is not documented, unfortunately.

List all folders named `test` in Rust using `fd-find` crate?

I want to list all folders named test when I run my Rust application as a binary.
I want to use fd-find → https://crates.io/crates/fd-find
The basic documentation shows how to call it in the terminal but doesn't tell how to call it from a rust file called main.rs.
I am new to Rust so don't know much. Any help appreciated :)
By the look of it fd-find is not shipped as a library so I guess your best bet would be something like std::process::Command.

Error linking module in ocaml

I am a complete beginner with Ocaml programming and I am having trouble linking a module into my program. Actually I am doing some regular expression checking and I have written a function that basically tokenizes a string based on a separator string using the Str module . So i use the functions defined in the library like this:
Str.regexp_string /*and so on*/
However, when I try to compile the ml file, I get an error suggesting that I have an undefined global Str . We use List functions by typing in List.length and so on just like I did for Str without having to explicitly include the specific module. I tried
open Str;;
include Str;; /*None of these work and I still get the same error*/
However if in the toplevel I use
load "str.cma" /*Then the program works without problems*/
I want to include the module in the ml file because I have to in the end link 3 cmo's to get the final executable(which is not run in the toplevel). I know this is a really basic question but I am having trouble solving it. Thanks in advance.
You don't need to add anything in your file foo.ml.
You do need to tell the compiler where to find the Str module when compiling foo.ml . To do so, add it to the command line used to compile foo.ml:
ocamlc str.cma foo.ml
or
ocamlopt str.cmxa foo.ml
List and other modules from the standard library are accessible by default, so you don't need to tell the compiler about those often used modules.
Just add str to the libraries field of your dune file.
I think you need to use '-cclib ' compiler directive.
The module name shouldn't include the file ending like .cma.
Below is what I did when trying to use the unix and threads modules.
I think you need to use some combination of the 'custom' and 'cclib' compiler directives.
ocamlc -custom unix.cma threa.ml -cclib -lunix
Look at chapter 7 of this book for help:
http://caml.inria.fr/pub/docs/oreilly-book/html/book-ora063.html
And look at coverage of compiler directives here:
http://caml.inria.fr/pub/docs/manual-ocaml-4.00/manual022.html#c:camlc
ocamlc calc.ml str.cma -o calc
File "calc.ml", line 1:
Error: Error while linking calc.cmo:
Reference to undefined global `Str'
Code is very simple, to cut down scruff.
let split_into_words s =
Str.split ( Str.regexp "[ \n\t]+") s ;;
let _ =
split_into_words "abc def ghi" ;;
On ocaml 4.0.2. Obviously, there is a problem here, but I am too much of a beginner to understand what it is. From toplevel it seems work fine with #load "str.cma", so there is something here we don't understand. Anyone know what it is?

autoconf: AC_PROG_CC checks for object and executable suffix, but how to get this?

I'm a newbie to autoconf, and found out that a call of the macro AC_PROG_CC checks for the suffixes of executables and object files. Now I want to use the results of these checks and replace them in my Makefile.in, but there is no adequate documentation or mentioning in the autoconf docs on how to use this.
I'm also having the general problem: Which macro gives me which variables, and where is a reference to get know about?
Thanks for any help.
The variables you are looking for are #EXEEXT# and #OBJEXT#.
This link takes you to the index of all the output variables from the Autoconf manual.
Unfortunately there's no easy table of which ones are defined by which macros, you just have to read the descriptions.

haskell libmagic how to use it?

I'm trying to write a program that will check the file type of a certain file and I found a haskell library that should do the trick.
The problem arises when I try to use it. I have no idea what I have to do, which function to call etc. The library is full of cryptic commands with no examples, no tutorial or a homepage.
Please help.
There is the package's documentation that contains short descriptions of the important functions (which are not that many). For additional information about what the underlying C library does (and therefore also the Haskell library), have a look at libmagic's man page.
The basic usage should look similar to this (untested):
import Magic.Init
import Magic.Operations
main =
do magic <- magicOpen []
loadDefaultMagic magic
magicFile magic "/my/file" >>= print

Resources