terralang / terra

Terra is a low-level system programming language that is embedded in and meta-programmed by the Lua programming language.
terralang.org
Other
2.72k stars 201 forks source link

Unable to compile to executable. #433

Closed SrMordred closed 4 years ago

SrMordred commented 4 years ago

Windows 10

terralib.includepath ="D:/msys64/mingw64/x86_64-w64-mingw32/include/";
C = terralib.includec("stdio.h")
terra hello()
    C.printf("Hello, Lua!")
end
terralib.saveobj("helloterra",{ main = hello })

terra main.t

llvm: program not executable

stack traceback:
    [C]: in function 'saveobj'
    C:\projects\terra\src\terralib.lua:4034: in function 'saveobj'
    main.t:6: in main chunk
elliottslaughter commented 4 years ago

I'm hoping one of our Windows users can step in to help debug this, as I don't have a working Windows dev environment.

@SrMordred is this dependent on using printf? If you have a version that just does return 0 or something trivial, does that also fail?

SrMordred commented 4 years ago

Yes, it also fail with just a do nothing function.

SrMordred commented 4 years ago

It may be related to this: https://github.com/terralang/terra/issues/323#issuecomment-538723643 I take a brief look at terralib.lua source and believe that it didnt find where my link.exe path is. (but i thought that it wasnt needed ) Also something i didn´t said before (because i was thinking that maybe was not related. ) when executing terra it give me a error related to not finding a registry path. "ERRO: O sistema não pôde localizar a chave do Registro ou valor especificado." (in Portuguese). If this was the case maybe there is a way to define myself the link.exe path ?

elliottslaughter commented 4 years ago

Are you running in the Visual Studio command prompt? If not can you try that? I believe Terra does require some environment variables that are set by that command prompt and otherwise certain things cannot be made to work. There was a lot of work that went into https://github.com/terralang/terra/pull/411 to fix this, but I believe it still requires the Visual Studio command prompt since newer Visual Studio versions don't set the right (or any) registry keys.

SrMordred commented 4 years ago

I tried to run with "vcvarsall.bat", but it didn´t work. Maybe is my env that is messed up.

SrMordred commented 4 years ago

If i call print(terralib.getvclinker("x64")) i get C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\VC\BIN\x86_amd64\link.exe which is not a path that i have.( Nor do i ever installed vs12)

ErikMcClure commented 4 years ago

This means the vclinker code isn't working properly, but it'll be very hard to figure out why it's broken. Can you try compiling something with clang and see if you still get a problem? If Clang can't find your visual studio linker, we won't be able to either, since our code is based on clang.

SrMordred commented 4 years ago

Yes i can compile with clang properly. Atm my solution is to generate the llvm bitcode and pass it to clang to generate the exe.

ErikMcClure commented 4 years ago

Actually, the beta1 precompiled EXE was never updated by @elliottslaughter. Are you running the precompiled release? It won't have the necessary updates to work with visual studio at all - you have to compile from source.

elliottslaughter commented 4 years ago

Just FYI, we made a new release, so this problem should hopefully go away if you try the new binaries: https://github.com/terralang/terra/releases/tag/release-1.0.0-beta2

SrMordred commented 4 years ago

Yes, its working now, thanks! (although it fails to link libc (printf), but that´s another issue :P )

ErikMcClure commented 4 years ago

if you are having printf issues on windows, refer to this pull request which attempted to fix it before: https://github.com/terralang/terra/pull/414