Compiling LLVM for P2 on Windows (attempt)
Supposedly this can work and have made a bit of progress:
Note: This may be all wrong!
Note2: This is probably a lot easier in Linux or Mac...
Install Visual Studio
- Add C++ Clange tools for Windows
- Add latest Win 11 SDK
Install Python
Install CMake
Install Git
Download LLVM P2
Extract "llvm-project-XXX" to somewhere
Create "build" folder under this folder
Run cmake, maybe like this:
cmake -G "Visual Studio 18 2026" -A x64 -Thost=x64 -DCMAKE_INSTALL_PREFIX=/opt/p2llvm -DLLVM_ENABLE_PROJECTS="lld;clang" -DCMAKE_BUILD_TYPE=Release -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=P2 -DLLVM_TARGETS_TO_BUILD="" ../llvm-project/llvm
Use Visual Studio to open "LLVM.slnx" solution.
Build solution. (takes forever)
Find clang.exe under \build\Release\bin
try to build something like:
clang -Os -ffunction-sections -fdata-sections -fno-jump-tables --target=p2 -I .\libc\include -I .\ -o hello.o -c hello.c
Here's where I'm stuck... Got a .o file but the linker doesn't seem to work :{

Comments
Ok, starting over, something is horribly wrong...
On windows 10 or 11 you can install WSL to get an emulated Linux shell, which probably has higher chance of success with this sort of thing. Getting anything to work with CMake on windows is a hassle, even if it's not a massive project like LLVM.
It might be hopeless... Tried again and can compile but not link (again)...
Found something from 4 years ago where @iseries and maybe me? Got it working in windows …
https://forums.parallax.com/discussion/171962/llvm-backend-for-propeller-2/p5
Will try stuff in post #133 there next…
For linking as a separate step I tend to use Clang twice, with these options:
1) first compile only to get the .o file:
clang -c -Os -ffunction-sections -fdata-sections -fno-jump-tables --target=p2 -I .\libc\include -I .\ -o hello.o -c hello.c2) then link the .o to the .elf (you can combine multiple .o files here too if needed)
clang -v -Wl,-error-limit=0 -L /Users/roger/Applications/p2llvm/libp2/lib --target=p2 -Wl,--gc-sections -o hello.elf -Wl,--no-whole-archive -L /Users/roger/Applications/p2llvm/libc/lib hello.o-v prints actual linker options out,
-Wl,-error-limit=0 prints multiple errors before failing,
--target=p2 (P2 specific output)
-Wl,gc-sections passes --gc-sections to lld linker
-L /path/to/libs (use your path)
-Wl,--no-whole-archive (doesn't suck in the entire lib.a code when only a single function is accessed)
3) use loadp2 to send the .elf file to a P2 (it understands .elfs as well as binary files)
loadp2 -PATCH -f 160000000 -b 115200 -t hello.elfYou can also convert the .elf into a binary file if you want with this:
llvm-objcopy -O binary -j .text -j .rodata -j .data hello.elf hello.binNote this binary also needs to be patched when downloaded with loadp2 as I'm not sure that the LLVM toolchain building the startup code uses useful default startup frequencies or baud rates otherwise. I think it defaults to RCslow unless you call _clkset and _uart_init with some arguments. But if the binary is patched at the normal addresses it will use the desired values.
@rogloh Yeah, but it didn't work... Using Clang twice...
Trying now with that post #133 in other thread, mentioned above.
One hiccup is with this line:
cmake -S llvm -B build -DLLVM_ENABLE_PROJECTS="lld;clang" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=P2 -DLLVM_TARGETS_TO_BUILD="" -DLLVM_COMPILER_JOBS="2" -Thost=x64Had to change llvm to ../llvm Hope that is right...
Says to do this:
Guess these are folders and not files? Don't have libp2.a, but do have folder libp2++...
Somehow got two build folders deep...
path=%path%;c:\opt\p2llvm\llvm-project\build\build\release\bin
Ok, can build, but stuck once again trying to turn .o into .elf:
Hmm ... Seems had same problem back in post #249 of other thread.
Will keep reading in hopes figured it out...
Ok, in post #255 or so seemed just copied the files needed, libc.a and libp2.a, from some link.
But, that link doesn't work anymore
Looking like libc.a and libp2.a have to be built on Linux...
But, think should be portable to Windows, not sure...
The python build script should be building the libp2.a and libc.a files for you. If it can build a customized llvm application which runs under Windows it can then use that to build and archive the lib files into static libraries. I can't see what would prevent it from running on Windows unless there is some config setup error or path error etc and remember that the build directory is not the same as the install directory. That multi-level folder nesting you have for the build folder may possibly have messed things up too given the python script uses these defaults:
DEBUG_BUILD_DIR = "llvm-project/build_debug"
RELEASE_BUILD_DIR = "llvm-project/build_release"
I think you might want to try to use Nikita's actual python script to install things. Windows has python3 available right?
First you need the --configure option to create Cmake settings. Seems like you already had those and built it separately.
Then you basically build everything, and if you do the --install option it will copy the llvm and library files it built in the build folders to the final install folder location nominated after they are built. At least that is what it does for me.
Don't pass the --skip_libc or --skip_libp2 option or it won't build these libraries. If you already have built llvm with Visual Studio you may be able to save time and skip the llvm toolcahin building step to avoid building it again using --skip_llvm option, but you would then also need to ensure that the RELEASE_BUILD_DIR points to the correct location on your PC so it will find the built files there.
In build.py here are the different options:
def main(): global build_dir parser = argparse.ArgumentParser(description='P2 LLVM Build Script') parser.add_argument('--configure', nargs='?', const=True, default=False) parser.add_argument('--skip_llvm', nargs='?', const=True, default=False) parser.add_argument('--skip_libc', nargs='?', const=True, default=False) parser.add_argument('--skip_libp2', nargs='?', const=True, default=False) parser.add_argument('--clean', nargs='?', const=True, default=False) parser.add_argument('--debug', nargs='?', const=True, default=False) parser.add_argument('--install', type=str, required=False) ...UPDATE: I just noticed you were not passing the -L option to nominate where to find the libraries in the linking step - see my prior post above.
C:\opt\p2llvm\llvm-project\build\build\Release>clang --target=p2 -Wl,--gc-sections -Wl,--print-gc-sections -o t0.elf t0.oYou will need to put that path in (relative to your own install folder). Without it there the linker won't know where to find these files. Also I have the p2.ld file present in the top level install folder of p2llvm and it seems to find it okay.
