Nim: On mac, cannot open standard import - nim-lang

I'm using nim on Mac, and am having trouble with this line:
from strutils import parseInt
It gives this error when trying to compile:
csvx.nim(1, 6) Error: cannot open 'strutils'
~/dev/polyglot/csvx/
I installed nim using the "Installation based on generated C code" option.

I got it working by following the "Installation from github" installation option, basically building nim from scratch.
I should note, too, that I created an alias for "nim" that pointed to the build location. Moving the nim executable into my /usr/local/bin caused problems.

Related

Julia integration with VS Code in Linux

I am using Pop_os! system (ubuntu based system) and just installed VS Code. I would like to use Julia with it and installed Julia Extension in the VS Code Extension Marketplace. In the extension settings, I typed in the Julia executable path as where I installed it (in my case is: /opt/julia-1.5.3-linux-x86_64/julia-1.5.3/bin/julia.exe). It is able to run code and print hello world in the output window. However, when I try to click "julia: Execute file" button and run it in Julia REPL, it shows me error message:
Command failed: "/opt/julia-1.5.3-linux-x86_64/julia-1.5.3/bin/" --startup-file=no --history-file=no -e "using Pkg; println(dirname(Pkg.Types.Context().env.project_file))"
/bin/sh: 1: /opt/julia-1.5.3-linux-x86_64/julia-1.5.3/bin/: ***Permission denied***
`"/opt/julia-1.5.3-linux-x86_64/julia-1.5.3/bin/" --startup-file=no --history-file=no -e "using Pkg; println(dirname(Pkg.Types.Context().env.project_file))"` (exited with error code 126)
I noticed in the previous error message it says "permission denied", so I change the path to where the static link is located "/usr/local/bin/julia.exe", but in this case it shows me the same "permission denied" error message.
Does anyone know how to get around this issue?
Thanks!
The cause of the issue is when I installed vs code on linux, I accidentally synced the accounted settings I used in a windows laptop, and that seems to mess up the Julia extension (I used to use Julia extension in windows vs code). I tried uninstall and reinstall vs code, and make sure I don't sync my windows account settings, this time julia extension works for me right after installing it. I don't even need to define any paths.

f2py does not properly import, despite successfully compiling

I am successfully compiling my Fortran subroutine with f2py. However, a folder is created as well as a pyd file.
If I do not put the created pyd file in the generated folder I get this error
ImportError: DLL load failed: The specified module could not be found.
If I put the generated .pyd file in the generated folder, my python script will run, and the import seems to work. However, if I run print(energy_f2py.__doc__) None is the output, and when I try to use the subroutine I get an error AttributeError: module 'energy_f2py' has no attribute 'potential_3'
potential_3 is the name of the subroutine inside energy_f2py.f90
I have also tried making energy_f2py.f90 a module containing the subroutine, with no difference in results.
This is the pyd file that is generated energy_f2py.cp36-win_amd64.pyd. I am using the commandline in Pycharm (windows 10 64 bit) to compile the Fortran file using
f2py -c -m energy_f2py energy_f2py.f90
python -m numpy.f2py -c -m energy_f2py energy_f2py.f90
The same thing happens.
It seems weird to me that both the pyd file is created as well as a folder, see the below image
I am stuck at this point... it seems like it is 95% of the way to working...
Lastly, this other post had a solution saying to name the Python and Fortran modules different names. I have tried this, and it did not make a difference either.
The best solution I found which worked was to partition my hardrive and install Linux. I chose to use Lubuntu, but you could use anything.
Everything works as it should on Linux.
Anther option to is to make it a static build, with the -static flag. This builds everything needed into a single file:
python -m numpy.f2py -c -m energy_f2py energy_f2py.f90 -static
You should then be able to use that .pyd file no matter what folder you've placed it in.
If you are using windows, I think adding --compiler=mingw32 may help. The defualt compiler is msvc on windows.
It occurs to me that the resulting .pyd module is looking for the DLL library in the same directory it itself resides in. Therefore, try moving the DLL from .libs directory to energy_f2py - it worked for me on Windows 10.

collect2.exe: error: ld returned 1 exit status error: command 'C:\\MinGW\\bin\\gcc.exe' failed with exit status 1 [duplicate]

