@@ -49,12 +49,6 @@ print_help() {
49
49
echo " "
50
50
echo " Options:"
51
51
echo " -h, --help Show this help message and exit."
52
- echo " "
53
- echo " Examples:"
54
- echo " ./build.sh build # Build for host architecture (will prompt for target)"
55
- echo " ./build.sh build aarch64 # Build for ARM64 (will prompt for target)"
56
- echo " ./build.sh clean # Clean build files"
57
- echo " ./build.sh cross arm-linux-gnueabihf-gcc armv7l # Cross-compile for ARMv7"
58
52
}
59
53
60
54
# --- Handle help command early ---
@@ -274,7 +268,6 @@ build() {
274
268
fi
275
269
fi # End of CI/interactive build type selection
276
270
277
- log_info " Compiling ${SRC_FILE} for ${TARGET_ARCH} using ${COMPILER} ..."
278
271
log_info " Initial compiler flags: ${CFLAGS} "
279
272
280
273
# Special handling for different architectures or cross-compilation
@@ -402,11 +395,23 @@ build() {
402
395
log_info " Final compiler flags: ${CFLAGS} "
403
396
log_info " Final linker flags: ${LDFLAGS} "
404
397
405
- # Compile the source file
406
- " ${COMPILER} " ${CFLAGS} ${TARGET_SPEC} " ${SRC_FILE} " -o " ${BUILD_DIR} /${BIN_NAME} " ${LDFLAGS}
398
+ # --- Two-step build process: Compile to .o, then link .o to executable ---
399
+
400
+ # Step 1: Compile source file to object file
401
+ log_info " Compiling ${SRC_FILE} to object file: ${BUILD_DIR} /${BIN_NAME} .o"
402
+ " ${COMPILER} " ${CFLAGS} ${TARGET_SPEC} -c " ${SRC_FILE} " -o " ${BUILD_DIR} /${BIN_NAME} .o"
403
+
404
+ if [ $? -ne 0 ]; then
405
+ log_error " Compilation to object file failed!"
406
+ exit 1
407
+ fi
408
+
409
+ # Step 2: Link object file to create the executable
410
+ log_info " Linking object file ${BUILD_DIR} /${BIN_NAME} .o to create executable: ${BUILD_DIR} /${BIN_NAME} "
411
+ " ${COMPILER} " " ${BUILD_DIR} /${BIN_NAME} .o" -o " ${BUILD_DIR} /${BIN_NAME} " ${LDFLAGS}
407
412
408
413
if [ $? -eq 0 ]; then
409
- log_success " Compilation successful!"
414
+ log_success " Compilation and Linking successful!"
410
415
log_info " Executable created at: ${BUILD_DIR} /${BIN_NAME} "
411
416
log_info " To run: ./${BUILD_DIR} /${BIN_NAME} <image-file>"
412
417
log_info " Example: ./${BUILD_DIR} /${BIN_NAME} assets/test.jpg"
0 commit comments