1、helloworld
#include <stdio.h>
int main(int argc, char **argv)
{
printf("\n************************************************\n");
printf("\n\t\tHello OHOS20210419!\n");
printf("\n************************************************\n\n");
return 0;
}
2、修改Makefile
#CROSS_COMPILE = arm-hisiv400-linux-
CROSS_COMPILE =
ExtLib =
NAME = helloWorld_OHOS
ODIR = output
#=============================================================================#
CFLAGS:=-Wall -Wextra -Wno-unused-parameter -O2 -g --target=arm-liteos -march=armv7-a \
-I./common/inc \
--sysroot=/home/harmony/harmony/code/code-1.0/prebuilts/lite/sysroot
LD = $(CROSS_COMPILE)ld
CC = $(CROSS_COMPILE)clang
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
#============================================================================#
OBJSss := $(wildcard user/*.c) $(wildcard user/*.cpp) \
$(wildcard common/src/*.c) $(wildcard common/src/*.cpp)
OBJSs := $(patsubst %.cpp,%.o,$(OBJSss))
OBJS := $(patsubst %.c,%.o,$(OBJSs))
#============================================================================#
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
%.o: %.cpp
$(CC) $(CFLAGS) -c -o $@ $<
all:$(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $(ODIR)/$(NAME) $(ExtLib) -lm
#============================================================================#
clean:
rm -rf $(OBJS) $(ODIR)/$(NAME)
#============================================================================#
3、NFS挂载通过串口运行
########################################################################################################################
4、Makefile方式组织编译的库移植--参考
使用交叉编译 NFS挂载串口直接运行
5、Makefile文件
#设置交叉编译工具链,确保工具链所在路径已经添加到了PATH环境变量中
CC:=clang
AR:=llvm-ar
#cflags中必须要添加--target及--sysroot选项
CFLAGS:=-Wall -Wextra -Wno-unused-parameter -O2 -g --target=arm-liteos -march=armv7-a --sysroot=/home/harmony/harmony/code/code-1.0/prebuilts/lite/sysroot
.PHONY: clean all test
all: libyxml.a
yxml.c: yxml.c.in yxml-gen.pl yxml-states
perl yxml-gen.pl
libyxml.a: yxml.c yxml.h
$(CC) $(CFLAGS) -I. -c yxml.c
$(AR) rcs libyxml.a yxml.o
test/test: libyxml.a test/test.c
$(CC) $(CFLAGS) -I. test/test.c libyxml.a -o test/test
test: test/test
cd test && sh test.sh
# yxml.c isn't cleaned, since it's included in git
clean:
rm -f yxml.o libyxml.a test/*.test test/test
6、编译
make test OHOS_SYSROOT_PATH=/home/harmony/harmony/code/code-1.0/