I am currently trying to install Eclipse for making C++ programs.
I've run into an issue when compiling the premade default hello world program.
The console shows this error:
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot find -lpthread
I am not using the library in my program at all.
Any ideas on how to fix this?
Just run and open MinGW Installation Manager, which should be pre-installed with MinGW, select "All Packages" on the left panel, and on the right panel, search for "mingw32-pthreads-w32" packages and install them.
Restart Eclipse, rebuild the project and run it. It should now work.
I had the same problem even with those packages installed. I had to go to mingw\lib and copy the file libpthreadGC-3.a and rename it to libpthread.a and the file libpthreadGC-3.dll.a rename it to libpthread.dll.a
After that it works!
After installing MinGw mingw-gcc-g++, reopen Eclipse, then clear errors. Once all the errors are cleared, try rebuilding your project.
If you also have cygwin installed ... see the question on mingw.org. I ended up with adding 'C:/cygwin/lib' to the settings for the "Library search path (-L)" at properties >> c/c++ build >> settings >> MinGW C Linker >> Libraries.

Error trying to `#require "ctypes.foreign";;` in utop on Windows (Cygwin)

I managed to install and run OCaml + OPAM + utop on Windows (in Cygwin) thanks to the awesome guide by Jonathan Protzenko. In utop, I especially want to be able to use ctypes + ctypes.foreign to quickly experiment and prototype accessing various WinAPI calls. Theoretically, I managed to install the ctypes packages successfully (opam install ... succeeds). Unfortunately, when I try to actually load them in utop, they fail miserably with a surprising error message:
utop # #require "ctypes.foreign";;
Error: Reference to undefined global `Ctypes_closure_properties'
Trying to do the same in rlwrap ocaml gives a somewhat longer error message:
# #require "ctypes.foreign";;
C:\OCaml\lib\unix.cma: loaded
C:\OCaml\lib\bigarray.cma: loaded
C:\OCaml\lib\str.cma: loaded
C:\cygwin64\home\Mateusz\.opam\system\lib\bytes: added to search path
C:\cygwin64\home\Mateusz\.opam\system\lib\ctypes: added to search path
C:\cygwin64\home\Mateusz\.opam\system\lib\ctypes\ctypes.cma: loaded
C:\cygwin64\home\Mateusz\.opam\system\lib\ctypes\ctypes-foreign-base.cma: loaded
Cannot load required shared library dllctypes-foreign-base_stubs.
Reason: dllctypes-foreign-base_stubs.dll: Cannot resolve ffi_type_pointer.
C:\cygwin64\home\Mateusz\.opam\system\lib\ctypes\ctypes-foreign-unthreaded.cma: loaded
Characters -1--1:
#require "ctypes.foreign";;
Error: Reference to undefined global `Ctypes_closure_properties'
Note: full transcript of the sessions is here — it contains output of a utop session in the cmd.exe terminal, and also of an additional rlwrap ocaml session in the Cygwin terminal.
I have absolutely no idea why that happens, or how I could further try to debug/pinpoint/diagnose the situation, so that I could try to find some workaround. (And by the way — I'm a total newbie to OCaml & OPAM, although I'm reasonably experienced in C/C++ and Linux generally.) What follows are some questions I have, that I imagine might hopefully help nudge the problem enough to push me through the roadblock:
Is there a way to tweak a git repo (i.e. ctypes) locally and pass it to OPAM instead of the original github one?
I've managed to google up some comment, which seems to mention that "a static version of libffi" might work, as hinted also in ctypes issue #198; but I'm a total newbie to OCaml, and unfortunately I have no faintest idea how I could apply this suggestion to utop?
How can I tell OPAM which libffi to use for ctypes? (specifically, to use "static libffi"?)
How can I check if the mingw64-x86_64-libffi Cygwin package I do have installed is statically linked, or dynamically? or if both variants are provided, then which one is used by ctypes? I found some answers on SO regarding how to detect if a libffi.a is linked with PIC (?) relocations [-fpic?], but they all seemed really hackish and none of the ones I tried seemed really to work, at least in my case.
Any at all help would be highly appreciated. I don't even know who to ask about this, given it's at a crossing of OCaml, OPAM, utop and Cygwin, all of those being huge and somewhat unrelated/orthogonal systems. I've tried posting the issue on ctypes repo, but all it got over a month's time was a "patches-welcome" label.
mingw64-x86_64-libffi ships with static and dynamic libraries, but the gnu linker will use the dynamic versions by default.
Patching the build of ctypes would be very fiddling (the build system of ctypes is rather complex, a mix of scripts and makefiles). So just try the following: delete the dynamic libraries (/usr/x86_64-w64-mingw32/sys-root/mingw/lib/libffi.dll.a and /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libffi-6.dll), rebuild ctypes and then restore the deleted files.
opam-repository-mingw
By the way: https://fdopen.github.io/opam-repository-mingw/installation/ contains a patched version of flexdll (https://github.com/alainfrisch/flexdll/pull/3 applied - the problem is not specific to libffi) that supports the dynamic and static versions of libffi. opam install ctypes-foreign ctypes utop should work out of the box, if /usr/x86_64-w64-mingw32/sys-root/mingw/bin is in your PATH. Full step-by-step guide below:
Download a 64-bit graphical installer and run it.
After installation completes, start the "Cygwin64 Terminal" (gets installed into Cygwin group in the Start Menu).
Type cygwin-install gui to start the Cygwin Setup/Installer and use it to install some text editor (joe or nano or vim or whatever you prefer).
Use the text editor you installed to edit your ~/.bashrc file, add the following line:
export PATH="/usr/x86_64-w64-mingw32/sys-root/mingw/bin:$PATH"
then execute it in your Cygwin Terminal (just type it in the terminal, or run the following command instead):
$ source ~/.bashrc
Install depext which will auto-download any required OS level (native) dependencies for OPAM packages, the use it to install ctypes and utop:
$ opam install depext depext-cygwinports
$ opam depext -i ctypes-foreign ctypes utop
Switch from Cygwin Terminal to cmd.exe, for example by typing the following command in Cygwin Terminal:
$ cmd /c start cmd
Start utop in cmd.exe terminal, and use it to call the MessageBox WinAPI function as a test that all's working well:
c:> utop
utop # #require "ctypes.foreign";;
utop # let dll = Dl.dlopen ~filename:"user32.dll" ~flags:[];;
val dll : Dl.library = <abstr>
utop # open Ctypes;;
utop # let mb =
Foreign.foreign ~from:dll "MessageBoxA"
(ptr void #-> string #-> string #-> uint #-> returning int) ;;
val mb : unit Ctypes_static.ptr -> bytes -> bytes -> Unsigned.uint -> int =
<fun>
utop # mb null "hello" "world" Unsigned.UInt.zero;;
- : int = 1
utop # #quit;;
c:>
[NOTE: not all of the above utop commands may be required, but that's what worked for me.]

I cannot compile Z3 using Visual C++ & gcc

I'm starter Z3 so my question may be too basic.
But If you let me know some information for my question, I'm very happy.
I searched before history in this site.
But I couldn't get detailed information for me. ( because maybe..my question is too basic..)
[using Visual C++]
1) First of all, I downloaded "z3 4.3.0 for window" at codePlex site.
But this file doesn't have example file(test_capi.c).
So I got "z3-89c1785b73225a1b363c0e485f854613121b70a7.zip" for example file.
( I cannot remember what I can get... :( )
I succeeded compiling python file as codeplex site quide.
But I cannot compile test_capi.c using Visual C++.
I also added "test_capi.c" at "z3 4.3.0 for window" folder but I cannot also compile.
Lastly, I just tried using "test_capi.vcxproj" of "z3-src-4.1.1" and this is succeeded.
I cannot understand.
If i want to test "my file", what file is needed at "z3 4.3.0 for window"?
Or
Do I have to use only "z3 4.1.1" for visual c++ and add "my file" at some location of "z3 4.1.1"? ( All files of Z3 4.1.1 is needed?? AND what is the Some location?)
I read other some comment - "Z3 4.3.0" is simplified.
I understood this comment that I can use only "z3 4.3.0" and test successfully.
But as i told you, I cannot compile.
Please give me some information..
[using gcc in ubuntu]
First of all, I downloaded "z3-4.3.2.07d56bdc705c-x86-ubuntu-12.04.zip" from codeplex site.
Because I tried git command for getting source code but i cannot find source code.
( I also don't know the reason..)
Anyway... "z3-4.3.2.07d56bdc705c-x86-ubuntu-12.04.zip" doesn't have any example file and only bin & include folder is existed.
So I also used "z3 4.1.1" but i cannot compile using below command.
gcc -fopenmp -o test_capi -I ../../Include -L ../../lib test_capi.c -lz3-gmp
Error is "cannot find -lz3-gmp."
In some comment, I found "use "sudo install"" but i don't know how i can install lz3.
(Of course only "sudo install" doesn't work and "sudo apt-get install z3" also doesn't work...)
For compiling "test_capi.c" using gcc, could you explain in detail..?
I'm confused many kinds of guide but i couldn't get basic information for me.
Thank you in advance and I hope to get information...even if my question is too basic..
First, you should use only one version of the source code. Version 4.1.1 is very old and newer versions do not come with test_capi.vcxproj anymore, instead everything is done via the Makefile. For the very latest version please use the unstable branch (e.g., by selecting unstable here and then clicking download.)
The examples can be compiled by calling nmake examples (on Windows) or make examples (on Linux) in the build directory. The makefile has a target called _ex_c_example which shows how to call the compiler for the C example. The various variables that this target uses are defined in build/config.mk. Note that these variables are set to different values on Windows and Linux (this file is produced by python scripts/mk_make.py).
The git command on many Linux distributions is not compatible with the codeplex git server (for a fix see here), but of course this is not necessary if you download the source code from the webpage directly.

Resources