F# script can't load .Net 4.5? - f#

I have an F# library that uses the .Net 4.5 HttpClient. It compiles just fine but when I try to call functions in the library after loading it in a script the script says it can't find System.Net.Http.
Both the script and the library are in the same project targeted at .Net 4.5.
The library (in TdApi.fs) does this open System.Net.Http; but when the script does this #load "TdApi.fs" the error in the interactive window is this TdApi.fs(6,17): error FS0039: The namespace 'Http' is not defined.
I'm using VS2012 and am just getting started in F#.

There is a difference between a compiled library and a script file.
When you compile your TdApi.fs file as part of a library project, the dependencies (in your case, the HTTP library) are specified in project properties. The compiler uses the fsproj file to find the dependencies (and so everything compiles fine).
When you #load your TdApi.fs file from a script, it does not know about the project - and so it also does not know about the dependencies. To fix this, you can either use #r "TdApi.dll" where TdApi.dll is the compiled library, or you can use something like:
#r "someplace/System.Net.Http.dll"
#load "TdApi.fs"
So, you can use #r to explicitly load the HTTP library first and then TdApi.fs will see it.

Related

Add Suave - Open Declarations not working

I add Suave.io to my project - so far empty - via NuGet and that's alright. But none of the open Suave declarations work yielding "The namespace or module "Suave" is not defined."
The following works in script file though:
#r ".../Suave.dll"
open Suave
Targeting .NET 4.7 (rather than 4.5.2) solved the issue. Wierd

Delphi package compiles without the finding the unit file of a referenced type?

Today I'm trying to figure out why something works when I think it should be broken.
I have little Delphi experience, and I've inherited a Delphi codebase and am setting up a machine where it will be maintained and compiled. I have a package that compiles successfully but can't figure out how it is resolving one of the types. My understanding is that when you use a unit, you must either
Include the source file in your package directly
Resolve the source pas or dcu file on your project search path
Resolve the source pas or dcu file on your IDE library path
None of these appear to be happening, and yet the package compiles. How else could this be compiling successfully?
Details
I have 'base' package that has a direct include on the file THotLog.pas. The file appears under the project's Contains folder in Project Manager. THotLog is NOT one of the components in the package, it is not in the register procedure for base package.
I then have 'consuming' package that requires base package. Consuming package has several components with THotLog members, and consuming package compiles. This surprises me, because I thought consuming package would have to be able to locate THotLog.pas or THotLog.dcu.
This is for RAD Studio 10.1. The project search path (Project > Options : Search path) is empty, and the IDE search paths (Tools > Options , then Environment Options > Delphi Options > Library) do not include where THotLog is.
I've also tried renamed all THotLog files on the hard drive and consuming package still compiles.
Hypothesizing that my understanding about type resolution is wrong, I tried making a set of sample projects with a similar layout and the sample consuming package cannot resolve sample THotLog without locating the pas or dcu file.
When you build a Delphi package, the compiler/linker creates a Compiled Package File named [package-name].dcp. It is a binary file containing all of the compiled units included in that package.
Compiling your "base" package created a [base-package].dcp file that is visible to the "consuming" package. The "consuming" package is referencing the base-package in its "Requires" section; this is the link to the base package's DCP file.
Delphi Compiled Package File

What are the differences between in .fsx, .fsi and .fs file in F#?

So I'm starting to learn F# from the tryfsharp.org and I'm using VS2013. What are the differences of the .fs (source), .fsx (script) and .fsi (signature)?
.fsx is for individual files intended to run as a script. In particular, in an .fsx file you can use things like #r "Foo.dll" to dynamically load a library and #load "Foo.fsx" to load another script file.
[Edit: and starting with .NET 5, #r "nuget: FooBar" to load a NuGet package.]
.fs is for source files compiled as part of a project.
.fsi is for signature files, they are optional and describe the API of a corresponding .fs file. More detail here.

how to add third party dll reference to F# project?

I'm adding a third party dll reference to my F# project. I added the dll in references and when I use this i.e highlight the code and do Alt+Ent, I get the error "The namespace or module 'AZROLESLib' not defined." Am I missing some thing.
In short, you have to use #r "/path/to/AZROLESLib.dll" in order that F# Interactive recognizes and loads the dll file.
Adding a dll reference helps Visual Studio to find correct libraries when compiling the project, but it has nothing to do with F# Interactive. Therefore, you have to use #r directive to point to AZROLESLib.dll. If VS has some troubles to highlight the code,
you may have to open the exact module in your dll file:
open AZROLESLibModule
If the code is in a *.fs file, you may want to distinguish between using fsi and using fsc:
#if INTERACTIVE
#r "/path/to/AZROLESLib.dll"
#endif
for some things you can call them directly by name with no path
#r "EnvDte"
works for vs2013 here for instance
In my case my F# project was referencing a C# DLL but I had the same issue, "The namespace or module 'MyModule' not defined", when doing "open MyModule".
The solution was to edit the settings to use the same framework (one was using 4.5 and the other 4.0).

integrating cvblobslib in opencv

here I have just started my fyp and ints gona be in opencv.
I needed to vectorize the image and in order to do that I chose to use cvblobslib.
I downloaded it and it was build successfully but when I use it in my project there's a link error saying that "could not open cvblobslib.obj"
the exact string is pasted below
fatal error LNK1104: cannot open file 'E:\Faizan\myWork\moCap\blobslib\Debug\cvblobslib.obj'
of the solutions which I found on net and tried on my project are to remove any spaces in path, build in release mode rather than in debug mode, but problem was not solved.
the thing is that the stated file does not get built with other files when cvblobslib is built, i.e it is not there in the stated folder.
any body please give a solution
What exactly are you trying to use the cvblobslib for? I also tried using this with no luck. I found that openCV has a lot of the same capabilities. For example, you can use cvCountours to detect "blobs" and filter them by area.
(ps. i tried leaving this as a comment. do you need certain amount of rep to do that?)
cvBlobsLib has been developed using Microsoft Visual C++ (6.0) and can also be used in .NET. A Linux version could be downloaded here.
cvBlobsLib is distributed in a static library (.lib). To use it, it is requred that you build the .lib file and later use that lib file in the desired project. To build the .lib file, simply open the MSVC++ project and build it (debug or release version).
To build the project where the library is to be used follow this steps (MSVC++ 6.0):
In Project/Settings/C++/Preprocessor/Additional Include directories add the directory where the blob library is stored
In Project/Settings/Link/Input/Additional library path add the directory where the blob library is stored and in Object/Library modules add the cvblobslib.lib file
Include the file BlobResult.h where you want to use blob variables.
In Project/Settings/C++/Precompiled Headers select Not use precompiled headers
NOTE: Verify that in the project where the cvblobslib.lib is used, the MFC Runtime Libraries are not mixed:
Check in Project->Settings->C/C++->Code Generation->Use run-time library of your project and set it to
Debug Multithreaded DLL (debug version) or to Multithreaded DLL ( release version ).
Check in "Project->Settings->General" how it uses the MFC. It should be "Use MFC in a shared DLL".
NOTE: The library can be compiled and used in .NET using this steps, but the menu options may differ a little
NOTE 2: In the .NET version, the character sets must be equal in the .lib and in the project. [OpenCV yahoo group: Msg 35500]
NOTE 3: cvBlobsLib might give errors when building with OpenCV v2.2 onwards. Try commenting out this line in file BlobLibraryConfiguration.h:
#define _SHOW_ERRORS
NOTE 4: If you are using the new cv::Mat for your images instead of the old IplImage, you can easily convert between them, such as by following the OpenCV C++ Cheatsheet.

Resources