Skip to content

Segmentation fault when compile and run a simple code #599

Answered by ghaith
jiguorui asked this question in Q&A
Discussion options

You must be logged in to vote

Hello, thank you for your interest in Rusty!
In order to run the test file, you will need to link it with the crt from musl. The Clang compiler usually does this, but our embedded linker cannot.
You have two ways of doing this:

  • Use the --linker flag to replace the embedded linker with one of your choice --linker=clang-13
  • Compile with -c instead of --static, and then use a compiler of your choice to link the resulting object file.

You can see both compiled files' differences by running nm on them. The first file will only show main while the second one will have additional symbols that get added from including the crt

Hope this helps

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by jiguorui
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants