3

I just learn to work with Nim-Lang. Im running Nim under Windows 10. Compiling my first test program worked well. Also using it with nimpy as a library in Python. Now I generated a build script using the options --genScript:on --nimcache:./nimcache. Running this build script gives the error

clang.exe  -v -shared -o mcpi  stdlib_assertions.nim.c.o stdlib_locks.nim.c.o stdlib_sharedlist.nim.c.o stdlib_formatfloat.nim.c.o stdlib_io.nim.c.o stdlib_system.nim.c.o stdlib_math.nim.c.o stdlib_strutils.nim.c.o stdlib_dynlib.nim.c.o stdlib_winlean.nim.c.o stdlib_times.nim.c.o stdlib_os.nim.c.o @m..@s..@s..@sUsers@sdi29394@s.nimble@spkgs@snimpy-0.1.1@snimpy@spy_types.nim.c.o @m..@s..@s..@sUsers@sdi29394@s.nimble@spkgs@snimpy-0.1.1@snimpy@spy_lib.nim.c.o @m..@s..@s..@sUsers@sdi29394@s.nimble@spkgs@snimpy-0.1.1@snimpy@spy_utils.nim.c.o @m..@s..@s..@sUsers@sdi29394@s.nimble@spkgs@snimpy-0.1.1@snimpy.nim.c.o stdlib_random.nim.c.o @mmcpi.nim.c.o
clang version 11.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\LLVM\bin
 "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\bin\\Hostx64\\x64\\link.exe" -out:mcpi -defaultlib:libcmt "-libpath:C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\lib\\x64" "-libpath:C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\atlmfc\\lib\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.17763.0\\ucrt\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.17763.0\\um\\x64" "-libpath:C:\\LLVM\\lib\\clang\\11.0.0\\lib\\windows" -nologo -dll -implib:mcpi.lib stdlib_assertions.nim.c.o stdlib_locks.nim.c.o stdlib_sharedlist.nim.c.o stdlib_formatfloat.nim.c.o stdlib_io.nim.c.o stdlib_system.nim.c.o stdlib_math.nim.c.o stdlib_strutils.nim.c.o stdlib_dynlib.nim.c.o stdlib_winlean.nim.c.o stdlib_times.nim.c.o stdlib_os.nim.c.o @m..@s..@s..@sUsers@sdi29394@s.nimble@spkgs@snimpy-0.1.1@snimpy@spy_types.nim.c.o @m..@s..@s..@sUsers@sdi29394@s.nimble@spkgs@snimpy-0.1.1@snimpy@spy_lib.nim.c.o @m..@s..@s..@sUsers@sdi29394@s.nimble@spkgs@snimpy-0.1.1@snimpy@spy_utils.nim.c.o @m..@s..@s..@sUsers@sdi29394@s.nimble@spkgs@snimpy-0.1.1@snimpy.nim.c.o stdlib_random.nim.c.o @mmcpi.nim.c.o
Microsoft (R) Incremental Linker Version 14.16.27045.0
Copyright (C) Microsoft Corporation.  All rights reserved.

LINK : fatal error LNK1104: Datei "m..@s..@s..@sUsers@sdi29394@s.nimble@spkgs@snimpy-0.1.1@snimpy@spy_types.nim.c.o" kann nicht geöffnet werden.
clang: error: linker command failed with exit code 1104 (use -v to see invocation)

The file @m..@s..@s..@sUsers@sdi29394@s.nimble@spkgs@snimpy-0.1.1@snimpy@spy_types.nim.c.o is in the directory but obviously the compiler/linker has problems with the leading @. Am I doing something wrong or is there a bug in Nim for Windows?

EDIT:

Code example

import nimpy
import math, random

proc mcpi(nthrows: float): float {.exportpy.} =
  randomize()
  var inside = 0.0
  for i in 1..int64(nthrows):
    if hypot(rand(1.0), rand(1.0)) < 1:
      inside += 1
  result = 4 * inside / nthrows
 
when isMainModule:
    import times
    echo "isMainModule"
    let time = cpuTime() 
    echo mcpi(250000000)
    echo cpuTIme()-time 

