Help: Using Code App on iOS for cross-file C++ programming (I'm a beginner in C++ and not doing particularly complex development)
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.!
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.
What I found that could help https://github.com/holzschu/a-shell/issues/225#issuecomment-849840260
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.
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)