thebaselab / codeapp

Building a full-fledged code editor for iPad
https://code.thebaselab.com
MIT License
2.95k stars 202 forks source link

Why compiling multiple c++ files generates Segmentation fault? #667

Closed shubham-1827 closed 1 year ago

shubham-1827 commented 1 year ago

I have seen an issues, in which you are explaining how to fix this segmentation fault. https://github.com/thebaselab/codeapp/issues/578#issue-1383726389

But, I want the reason why this is working: clang++ main.cpp -c clang++ func.cpp -c clang++ main.o func.o a.out

and this is not working and generating a segmentation fault: clang++ -Wall -std=c++14 -g main.cpp func.cpp

(func.cpp is a file linked to main.cpp)

bummoblizard commented 1 year ago

Hi. It is due to iOS not supporting spawning child processes. The clang compiler tried to fork a subprocess and caused memory issues.

Here's the reference to the upstream issue: https://github.com/holzschu/a-shell/issues/225

bummoblizard commented 1 year ago

Here's is the framework that emulates a fork and other system calls in iOS: https://github.com/holzschu/ios_system Here's the port of clang for iOS: https://github.com/holzschu/llvm-project