The cross-compilation tool uses ARM-poky-linux-gnueabi-g++ and arm-poky-linux-gnueabi-gcc for mixed compilation
1. Create new main.c Makefile myinclude.h test.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"{ //When using g++ to compile, this will be recognized by the compiler, and when using gcc to compile, it will be skipped, so that this public header file generates different codes for different compilers
#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. Set up cross compilation Tools
A9 series cross-compilation tool settings
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
A7 series cross compilation Tool settings
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
Note: Just set the cross-compilation tool according to the CPU model.
After setting, CC and CXX are set by default.
echo $CC
echo $CXX
3. Compile
make
|