codeapp icon indicating copy to clipboard operation
codeapp copied to clipboard

Help: Using Code App on iOS for cross-file C++ programming (I'm a beginner in C++ and not doing particularly complex development)

Open suiyutong61 opened this issue 10 months ago • 4 comments

Help: Using Code App on iOS for cross-file C++ programming (I'm a beginner in C++ and not doing particularly complex development) Does the Code App on the iOS App Store support cross-file programming? For example, a folder containing myhead.h (function declarations), myfunction.cpp (function definitions), and main.cpp (a main function that calls the functions declared in myhead.h and defined in myfunction.cpp). If there is a way to achieve cross-file programming, please help me out. I don’t know how to properly compile and run files across multiple sources. I tried entering commands in the terminal (the command was clang++ main.cpp my.cpp -o myPro), but the terminal kept reporting errors.!

suiyutong61 avatar Jan 19 '26 19:01 suiyutong61

Does the Code App on the iOS App Store support cross-file programming? For example, a folder containing myhead.h (function declarations), myfunction.cpp (function definitions), and main.cpp (a main function that calls the functions declared in myhead.h and defined in myfunction.cpp). If there is a way to achieve cross-file programming, please help me out. I don’t know how to properly compile and run files across multiple sources. I tried entering commands in the terminal (the command was clang++ main.cpp my.cpp -o myPro), but the terminal kept reporting errors.

suiyutong61 avatar Jan 19 '26 19:01 suiyutong61

What I found that could help https://github.com/holzschu/a-shell/issues/225#issuecomment-849840260

Jakubpoland avatar Feb 14 '26 12:02 Jakubpoland

You can use clang to compile the files manually; however, it is a must-have feature for C++ programmers to run a program with multiple .cpp files directly from the Code app. Hopefully, the developers will add this feature in a future version.

carinconc avatar Feb 18 '26 21:02 carinconc

You can write a simple build script like this:

mkdir -p build/obj
clang++ <CLANG-OPTIONS> -c -o build/obj/<file1>.obj src/<file1>.cpp
# ... do this for every source file

clang++ <CLANG-OPTIONS> -o build/<bin> <files paths for bin in build/obj>

The first clang calls only compile the sources into linkable object files (don't know if there is a difference using wasm) and the last call builds it into one "executable" (wasm) file

Example:

src/
 - main.cpp
 - helper.hpp
 - helper.cpp

could be compiled using:

mkdir -p build/obj
# helper.cpp
clang++ -Wall -Wextra -c -o build/obj/helper.obj src/helper.cpp
# main.cpp
clang++ -Wall -Wextra -c -o build/obj/main.obj src/main.cpp


clang++ -o build/example build/obj/helper.obj /build/obj/main.obj

use clang instead of clang++ for C

but since running sh script (after trying) doesn't currently seem to be supported you can just put this in a python script, which executes each command (this can also simplify the process of adding new files to the build)

Knoficooki avatar Feb 21 '26 10:02 Knoficooki