Env

关于scons 编译CPP问题求教

发布于 2016-08-02 13:27:48
我在ubuntu下使用GCC编译 RT_Thread src下面添加自己的say.cpp
代码如下:

#include
using namespace std; //使用命名空间std
extern "C"void printfbysay(void);

void printfbysay(void)
{
std::cout << "string" << "
";
}


头文件
#ifndef __SAY_H__
#define __SAY_H__

void printfbysay(void);

#endif


在FHIPC_General.c文件中调用
#include "FHIPC_General.h"
#include "say.h"

// 业务层启动接口 ...
int FHIPC_Startup(void)
{
printfbysay();
return 0;
}


编译之后报错:

[attach]0[/attach]

sconscript 文件配置如下:

Import('RTT_ROOT')
Import('APP_ROOT')
Import('SDK_ROOT')
Import('rtconfig')
from building import *

mypath = [APP_ROOT + '/inc']
#mypath += [APP_ROOT + '/include/pub']
#mypath += [APP_ROOT + '/include/fh8810sdk']
#mypath += [SDK_ROOT + '/Libraries/inc']

src = Glob('*.c')

src+=['say.cpp']

group = DefineGroup('apidemo', src, depend = [''], LOCAL_CPPPATH = mypath)

Return('group')


为什么不能编译CPP呐
捕获.JPG
cxx.JPG
cxx1.JPG
cxx3.JPG
捕获1.JPG
QQ图片20160805150537.png

查看更多

关注者
0
被浏览
3k
6 个回答
bernard
bernard 2016-08-02
你的rtconfig.py中要把CXX加上,然后在SConstruct中创建Env时也需要把CXX加上,否则用的就是你日志中给出的调用本机的g++,而不是交叉编译器的g++。
Fly
Fly 2016-08-04
你好,感谢你的回复,
我在reconfig.py中添加了如下配置
[attachment=-3]

[attachment=-2]

然后更改SConstruct里面

[attachment=-1]

然后我们在编译C和C++混合工程时出现如下错误:


path==/mnt/hgfs/exchange-2/62_demo/bsp/rt-thread

/mnt/hgfs/exchange-2/62_demo/bsp/rt-thread/kernel
scons: done reading SConscript files.

scons: warning: Support for pre-2.7.0 Python version (2.6.5) is deprecated.
If this will cause hardship, contact scons-dev@scons.org
File "/usr/local/bin/scons", line 199, in
scons: Building targets ...
scons: building associated VariantDir targets: build/bsp build/app
CXX build/app/src/hanzo_recog.o
LINK rtthread.axf
build/app/src/hanzo_recog.o: In function `face_detection':
hanzo_recog.cpp:(.text+0xaf8): undefined reference to `__cxa_end_cleanup'
build/app/src/hanzo_recog.o:(.ARM.extab+0x0): undefined reference to `__gxx_personality_v0'
build/app/src/mycv.o: In function `cvSaveImage(char const*, _IplImage const*)':
mycv.cpp:(.text+0x128c): undefined reference to `operator new[](unsigned int)'
/home/hanzo852/fh8620_sdk/bsp/toolchain/arm-2013.11/bin/../lib/gcc/arm-none-eabi/4.8.1/libgcc.a(unwind-arm.o): In function `get_eit_entry':
unwind-arm.c:(.text+0x20c): undefined reference to `__exidx_end'
unwind-arm.c:(.text+0x210): undefined reference to `__exidx_start'
build/app/src/cvlabel.o: In function `std::_Rb_tree, std::_Select1st >, std::less, std::allocator > >::_M_erase(std::_Rb_tree_node >*)':
cvlabel.cpp:(.text._ZNSt8_Rb_treeIjSt4pairIKjPN3cvb6CvBlobEESt10_Select1stIS5_ESt4lessIjESaIS5_EE8_M_eraseEPSt13_Rb_tree_nodeIS5_E[_ZNSt8_Rb_treeIjSt4pairIKjPN3cvb6CvBlobEESt10_Select1stIS5_ESt4lessIjESaIS5_EE8_M_eraseEPSt13_Rb_tree_nodeIS5_E]+0x24): undefined reference to `operator delete(void*)'
collect2: error: ld returned 1 exit status
scons: *** [rtthread.axf] Error 1
scons: building terminated because of errors.


你所说的创建Env是指在如下地方创建吗

[attach]0[/attach]

