Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
Env
C++_cpp
关于scons 编译CPP问题求教
发布于 2016-08-02 13:27:48 浏览:7899
订阅该版
我在ubuntu下使用GCC编译 RT_Thread src下面添加自己的say.cpp 代码如下: ```c #include
using namespace std; //使用命名空间std extern "C"void printfbysay(void); void printfbysay(void) { std::cout << "string" << " "; } ``` 头文件 ```c #ifndef __SAY_H__ #define __SAY_H__ void printfbysay(void); #endif ``` 在FHIPC_General.c文件中调用 ```c #include "FHIPC_General.h" #include "say.h" // 业务层启动接口 ... int FHIPC_Startup(void) { printfbysay(); return 0; } ``` 编译之后报错: ![捕获.JPG](https://club.rt-thread.org/uploads/9570_93187aa898c72fa5ad9bbd5391f08629.jpg) sconscript 文件配置如下: ```python 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呐 ![cxx.JPG](/uploads/9570_0545da144c0b3c7c215ca3919394ce75.jpg) ![cxx1.JPG](/uploads/9570_8bbb40460efd4f166b792d103a2cf96c.jpg) ![cxx3.JPG](/uploads/9570_68a0bab95e0428af6e2c2f57ad567227.jpg) ![捕获1.JPG](/uploads/9570_e726b07ca886f155c81c39b8bba4bca1.jpg) ![QQ图片20160805150537.png](/uploads/9570_6ebde4dfa09fcce5d68eabd3b7c85d46.png)
查看更多
6
个回答
默认排序
按发布时间排序
bernard
2016-08-02
这家伙很懒,什么也没写!
你的rtconfig.py中要把CXX加上,然后在SConstruct中创建Env时也需要把CXX加上,否则用的就是你日志中给出的调用本机的g++,而不是交叉编译器的g++。
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
2016-08-04
这家伙很懒,什么也没写!
嗯, RT-Thread版本,BSP分支,使用的编译器情况是?如果是服务公司支持客户,请直接使用服务公司的工单系统。
Fly
2016-08-05
这家伙很懒,什么也没写!
RT_Thread 版本是2.0的,编译器是GCC,我们想在RT_Thread 里面实现C和C++的混合编译,尝试后发现,CPP里面不能使用`printf`,`new`等关键字,一使用就报错误: say.h: ```c #ifndef __SAY_H__ #define __SAY_H__ #ifdef __cplusplus extern "C" { #endif int add_test(int a,int b); #ifdef __cplusplus } #endif #endif ``` say.cpp ```c /* 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的话: [attach]2576[/attach] 给我支持的工程师表示他们没有这样用过,不太清楚,就是不太确定是不是scons配置没有配置好的原因,scons完全看不懂,和网上流传的根本不一样。 弱弱的问一句,RT_Thread 能实现C和C++混合编译吗? reconfig.py: ```python 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: ``` # RT-Thread building script for bridge import os from building import * objs = [] Return('objs') ```
bernard
2016-08-05
这家伙很懒,什么也没写!
能混合编译的
撰写答案
登录
注册新账号
关注者
0
被浏览
7.9k
关于作者
Fly
这家伙很懒,什么也没写!
提问
1
回答
2
被采纳
0
关注TA
发私信
相关问题
1
用scons构建代码出现问题
2
求助用scons生成不了mdk工程
3
关于使用scons编译的问题
4
scons编译出现警告信息
5
SCons生成MDK5工程出错
6
realtouch的scons问题
7
SCons的PreAction能用吗?
8
scons 编译时出错。
9
求教:关于scons构建rtt时的两个问题
10
使用scons编译工程出现错误
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
【RT-Thread】记录一次对主仓的bsp进行修复并提交pr的总结
2
【请投票】嵌入式大赛Top10排名等你来选!
3
【24嵌入式设计大赛】HPM5300-EVK 网络测速仪
4
RT-Thread Nano 上线ST CubeMX
5
Nordic移植笔记: RT_Thread v5.1.0(基于Nordic nRF52840的ble_app_hids_mouse工程)
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
ART-Pi
FinSH
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
rt-smart
FAL
ESP8266
I2C_IIC
WIZnet_W5500
ota在线升级
UART
flash
packages_软件包
cubemx
PWM
freemodbus
BSP
潘多拉开发板_Pandora
定时器
ADC
socket
flashDB
中断
Debug
GD32
编译报错
msh
keil_MDK
C++_cpp
rt_mq_消息队列_msg_queue
ulog
at_device
SFUD
本月问答贡献
出出啊
1515
个答案
342
次被采纳
小小李sunny
1438
个答案
289
次被采纳
张世争
785
个答案
168
次被采纳
crystal266
546
个答案
161
次被采纳
whj467467222
1222
个答案
148
次被采纳
本月文章贡献
出出啊
1
篇文章
6
次点赞
小小李sunny
1
篇文章
1
次点赞
张世争
1
篇文章
2
次点赞
crystal266
2
篇文章
1
次点赞
whj467467222
2
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部