Nim command-line call to build a library for Python

c:\bin\nim-1.4.4\bin\nim.exe c -d:release --opt:speed --threads:on --app:lib --tlsEmulation:off --passC:-Ofast --passC:-g0 --passC:-mtune=intel --passC:-msse4.2 --passC:-mmmx --passC:-march=native --out:mcpi.pyd --verbosity:2 --genScript:on --nimcache:./nimcache mcpi.nim  
Michael Hecht
  • 2,093
  • 6
  • 25
  • 37
  • 1
    Hi, I think it would be helpful if you are able to give a small reproducible example. Do you have a simple nim file that you can compile and run fine with standard commands and that you have trouble with using those parameters? I also do suspect that it is the genscript option causing trouble (never used it myself, I think it is not very used in general). you also could look into genscript related issues (both closed and open): https://github.com/nim-lang/Nim/issues?q=is%3Aissue+genscript – pietroppeter Mar 01 '21 at 17:14
  • 1
    also it is better to report which Nim version you are using – pietroppeter Mar 01 '21 at 17:15
  • 1
    and about the downvote, many possible reason for it: https://meta.stackoverflow.com/questions/252677/when-is-it-justifiable-to-downvote-a-question – pietroppeter Mar 01 '21 at 17:19
  • ok, after edit with reproducible example, I can run but I do not find any error, everything seems to run fine and I also find a filename similar to the one reported. one difference, I am using gcc, but I see you probably have somewhere set up nim to use clang. Can you try with gcc? – pietroppeter Mar 01 '21 at 17:45
  • 1
    You ran in the error when type the nim command above or when runing the generated compile_mcpi.bat in nimcache folder? I do not find error in any of those, but the script does not generate a mcpi.pyd file (as requested by nim command, but this request does not appear in compile_mcpi.bat). it does instead generate a mcpi.exe file that when run just hangs there. It seems to me you are trying to automate the generation of a python library from nim, have you checked https://github.com/Pebaz/nimporter for this use case? it is built on nimpy – pietroppeter Mar 01 '21 at 18:04
  • 1
    caveat: i'm on linux, but the compile_mcpi script does create a python library, both with gcc and clang. if i run the script, then change the name of the produced binary to 'mcpi.so' i can import it in python and run it normally. it's important to export the mcpi proc with a * to be able to use it. – shirleyquirk Mar 02 '21 at 02:38
  • please don't cross-post without cross-referencing; you should edit both this issue and https://forum.nim-lang.org/t/7569 to cross reference each other otherwise this leads to wasted duplicate efforts. – timotheecour Mar 02 '21 at 05:24
  • Changing to gcc (downloaded from Nim homepage) I get a lot of errors. That was the reason to change to clang. For example: In file included from CC: stdlib_times.nimC:\Users\Me\nimcache\mcpi_r\stdlib_locks.nim.c:11 : c:\bin\nim-1.4.4\lib/nimbase.h:271:35: error: static assertion failed: "" #define NIM_STATIC_ASSERT(x, msg) _Static_assert((x), msg) ^~~~~~~~~~~~~~ – Michael Hecht Mar 02 '21 at 07:03
  • 1
    that looks like a 32bit/64bit mismatch. – shirleyquirk Mar 02 '21 at 07:48
  • @pietroppeter: nimporter hangs on running of script - see https://github.com/Pebaz/nimporter/issues/43 – Michael Hecht Mar 02 '21 at 13:00
  • 1
    @shirleyquirk: usually I run all languages on 64bit, but with mingw32 and mingw64 subdirectory I'm always confused if it is 32bit or 64bit. I got the mingw version proposed by nim homepage. That should do the job, shouldn't it? – Michael Hecht Mar 02 '21 at 13:01
  • I think Nim website has both version, in the past I did have issues with choosenim picking the wrong mingw, see https://forum.nim-lang.org/t/5985#37054 Regarding nimporter probably it is running in similar issues... – pietroppeter Mar 02 '21 at 16:26
  • On windows it will not work. I tried several approaches. – Michael Hecht Mar 08 '21 at 15:25

0 Answers0