2017-04-17 1 views
0

J'ai suivi un tutoriel pour inclure un programme C dans mon image yocto. Cela a fonctionné comme un charme et maintenant j'ai un script helloworld fonctionnant sur ma machine.compiler le programme C++ dans yocto

Je veux faire de même avec C++ car j'ai besoin de charger un programme qui utilise opencv.

J'ai essayé en changeant c avec cpp mais comme je le pensais, il a échoué. Quoi d'autre dois-je changer pour que cela fonctionne? Pouvez-vous me montrer un tutoriel ou un exemple? Je n'ai pas réussi à trouver un modèle approprié avec un exemple simple.

+0

vous ne transformez pas un code c en code C++ en changeant simplement l'extension de fichier – user463035818

+0

Je sais, c'est pourquoi je demande comment modifier l'ordre de compilation sur la recette – user1298272

Répondre

4

On suppose que vous suivez ce video sur la création helloWorld.bb et meta-mylayer

Voici comment vous compiler un fichier C++ dans Yocto:

D'abord, vous devez comprendre ce que le compilateur GNU et construire option drapeau dans Yocto ; En bspdir/sources/poky/meta/conf/bitbake.conf Il y a une liste des compilateurs qui bitbake utilise pour la compilation croisée:

TOOLCHAIN_OPTIONS = " --sysroot=${STAGING_DIR_TARGET}" 

export CC = "${CCACHE}${HOST_PREFIX}gcc ${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}" 
export CXX = "${CCACHE}${HOST_PREFIX}g++ ${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}" 
export FC = "${CCACHE}${HOST_PREFIX}gfortran ${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}" 
export CPP = "${HOST_PREFIX}gcc -E${TOOLCHAIN_OPTIONS} ${HOST_CC_ARCH}" 
export LD = "${HOST_PREFIX}ld${TOOLCHAIN_OPTIONS} ${HOST_LD_ARCH}" 
export CCLD = "${CC}" 
export AR = "${HOST_PREFIX}ar" 
export AS = "${HOST_PREFIX}as ${HOST_AS_ARCH}" 
export RANLIB = "${HOST_PREFIX}ranlib" 
export STRIP = "${HOST_PREFIX}strip" 
export OBJCOPY = "${HOST_PREFIX}objcopy" 
export OBJDUMP = "${HOST_PREFIX}objdump" 
export STRINGS = "${HOST_PREFIX}strings" 
export NM = "${HOST_PREFIX}nm" 
PYTHON = "${@sys.executable}" 

export BUILD_CC = "${CCACHE}${BUILD_PREFIX}gcc ${BUILD_CC_ARCH}" 
export BUILD_CXX = "${CCACHE}${BUILD_PREFIX}g++ ${BUILD_CC_ARCH}" 
export BUILD_FC = "${CCACHE}${BUILD_PREFIX}gfortran ${BUILD_CC_ARCH}" 
export BUILD_CPP = "${BUILD_PREFIX}gcc ${BUILD_CC_ARCH} -E" 
export BUILD_LD = "${BUILD_PREFIX}ld ${BUILD_LD_ARCH}" 
export BUILD_CCLD = "${BUILD_PREFIX}gcc ${BUILD_CC_ARCH}" 
export BUILD_AR = "${BUILD_PREFIX}ar" 
export BUILD_AS = "${BUILD_PREFIX}as ${BUILD_AS_ARCH}" 
export BUILD_RANLIB = "${BUILD_PREFIX}ranlib" 
export BUILD_STRIP = "${BUILD_PREFIX}strip" 
export BUILD_NM = "${BUILD_PREFIX}nm" 

export MAKE = "make" 
EXTRA_OEMAKE = "-e MAKEFLAGS=" 
EXTRA_OECONF = "" 
export LC_ALL = "C" 

Exécuter bitbake -e | grep CXX, vous verrez où le toolchain est directement pointé.

export CXX="arm-poky-linux-gnueabi-g++ -march=armv7-a -marm -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=/mountdata/charles/hio-yocto-bsp/jethro/build/tmp/sysroots/hio-imx6dl-board" 

Maintenant, compris où l'arrière-plan toolchain, nous allons utiliser CXX pour compiler la recette helloworld;

changement meta-mylayer/recipes-example/example/helloworld-0.1/helloworld.c à helloworld.cpp

#include <stdlib.h> 
#include <iostream> 

using namespace std; 

int main() 
{ 
    cout << "hello World "<< endl; 
    return 0; 
} 

et modifier helloworld.bb. prenez note que j'ai changé {CC}-{CXX} et helloworld.c changé helloworld.cpp

SUMMARY = "Simple helloworld application" 
SECTION = "examples" 
LICENSE = "MIT" 
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" 

SRC_URI = "file://helloworld.cpp" 

S = "${WORKDIR}" 

do_compile() { 
     ${CXX} helloworld.cpp -o helloworld 
} 

do_install() { 
     install -d ${D}${bindir} 
     install -m 0755 helloworld ${D}${bindir} 
} 

Maintenant, vous pouvez utiliser bitbake helloworld pour créer le package.

+0

C'est ce que je cherchais. merci pour l'explication détaillée sur les définitions de compilateur! – user1298272