软件01 发表于 2019-5-31 10:23:27

arm-poky-linux-gnueabi-g++和arm-poky-linux-gnueabi-gcc混编Makefile写法

CB140对应cpu为cortex-A7          CB200和CB314 对应cpu为cortex-A9
交叉编译工具用arm-poky-linux-gnueabi-g++和arm-poky-linux-gnueabi-gcc混编

1.新建main.cMakefilemyinclude.htest.cpp

vim main.c
//filename main.c
#include <stdlib.h>
#include <stdio.h>

#include "myinclude.h"

int main()
{
    test_fun();
    return 0;
}


vim test.cpp
//filename test.cpp
#include <iostream>

#include "myinclude.h"

void test_fun()
{
    std::cout<<"hello, this is a c++ test"<<std::endl;
}


vim myinclude.h
//filename myinclude.h
#ifndef MYINCLUDE_H
#define MYINCLUDE_H

#ifdef __cplusplus
extern "C"{//当使用g++编译时,这里将会被编译器识别,使用gcc编译时则跳过,这样这个公共头文件对不同的编译器产生不同的代码
#endif

    void test_fun();

#ifdef __cplusplus
}
#endif

#endif//MYINCLUDE_H


vim Makefile
SRCFILES := test.cpp myinclude.h main.c
OBJFILES := test.o main.o
TARGET=my_cpp

$(TARGET):$(OBJFILES)
      $(CXX) $(OBJFILES) -o $@
$(OBJFILES):$(SRCFILES)
      $(CXX) test.cpp -c\
      $(CC ) main.c -c


.PHONY:
clean:.PHONY
      rm -rf $(OBJFILES) $(TARGET)


2.设置交叉编译工具
MY-IMX6-A9 系列交叉编译工具设置
source /opt/fsl-imx-fb-glibc-x86_64-meta-toolchain-qt5-cortexa9hf-neon-toolchain-4.1.15-2.1.0/environment-setup-cortexa9hf-neon-poky-linux-gnueabi


MY-IMX6-A7 系列交叉编译工具设置
source/home/myzr/my-work/03_toolchain/fsl-imx-x11-glibc-x86_64-meta-toolchain-qt5-cortexa7hf-neon-toolchain-4.1.15-2.1.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi


注意:按CPU型号设置交叉编译工具就行
设置后好,默认设置好CC和CXX
echo $CC
echo $CXX



3.编译
make


页: [1]
查看完整版本: arm-poky-linux-gnueabi-g++和arm-poky-linux-gnueabi-gcc混编Makefile写法