04.鸿蒙之helloworld

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方式组织编译的库移植--参考

https://device.harmonyos.com/cn/docs/develop/transplant/oem_thirdparty_transplant_makefile-0000001064218672

使用交叉编译  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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值