Win11 rusty build compiles hello_world sample but does not run as expected
Not sure if this is indeed a bug or just something got mixed up with my setup:
I just pulled the latest master commit and rebuilt rusty on a Win11 machine. I build the hello_world example from the docs using
plc -c main.st -o main.exe --linker=clang
and it completes without an error. When I try to run it from powershell I get:
Program 'main.exe' failed to run: The specified executable is not a valid application for this OS platform.At line:1
I havent been using rusty in a while and used to use a build from an older master commit - probably almost two years old - and was able to compile and run far more complicated code.
Due to a Siemens AX trial installation I know that there was another clang toolchain installed on my system but that one is not on the path and pretty sure I am using the custom LLVM 14.0.6 toolchain.
Any ideas what could be causing this?
Hello @zeehans
There are 2 things I notice:
- You use the
-cflag but try to link the application,-cis compile only, which will skip linking. If you remove the flag you should not be compiling an executable for windows - Second option that might be worth a try if removing the
-cdoes not help is to divide the compile steps in 2, this is because sometimes clang can be configured to use the wrong linker to compile. I don't think it is happening in your case but it's worth a try:
plc -c main.st -o main.o
clang main.o -fuse-ld=lld-link -o main.exe
This will force clang to use the lld-link linker to link the executable.
Right how silly of me re the -c flag. I just tried this without the -c flag
plc main.st main.exe --linker=clang
and get the error message:
clang: error: unable to execute command: program not executable
clang: error: linker command failed with exit code 1 (use -v to see invocation)
An error occurred during linking: An error occured during linking.
Hint: You can use plc explain <ErrorCode> for more information
That is the same error message that I am receiving when building via plc config, eg
plc build config.json --linker=clang
Using your second suggestion,
plc -c main.st -o main.o
clang main.o -fuse-ld=lld-link -o main.exe
I get more useful error output suggesting the following libs need to be linked as well:
lld-link: error: could not open 'libcmt.lib': no such file or directory
lld-link: error: could not open 'oldnames.lib': no such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
libcmt.lib is shipped together with the Win 10 SDK. Not sure where to find oldnames.lib.
could it be that oldnames was removed for win11?
Let's try another approach, can you compile with
clang main.o -o main.exe skipping the lld-link part? this will link with the msvc linker (link.exe) let's see if it does a better job. You can also force it with -fuse-ld=link
I don't have a windows 11 machine at the moment but i'll try doing more tests later with that.
@ghaith just tried your suggestions with -fuse-ld=link and without and in either case the error message is
clang: error: unable to execute command: program not executable
clang: error: linker command failed with exit code 1 (use -v to see invocation)