Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross Compliation from Windows for Linux target fails #2382

Open
Tracked by #13430
UNIcodeX opened this issue Oct 16, 2019 · 9 comments
Open
Tracked by #13430

Cross Compliation from Windows for Linux target fails #2382

UNIcodeX opened this issue Oct 16, 2019 · 9 comments
Assignees
Labels
Bug This tag is applied to issues which reports bugs. OS: Windows Bugs/feature requests, that are specific to Windows OS. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.
Projects

Comments

@UNIcodeX
Copy link

V version: V 0.1.21 69b4594
OS: Windows 8

What did you do?

// fib_rec.v
pub fn fib_rec(n int) int {
  if n <= 2 {
    return 1
  } else {
    return fib_rec(n-1) + fib_rec(n-2)
  }
}

println(fib_rec(40))

What did you expect to see?
successful build of fib_rec program for Linux target.

What did you see instead?

C compiler=gcc
all .v files:
["C:\V\vlib\builtin\array.v", "C:\V\vlib\builtin\builtin.v", "C:\V\vlib\builtin\float.v", "C:\V\vlib
\builtin\hashmap.v", "C:\V\vlib\builtin\int.v", "C:\V\vlib\builtin\map.v", "C:\V\vlib\builtin\option
.v", "C:\V\vlib\builtin\string.v", "C:\V\vlib\builtin\utf8.v", "C:\V\vlib\strings\builder_c.v", "C:\
V\vlib\strings\similarity.v", "C:\V\vlib\strings\strings.v", "fib_rec.v"]
C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw
32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -ldl
collect2.exe: error: ld returned 1 exit status
V error: C error. This should never happen. Please create a GitHub issue: https://github.com/vlang/v
/issues/new/choose
@UNIcodeX UNIcodeX added the Bug This tag is applied to issues which reports bugs. label Oct 16, 2019
@sdwfrost
Copy link

BTW, cross compilation of the same program from Linux to Windows also seems to break:

`"/home/simon/.vmodules/vlib/builtin.o"` not found

(.vmodules is present, but no compiled modules are there).

@vitalyster
Copy link
Contributor

vitalyster commented Oct 17, 2019

If you have working cross-compiler Windows->Linux in PATH, for example x86_64-linux-gnu-gcc, you can just call v --cc x86_64-linux-gnu-gcc fib_rec.v

@UNIcodeX
Copy link
Author

UNIcodeX commented Oct 17, 2019

That doesn't work for me.

> $ v --cc x86_64-w64-mingw32-gcc fibrec.v                                      
/usr/lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -ldl
collect2: error: ld returned 1 exit status
V error: C error. This should never happen. Please create a GitHub issue: https://github.com/vlang/v/issues/new/choose

Incidentally, to test, since it's a similar project, I tried cross-compilation with Nim via nim c -d:release -d:mingw --opt:speed fib_rec.nim and the resultant executable runs properly in both wine and on a test Windows 8 box.

This at least lets me know that my machine has the proper toolchain to build cross platform executables.

@vitalyster
Copy link
Contributor

vitalyster commented Oct 17, 2019

Yes, something broken for now, but here is the trick:
v -os windows -o fib_rec.c fib_rec.v
(-os windows will do correct C preprocessing there)
x86_64-w64-mingw32-gcc fib_rec.c -o fib_rec.exe

@UNIcodeX
Copy link
Author

UNIcodeX commented Oct 17, 2019

That does work. Thanks for the elaboration.

EDIT: The executable is created, and can be executed, but never prints the output... 🤔

output of ldd fib_rec.exe

$ ldd ./fib_rec.exe
        ntdll.dll => /c/Windows/SYSTEM32/ntdll.dll (0x7ff827db0000)
        KERNEL32.DLL => /c/Windows/system32/KERNEL32.DLL (0x7ff827ab0000)
        KERNELBASE.dll => /c/Windows/system32/KERNELBASE.dll (0x7ff825290000)
        msvcrt.dll => /c/Windows/system32/msvcrt.dll (0x7ff826440000)

@vitalyster
Copy link
Contributor

Known issue with msvcrt.dll, you need to configure mingw with gcc specs to link msvcr90 or later, or comment out _O_U8TEXT line in V code and rebuild (and obviously loose utf-8 support)

@UNIcodeX
Copy link
Author

Alright. Thanks for the info.

@lujfsd
Copy link

lujfsd commented Nov 5, 2019

BTW, cross compilation of the same program from Linux to Windows also seems to break:

`"/home/simon/.vmodules/vlib/builtin.o"` not found

(.vmodules is present, but no compiled modules are there).

I got the same issues, counld you share your idea?

@M4SSD35TRUCT10N M4SSD35TRUCT10N added Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. OS: Windows Bugs/feature requests, that are specific to Windows OS. labels Apr 6, 2020
@M4SSD35TRUCT10N M4SSD35TRUCT10N added this to the Beta Release milestone Apr 6, 2020
@M4SSD35TRUCT10N M4SSD35TRUCT10N added this to Issues, bugs, features and similar in V 0.2 Apr 6, 2020
@M4SSD35TRUCT10N M4SSD35TRUCT10N added the Status: Confirmed This bug has been confirmed to be valid by a contributor. label Apr 6, 2020
@ArtemkaKun
Copy link
Contributor

Actual V (0.3.2) has another problem with this code, but with Clang compiler. Logged here - #17032

@ArtemkaKun ArtemkaKun removed this from the Beta Release milestone May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. OS: Windows Bugs/feature requests, that are specific to Windows OS. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.
Projects
No open projects
V 0.2
  
Issues, bugs, features and similar
Development

No branches or pull requests

7 participants