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

Win11 rusty build compiles hello_world sample but does not run as expected #1414

Open
zeehans opened this issue Feb 20, 2025 · 4 comments
Open
Labels
bug Something isn't working

Comments

@zeehans
Copy link

zeehans commented Feb 20, 2025

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?

@zeehans zeehans added the bug Something isn't working label Feb 20, 2025
@ghaith
Copy link
Collaborator

ghaith commented Feb 20, 2025

Hello @zeehans

There are 2 things I notice:

  • You use the -c flag but try to link the application, -c is 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 -c does 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.

@zeehans
Copy link
Author

zeehans commented Feb 20, 2025

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.

@ghaith
Copy link
Collaborator

ghaith commented Feb 21, 2025

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.

@zeehans
Copy link
Author

zeehans commented Feb 21, 2025

@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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants