📄 c-wfc2.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><link rel="STYLESHEET" type="text/css" href="wrs.css"><title> C++ Development </title></head><body bgcolor="FFFFFF"><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="GuideIX.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-wfc.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-wfc1.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-wfc3.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p><font face="Helvetica, sans-serif" class="sans"><h3 class="H2"><i><a name="84385">5.2 C++ Development Under Tornado</a></i></h3></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84386"> </a>Basic C++ support is bundled with the Tornado development environment. VxWorks provides header files containing C++ safe declarations for all routines and the necessary run-time support. The standard Tornado interactive development tools such as the debugger, the shell, and the incremental loader include C++ support. </p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84387">5.2.1 Tools Support</a></i></h4></font><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84388">WindSh </a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84390"> </a>Tornado supports both C and C++ as development languages. WindSh can interpret simple C++ expressions. To exercise C++ facilities that are missing from the C-expression interpreter, you can compile and download routines that encapsulate the special C++ syntax. See the <i class="title">Tornado User's Guide: Tornado Tools Reference</i> or the HTML online reference for WindSh C++ options.</p></dl></dl><dl class="margin"><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="84392">Demangling</a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="84393"> </a>When C++ functions are compiled, the class membership (if any) and the type and number of the function's arguments are encoded in the function's linkage name. This is called <i class="term">name mangling</i> or <i class="term">mangling</i>. The debugging and system information routines in WindSh can print C++ function names in demangled or mangled representations. </p><dd><p class="Body"><a name="84395"> </a>The default representation is <b class="symbol_lc">gnu</b>. In addition, <b class="symbol_lc">arm</b> and <b class="symbol_lc">none</b> (no demangling) are available options. To select an alternate mode, modify the Tcl variable <b class="tclProc">shDemangleStyle</b>. For instance:</p><dl class="margin"><dd><pre class="Code2"><b><a name="84396"></b><tt class="output">-></tt><b> ?set shDemangleStyle none</a></b></pre></dl></dl><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="84397">Overloaded Function Names</a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="84398"> </a>When you invoke an overloaded function, WindSh prints the matching functions' signatures and prompts you for the desired function. For more information on how WindSh handles overloaded function names, including an example, see the <i class="title">Tornado User's Guide: Shell</i>.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84400">Debugger</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84402"> </a>The Tornado debugger supports debugging of C++ class member functions including stepping through constructors and templates. For details, see the <i class="title">Tornado User's Guide: Tornado Tools Reference</i> and <i class="title">Debugging with GDB</i>.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84404">5.2.2 Programming Issues</a></i></h4></font><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="85508">Making C++ Entry Points Accessible to C Code</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="85509"> </a>If you want to reference a (non-overloaded, global) C++ symbol from your C code you will need to give it C linkage by prototyping it using <b class="symbol_lc">extern "C"</b>:</p><dl class="margin"><dd><pre class="Code2"><b><a name="85514">#ifdef __cplusplus extern "C" void myEntryPoint (); #else void myEntryPoint (); #endif</a></b></pre></dl><dd><p class="Body"><a name="85520"> </a>You can also use this syntax to make C symbols accessible to C++ code. VxWorks C symbols are automatically available to C++ because the VxWorks header files use this mechanism for declarations.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="85507">5.2.3 Compiling C++ Applications</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84406"> </a>The Tornado project tool fully supports C++. The recommended way to configure and compile C++ applications is to use the project tool. The information below may be useful for understanding the C++ environment but unless you have a particular reason to use manual methods, you should use the methods explained in the <i class="title">Tornado User's Guide: Projects</i>.</p><dd><p class="Body"><a name="84407"> </a>For details on the GNU compiler and on the associated tools, see the <i class="title">GNU ToolKit User's Guide</i>. </p><dd><p class="Body"><a name="84408"> </a>When compiling C++ modules with the GNU compiler, invoke <b class="command">cc</b><i class="textVariable">arch</i> (just as for C source) on any source file with a C++ suffix (such as <b class="file">.cpp</b>). Compiling C++ applications in the VxWorks environment involves the following steps:</p></dl><dl class="margin"><p><ol class="List"><li value="1."><a name="84409"> </a>Each C++ source file is compiled into object code for your target architecture, just as for C applications. For example, to compile for a 68K target:</li></ol></p><dl class="margin"><dl class="margin"><dd><pre class="Code3"><b><a name="85872">cc68k -fno-builtin -I$WIND_BASE/target/h -nostdinc -O2 \ -DCPU=MC68040 -c foo.cpp cc68k -fno-builtin -I$WIND_BASE/target/h -nostdinc -O2 \ -DCPU=MC68040 -c bar.cpp</a></b></pre></dl></dl><p><ol class="List"><li value="2."><a name="84410"> </a>The objects are munched (see <a href="c-wfc2.html#84479"><i class="title">5.2.5 Munching C++ Application Modules</i></a>). In our example:</li></ol></p><dl class="margin"><dl class="margin"><dd><pre class="Code3"><b><a name="85887">nm68k foo.o bar.o | wtxtcl $WIND_BASE/host/src/hutils/munch.tcl \ -asm 68k > ctdt.c cc68k -c ctdt.c</a></b></pre></dl></dl><p><ol class="List"><li value="3."><a name="84411"> </a>The objects are linked with the compiled munch output. (They may be partially linked using <b class="command">-r</b> for downloadable applications or statically linked with a VxWorks BSP for bootable applications.) If you are using the GNU tools, invoke the linker from the compiler driver as follows:</li></ol></p><dl class="margin"><dl class="margin"><dd><pre class="Code3"><b><a name="85905">cc68k -r ctdt.o foo.o bar.o -o linkedObjs.o</a></b></pre></dl></dl><dl class="margin"><dd><div class="Indent"><a name="85907"> </a>Here we have linked two objects modules, <b class="file">foo.o</b> and <b class="file">bar.o</b>, to give a downloadable object, <b class="file">linkedObjs.o</b>. Using cc<i class="textVariable">arch</i> rather than ld<i class="textVariable">arch</i> performs template instantiation if you use the <b class="command">-frepo</b> option. (see <a href="c-wfc2.html#84565"><i class="title">5.2.7 Template Instantiation</i></a>).</div><br></dl></dl></dl><dl class="margin"><dd><p class="table" callout><table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td valign="top" width="40"><br><img border="0" alt="*" src="icons/note.gif"></td><td><hr><div class="CalloutCell"><a name="85039"><b class="symbol_UC"><font face="Helvetica, sans-serif" size="-1" class="sans">NOTE: </font></b></a>If you use a Wind River Systems makefile to build your application, munching is handled by <b class="command">make</b>. </div></td></tr><tr valign="top"><td></td><td><hr></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p callout><dd><p class="table" callout><table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td valign="top" width="40"><br><img border="0" alt="*" src="icons/warning.gif"></td><td><hr><div class="CalloutCell"><a name="85058"><b class="symbol_UC"><font face="Helvetica, sans-serif" size="-1" class="sans">WARNING: </font></b></a>In the linking step, <b class="operator">-r</b> is used to specify partial linking. A partially linked file is still relocatable, and is suitable for downloading and linking using the VxWorks module loader. The <i class="title">GNU ToolKit User's Guide: Using ld</i> describes a <b class="operator">-Ur</b> option for resolving references to C++ constructors. That option is for native development, not for cross-development. Do not use <b class="operator">-Ur</b> with C++ modules for VxWorks.</div></td></tr><tr valign="top"><td></td><td><hr></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p callout></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84436">5.2.4 Configuration Constants</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84439"> </a>By default VxWorks kernels contain the C++ run-time, basic Iostream functionality and support for the Standard Template Library. You may add/remove C++ components by including any of the following macros: </p></dl><dl class="margin"><dd><div class="Item"><a name="84441"> </a><b class="symbol_UC">INCLUDE_CPLUS</b> </div><dl class="margin"><dd><div class="Indent"><a name="84442"> </a>Includes all basic C++ run-time support in VxWorks. This enables you to download and run compiled and munched C++ modules. It does not configure any of the Wind Foundation Class libraries into VxWorks.</div><br></dl><dd><div class="Item"><a name="84444"> </a><b class="symbol_UC">INCLUDE_CPLUS_STL</b></div><dl class="margin"><dd><div class="Indent"><a name="84445"> </a>Includes support for the standard template library.</div><br></dl><dd><div class="Item"><a name="84447"> </a><b class="symbol_UC">INCLUDE_CPLUS_STRING</b></div><dl class="margin"><dd><div class="Indent"><a name="84448"> </a>Includes the basic components of the string type library.</div><br></dl><dd><div class="Item"><a name="84450"> </a><b class="symbol_UC">INCLUDE_CPLUS_IOSTREAMS</b></div><dl class="margin"><dd><div class="Indent"><a name="84451"> </a>Includes the basic components of the Iostream library.</div><br></dl><dd><div class="Item"><a name="84453"> </a><b class="symbol_UC">INCLUDE_CPLUS_COMPLEX</b></div><dl class="margin"><dd><div class="Indent"><a name="84454"> </a>Includes the basic components of the complex type library.</div><br></dl><dd><div class="Item"><a name="84456"> </a><b class="symbol_UC">INCLUDE_CPLUS_IOSTREAMS_FULL</b></div><dl class="margin"><dd><div class="Indent"><a name="84457"> </a>Includes the full Iostream library; this implies <b class="symbol_UC">INCLUDE_CPLUS_IOSTREAMS</b>.</div><br></dl><dd><div class="Item"><a name="84459"> </a><b class="symbol_UC">INCLUDE_CPLUS_STRING_IO</b></div><dl class="margin"><dd><div class="Indent"><a name="84460"> </a>Includes string I/O function; this implies <b class="symbol_UC">INCLUDE_CPLUS_STRING</b> and <b class="symbol_UC">INCLUDE_CPLUS_IOSTREAMS</b>.</div><br></dl><dd><div class="Item"><a name="84462"> </a><b class="symbol_UC">INCLUDE_CPLUS_COMPLEX_IO</b></div><dl class="margin"><dd><div class="Indent"><a name="84463"> </a>Includes I/O for complex number objects; this implies <b class="symbol_UC">INCLUDE_CPLUS_IOSTREAMS</b> and <b class="symbol_UC">INCLUDE_CPLUS_COMPLEX</b>.</div><br></dl></dl><dl class="margin"><dd><p class="Body"><a name="84464"> </a>To include one or more of the Wind Foundation Classes, include one or more of the following constants:</p></dl><dl class="margin"><dd><div class="Item"><a name="84466"> </a><b class="symbol_UC">INCLUDE_CPLUS_VXW</b></div><dl class="margin"><dd><div class="Indent"><a name="84467"> </a>Includes the VxWorks Wrapper Class library.</div><br></dl><dd><div class="Item"><a name="84469"> </a><b class="symbol_UC">INCLUDE_CPLUS_TOOLS</b></div><dl class="margin"><dd><div class="Indent"><a name="84470"> </a>Includes Rogue Wave's Tools.h++ class library.</div><br></dl></dl><dl class="margin"><dd><p class="Body"><a name="84477"> </a>For more information on configuring VxWorks, see the <i class="title">Tornado User's Guide: Projects</i>.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84479">5.2.5 Munching C++ Application Modules</a></i></h4></font><dl class="margin"><dl class="margin">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -