How lfortran finds subroutine in another file?

No preprocessor.cpp, but a preprocessor. re at \src\lfortran\parser.

\src\lfortran\CMakeLists.txt

set(PARSER_SRC
    parser/preprocessor.cpp
    parser/tokenizer.cpp
    parser/parser.tab.cc
    parser/parser.cpp
    parser/fixedform_tokenizer.cpp

    pickle.cpp
)

build0.bat starts a few commands with python. Don’t know how it works.

WITH_RUNTIME_STACKTRACE is not set in the main CMakeLists.txt

if (WITH_RUNTIME_STACKTRACE)
    set(WITH_UNWIND yes)
    if (APPLE)
        set(WITH_MACHO yes)
    else()
        set(WITH_LINKH yes)
    endif()
    set(HAVE_RUNTIME_STACKTRACE yes)
endif()

I recommend you use the pre-built binary from conda. You can also try to ask an AI for help — it’s super helpful to get almost any project built.

Always have problem to setup conda whatever on my computer.

I tried miniforge, but have error.

@Cean I am sorry about that, it looks like you are installing some PyPy version of conda, I never used that.

Let me try to create exact step-by-step instructions how to install LFortran on Windows, update our docs and then I’ll ask you to try again.

To solve that Fatal error in cpyext, I asked ai. It suggests me to reinstall the python bindings. That results a D:\miniforge-pypy3 folder.

Could you also add links to the dependences, so I don’t need to guess if I am using the right ones.

When I do the configure in cmake-gui, it tells me it needs pandoc. Don’t know if it is bring into by the dependences. I find a pandoc.exe and put it in the PATH, now configure is OK.

Instead of running this from Build from Git section:

conda env create -f environment_win.yml

I run this from Build From a Source Tarball section:

conda create -n lf python cmake llvmdev zstd-static zlib

The later works. But build0.bat needs xonsh. Tried:

pip install 'xonsh[full]'

Not working.

I installed Miniconda and can install new lfortran now.

I tried ‘Build From a Source Tarball’ under conda.

cmake Configuring done.

But ‘make -j8’ says ‘make: *** No targets specified and no makefile found. Stop.’

I think it generate a sln file. So I opened the sln file and compile with VS. There are 7 errors.

Where is file ‘\DIA SDK\lib\amd64\diaguids.lib’ ?

(lf) D:\00masterLib>cd D:\00masterLib\lfortran-0.62.0

(lf) D:\00masterLib\lfortran-0.62.0>cmake -DWITH_LLVM=yes -DCMAKE_INSTALL_PREFIX=`pwd`/inst .
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
-- Could NOT find LibXml2 (missing: LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR)
-- Found LLVM 22.1.4
-- Using LLVMConfig.cmake in: C:/Users/Cean/.conda/envs/lf/Library/lib/cmake/llvm
-- ZLIB LIBRARY PATH: C:/Users/Cean/.conda/envs/lf/Library/lib


Configuration results
---------------------
LFORTRAN_VERSION: 0.62.0
CPACK_PACKAGE_FILE_NAME: lfortran-0.62.0-Windows
C compiler      : C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.43.34808/bin/Hostx64/x64/cl.exe
C++ compiler    : C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.43.34808/bin/Hostx64/x64/cl.exe
Build type: Release
C compiler flags      : /MD /O2 /Ob2 /DNDEBUG
C++ compiler flags    : /MD /O2 /Ob2 /DNDEBUG /bigobj
Installation prefix: D:/00masterLib/lfortran-0.62.0/`pwd`/inst
WITH_LFORTRAN_ASSERT: no
LFORTRAN_STATIC_BIN: no
LFORTRAN_BUILD_TO_WASM: no
WITH_STACKTRACE: no
WITH_RUNTIME_STACKTRACE:
WITH_INTERNAL_ALLOC_CHECK: no
WITH_UNWIND: no
WITH_LIBUNWIND: no
WITH_BFD: no
WITH_LLVM_STACKTRACE: no
WITH_DWARFDUMP: no
WITH_LINKH: no
WITH_MACHO: no
HAVE_LFORTRAN_DEMANGLE: no
WITH_LLVM: yes
WITH_ZSTD: yes
USE_DYNAMIC_ZSTD: no
WITH_MLIR: no
WITH_XEUS: no
WITH_JSON: no
WITH_LSP: no
WITH_FMT: no
WITH_BENCHMARKS: no
WITH_LFORTRAN_BINARY_MODFILES: YES
WITH_RUNTIME_LIBRARY: YES
WITH_WHEREAMI: yes
WITH_ZLIB: yes
USE_DYNAMIC_ZLIB: no
WITH_TARGET_AARCH64: no
WITH_TARGET_X86: yes
WITH_TARGET_WASM: no
WITH_KOKKOS: no
WITH_CCACHE: no
CXXFLAGS: /DWIN32 /D_WINDOWS /W3 /GR /EHsc
CFLAGS: /DWIN32 /D_WINDOWS /W3
-- Configuring done (0.6s)
-- Generating done (2.1s)
-- Build files have been written to: D:/00masterLib/lfortran-0.62.0

compile errors:

My apologies I didn’t have time to write up the detailed instructions yet. Until then, here is how we build every commit on Windows at the CI: lfortran/.github/workflows/Quick-Checks-CI.yml at 659161d2832ebd8ce9dd13f69e225b3461811bde · lfortran/lfortran · GitHub, so at least that I now for sure works. It calls this build script: lfortran/ci/build.sh at 659161d2832ebd8ce9dd13f69e225b3461811bde · lfortran/lfortran · GitHub. Obviously you don’t need to do all the things we do there.

I found C:\Program Files\Microsoft Visual Studio\2022\Community\DIA SDK\lib\amd64\diaguids.lib

But some vcxproj files reference it as \DIA SDK\lib\amd64\diaguids.lib only. After add the full path, it is found correctly.

Now the compile error is:

unresolved external symbol __std_find_first_of_trivial_pos_1

AI says need to update VS.

after update VS, only 3 errors now.

Now build build_runtime, has this ‘Lead underscore not allowed’ error.

version = _lfortran_compiler_version() ! note: LFortran takes this and creates an IntrinsicElementalFunction

Though build_runtime & configure_runtime are not built, but lfortran is built successfully. It is located at D:\00masterLib\lfortran-0.62.0\src\bin.

When run, it needs a few dlls.

zstd.dll
zlib.dll
msys_2.0.dll
msys_perl5_38.dll
msys-gcc_s-seh-1.dll
msys-crypt-2.dll

After find and copy these dlls in, lfortran runs.

But the VS link doesn’t work. Need to setup right.

lfortran.exe is 50.8MB, so big.

the test_lfortran also built successfully.

Yes, I think most of it is LLVM. I am not happy about it either, and eventually for Debug builds we’ll get our own backends up and running and they will be much smaller. For Release builds LLVM is the best by far, so it’s good to keep it.

Can find link now, but still not work yet.

I found a lfortran_runtime_static.lib at D:\00masterLib\lfortran-0.62.0\src\runtime\legacy\Release\lfortran_runtime_static.lib.

Why under legacy folder?

I copied it to ‘D:\bjbin..\lib\lfortran_runtime_static.lib’. My lfortran is started at D:\bjbin.

Still not work.

Maybe I still need to build the build_runtime.

There are a few function pairs like these two in src\runtime\purelfortran_intrinsic_ieee_arithmetic.f90 has this error 5286.

Ambiguous generic interface IEEE_SUPPORT_DENORMAL: previously declared specific procedure SPIEEE_SUPPORT_DENORMAL is not distinguishable from this declaration. [DPIEEE_SUPPORT_DENORMAL]

AI corrected them with Remove OPTIONAL, use explicit kinds.

    ! IEEE_SUPPORT_DENORMAL
    pure function spieee_support_denormal(x) result(r)
        use iso_fortran_env, only: real32
        real(real32), intent(in) :: x  ! REQUIRED - NOT optional
        logical :: r
        ! Most modern hardware supports denormals
        r = .true.
    end function

    pure function dpieee_support_denormal(x) result(r)
        use iso_fortran_env, only: real64
        real(real64), intent(in) :: x  !Remove OPTIONAL, use explicit kinds
        logical :: r
        r = .true.
    end function

Now only two errors left when build runtime.

File: src\runtime\pure\lfortran_intrinsic_iso_c_binding.f90

Error 6683: A kind type parameter must be a compile-time constant. [C_SIZE_T]

AI corrected it with Use the actual kind value directly

    !integer(c_size_t) function c_sizeof(x)
    !!type(*), intent(in) :: x
    !integer, intent(in) :: x
    !end function
    
    integer(8) function c_sizeof(x)  ! Use the numeric kind directly
        integer, intent(in) :: x
    end function

Now I have successfully build runtime lib. Is this one the right one? D:\00masterLib\lfortran-0.62.0\src\runtime\legacy\Release\lfortran_runtime_static.lib