如果在我们函数里面调用一个含有指针的C函数,里面就一个空指针,就会报这种错误
unwind-arm.c:(.text+0x20c): undefined reference to `__exidx_end'
unwind-arm.c:(.text+0x210): undefined reference to `__exidx_start'

恳切希望得到指导
bernard
bernard 2016-08-04
嗯,

RT-Thread版本,BSP分支,使用的编译器情况是?如果是服务公司支持客户,请直接使用服务公司的工单系统。
Fly
Fly 2016-08-05
RT_Thread 版本是2.0的,编译器是GCC,我们想在RT_Thread 里面实现C和C++的混合编译,尝试后发现,CPP里面不能使用printf,new等关键字,一使用就报错误:

say.h:

#ifndef __SAY_H__
#define __SAY_H__

#ifdef __cplusplus
extern "C" {
#endif

int add_test(int a,int b);

#ifdef __cplusplus
}
#endif


#endif


say.cpp



/* say.cpp */

#include
#include "say.h"
using namespace std; //使用命名空间std

class CScw
{
public:
int a;
int b;
int add(int a,int b);
};


int CScw::add(int a,int b)
{
return a+b;
}

int add_test(int a,int b)
{

CScw scw;
char *x= new char[1,2,3];
return scw.add(a,b);

}


就会报错:
unwind-arm.c:(.text+0x20c): undefined reference to `__exidx_end'
unwind-arm.c:(.text+0x210): undefined reference to `__exidx_start'
bsp的话:
QQ图片20160805150537.png

给我支持的工程师表示他们没有这样用过,不太清楚,就是不太确定是不是scons配置没有配置好的原因,scons完全看不懂,和网上流传的根本不一样。

弱弱的问一句,RT_Thread 能实现C和C++混合编译吗?
reconfig.py:

mport os

# toolchains options
ARCH = 'arm'
CPU = 'armv6'
OUTPUT_NAME = 'rtthread'
LD_NAME = 'fh881x-evm'
#COMPILE_NAME = 'self_compile_path'


#find the TextBase from .ld file.
Protect_file_path = LD_NAME + '.ld'
P_file = open(Protect_file_path,'r+')
for p_num in range(20):
P_linebuff = P_file.readline()
#print P_linebuff
P_line = P_linebuff.split('=')
if P_line[0] == " TextBase ":
print('p_line[1]: %s',P_line[1])
P_BASE = P_line[1].split(';')
TextBase = P_BASE[0]
print('TextBase:',TextBase)




CROSS_TOOL = 'gcc'
if os.getenv('RTT_CC'):
CROSS_TOOL = os.getenv('RTT_CC')

if CROSS_TOOL == 'gcc':
PLATFORM = 'gcc'
#EXEC_PATH = '/opt/arm-2010q1/bin/'
EXEC_PATH = '/opt/fullhan/toolchain/arm-2013.11/bin'#'/home/zhangj/env/sdk-0.8.20160115/bsp/toolchain/arm-2013.11/bin'
#EXEC_PATH = 'D:/arm-2013.11/bin'
elif CROSS_TOOL == 'keil':
PLATFORM = 'armcc'
EXEC_PATH = 'C:/Keil'
elif CROSS_TOOL == 'iar':
print '================ERROR============================'
print 'Not support yet!'
print '================================================='
exit(0)

if os.getenv('RTT_EXEC_PATH'):
EXEC_PATH = os.getenv('RTT_EXEC_PATH')

print('EXEC_PATH is: %x',EXEC_PATH)



#BUILD = 'debug'
BUILD = 'release'

if PLATFORM == 'gcc':
# toolchains
PREFIX = 'arm-none-eabi-'
#PREFIX = 'arm-none-linux-gnueabi-'
CC = PREFIX + 'gcc'
CXX = PREFIX + 'g++'
AS = PREFIX + 'gcc'
AR = PREFIX + 'ar'
LINK = PREFIX + 'gcc'
TARGET_EXT = 'axf'
SIZE = PREFIX + 'size'
OBJDUMP = PREFIX + 'objdump'
OBJCPY = PREFIX + 'objcopy'

DEVICE = ' -mcpu=arm1176jzf-s -mfpu=vfp -mfloat-abi=soft'

CFLAGS = DEVICE + ' -mno-unaligned-access'

AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp -D__ASSEMBLY__' + ' -DTEXT_BASE=' + TextBase

LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map='+ OUTPUT_NAME +'.map,-cref,-u,_start -T' + LD_NAME +'.ld' + ' -Ttext ' + TextBase

CPATH = ''
LPATH = ''


if BUILD == 'debug':
CFLAGS += ' -O0 -gdwarf-2 '
AFLAGS += ' -gdwarf-2'
else:
CFLAGS += ' -O2 '

CXXFLAGS = CFLAGS

#add lib


POST_ACTION = OBJCPY + ' -O binary ?TARGET '+ OUTPUT_NAME +'.bin
' + SIZE + ' ?TARGET
'



elif PLATFORM == 'armcc':
# toolchains
CC = 'armcc'
AS = 'armasm'
AR = 'armar'
LINK = 'armlink'
TARGET_EXT = 'axf'

DEVICE = ' --device DARMATS9'
CFLAGS = DEVICE + ' --apcs=interwork --diag_suppress=870'
AFLAGS = DEVICE
LFLAGS = DEVICE + ' --strict --info sizes --info totals --info unused --info veneers --list rtthread-at91sam9260.map --ro-base 0x20000000 --entry Entry_Point --first Entry_Point'

CFLAGS += ' -I"' + EXEC_PATH + '/ARM/RV31/INC"'
LFLAGS += ' --libpath "' + EXEC_PATH + '/ARM/RV31/LIB"'

EXEC_PATH += '/arm/bin40/'

if BUILD == 'debug':
CFLAGS += ' -g -O0'
AFLAGS += ' -g'
else:
CFLAGS += ' -O2 '

POST_ACTION = 'fromelf --bin ?TARGET --output rtthread.bin
fromelf -z ?TARGET'



SConstruct:


import os
import sys
import rtconfig

if os.getenv('RTT_ROOT'):
RTT_ROOT = os.getenv('RTT_ROOT')
else:
RTT_ROOT = os.path.normpath(os.getcwd() + '/../bsp/rt-thread/kernel/')

if os.getenv('RTT_PLATFORM_ROOT'):
RTT_PLATFORM_ROOT = os.getenv('RTT_PLATFORM_ROOT')
else:
RTT_PLATFORM_ROOT = ''

if os.getenv('SDK_ROOT'):
SDK_ROOT = os.getenv('SDK_ROOT')
else:
SDK_ROOT = os.path.normpath(os.getcwd() + '/../bsp/rt-thread')


if os.getenv('RT_CONFIG_H'):
RT_CONFIG_H = os.getenv('RT_CONFIG_H')
else:
RT_CONFIG_H = os.path.normpath(os.getcwd() + '/rtconfig.h')

#new add by zhangy to make rtconfig.h could add #include....
rtconfig.PLATFORM_DEF = [ SDK_ROOT + '/platform']

APP_ROOT = os.path.normpath(os.getcwd())

sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
from building import *

TARGET = 'rtthread.' + rtconfig.TARGET_EXT

env = Environment(tools = ['mingw'],
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS,
AR = rtconfig.AR, ARFLAGS = '-rc',
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)

if env['PLATFORM'] == 'win32':
env['ASCOM'] = '$AS $ASFLAGS $CCFLAGS $_CCCOMCOM -o $TARGET $SOURCES'

Export('RTT_ROOT')
Export('RTT_PLATFORM_ROOT')
Export('SDK_ROOT')
Export('APP_ROOT')
Export('rtconfig')
Export('RT_CONFIG_H')

# prepare building environment
objs = PrepareBuilding(env, RTT_ROOT)
objs += SConscript(APP_ROOT + '/SConscript_app',variant_dir='build/app', duplicate=0)
if RTT_PLATFORM_ROOT != '':
rtt_platform_dir = RTT_PLATFORM_ROOT
else:
rtt_platform_dir = SDK_ROOT
objs += SConscript(rtt_platform_dir + '/SConscript',variant_dir='build/rt-thread', duplicate=0)

if GetDepend('RT_USING_WEBSERVER'):
objs = objs + SConscript(RTT_ROOT + '/components/net/webserver/SConscript', variant_dir='build/net/webserver', duplicate=0)

if GetDepend('RT_USING_RTGUI'):
objs = objs + SConscript(RTT_ROOT + '/examples/gui/SConscript', variant_dir='build/examples/gui', duplicate=0)

# libc testsuite
objs = objs + SConscript(RTT_ROOT + '/examples/libc/SConscript', variant_dir='build/examples/libc', duplicate=0)

# make a building
DoBuilding(TARGET, objs)



Sconscript&#058;

# RT-Thread building script for bridge

import os
from building import *

objs = []

Return('objs')

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友