有没有一种直接的方法来创建一个新的 C++ 项目来克隆现有项目的设置?在开发 C++ 时,我喜欢写很多小的测试和示例,但是如果我的代码依赖于外部库,就像他们经常做的那样,我每次都必须从头开始设置包含、库、编译器设置等。是否有某种模板机制?
我知道 C/C++ 项目设置的导出/导入。但是,这似乎只是为 C++ 编译选择包含路径和 #defines。它不导出完整的设置(编译器选项、警告设置、链接器选项、库、库路径等)这一事实确实限制了它的实用性。
此外,您必须为每个运行配置单独执行此操作,尽管这会带来一些不便。
我通常采用的是复制一个测试项目并手动编辑 .project和 .cproject文件,然后 nuking 和替换文件。但这似乎是一个容易出错的黑客。
还有其他方法吗?我是否需要切换到单独的构建系统并在外部生成 eclipse 项目才能拥有看起来非常基本的功能?
更新
我已经尝试创建一个插件项目,但如果您以前没有这样做过,那么这些说明还有很多不足之处。我绝对想弄清楚如何做到这一点。
我以一些非常简单的方式复制并修改了示例模板,只是为了开始,但是“如何使用 CDT 注册项目模板”说明从一开始就让我迷失了:“1. 从 Eclipse 创建一个空插件项目没有源文件夹的工作台。”我认为这需要安装 PDE,我做到了,但后来我迷路了。我尝试了“文件/新建/插件项目”,取消选择“创建 Java 项目”(我认为这就是“空”的意思)。这将创建一个仍然有很多东西的项目。然后我按照步骤 2 中的描述创建了子目录,但不知道如何让这些子目录显示在 Eclipse 中,因此我无法浏览到步骤 11 中的模板 XML 文件。此外,在步骤 9 中/10,我没有得到一个模板“字面命名为“(模板)” - 相反,它创建了一个带有我的模板项目全名的模板。
最佳答案
CDT 具有用于创建新项目的完整模板机制。
基本上,您扩展了 org.eclipse.cdt.core.templates扩展点指向 template.xml文件中有一堆你可以执行的命令。您不需要为此编写任何 Java 代码,但您需要创建一个插件项目。
你可以做的事情的种类:
File | New | | Other... | | Plug-in project ) 
Next/Finish直到完成 
$ find . -type f
./.classpath
./bin/com/example/cdt/templates/Activator.class
./.project
./src/com/example/cdt/templates/Activator.java
./.settings/org.eclipse.jdt.core.prefs
./META-INF/MANIFEST.MF
./build.properties
Extensions标签 org.eclipse.cdt.core.templates Show only extension points [...]复选框org.eclipse.cdt.core.templates来自列表 Finish Yes添加依赖项 
plugin.xml如屏幕截图所示,并在之后的 plugin.xml 代码示例中给出。 
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.cdt.core.templates">
<template
filterPattern=".*gcc"
id="com.example.cdt.templates.template1"
location="template/template.xml"
projectType="org.eclipse.cdt.build.core.buildArtefactType.exe">
</template>
</extension>
</plugin>
template.xml在 plugin.xml 中指定的位置( template/template.xml ) 包含以下内容: <?xml version="1.0" encoding="ISO-8859-1"?>
<template type="ProjTempl" version="1.0" supplier="Stack Overflow"
revision="1.0" author="Jonah Graham" id="EXE" label="Stack Overflow Example"
description="An example for https://stackoverflow.com/questions/33092746/creating-a-new-c-project-in-eclipse-cdt-with-the-same-settings-as-another-proj."
help="help.html">
<process type="org.eclipse.cdt.managedbuilder.core.NewManagedProject">
<simple name="name" value="$(projectName)" />
<simple name="artifactExtension" value="exe" />
<simple name="isCProject" value="true" />
</process>
<process type="org.eclipse.cdt.core.CreateSourceFolder">
<simple name="projectName" value="$(projectName)" />
<simple name="path" value="src" />
</process>
<process type="org.eclipse.cdt.core.AddFiles">
<simple name="projectName" value="$(projectName)" />
<complex-array name="files">
<element>
<simple name="source" value="src/basename.c" />
<simple name="target" value="src/$(projectName).c" />
<simple name="replaceable" value="true" />
</element>
</complex-array>
</process>
<process type="org.eclipse.cdt.ui.OpenFiles">
<simple name="projectName" value="$(projectName)" />
<complex-array name="files">
<element>
<simple name="target" value="src/$(projectName).c" />
</element>
</complex-array>
</process>
<!-- Set -Wall by checking the checkbox in the settings -->
<process
type="org.eclipse.cdt.managedbuilder.core.SetMBSBooleanOptionValue">
<simple name="projectName" value="$(projectName)" />
<complex-array name="resourcePaths">
<element>
<simple name="id" value=".*compiler\.option\.warnings\.extrawarn.*" />
<simple name="value" value="true" />
<simple name="path" value="" />
</element>
</complex-array>
</process>
<!-- Set -Werror by adding textual build settings -->
<process
type="org.eclipse.cdt.managedbuilder.core.SetMBSStringOptionValue">
<simple name="projectName" value="$(projectName)" />
<complex-array name="resourcePaths">
<element>
<simple name="id" value=".*compiler\.option\.misc\.other.*" />
<simple name="value" value="-c -fmessage-length=0 -Werror" />
<simple name="path" value="" />
</element>
</complex-array>
</process>
<!-- Add -lmylibname to libraries to link -->
<process
type="org.eclipse.cdt.managedbuilder.core.AppendToMBSStringListOptionValues">
<simple name="projectName" value="$(projectName)" />
<complex-array name="resourcePaths">
<element>
<simple name="id" value=".*link\.option\.libs.*" />
<simple-array name="values">
<element value="mylibname" />
</simple-array>
<simple name="path" value="" />
</element>
</complex-array>
</process>
</template>
template/src/basename.c $ find . -type f
./.classpath
./template/src/basename.c
./template/template.xml
./bin/com/example/cdt/templates/Activator.class
./.project
./src/com/example/cdt/templates/Activator.java
./.settings/org.eclipse.jdt.core.prefs
./META-INF/MANIFEST.MF
./plugin.xml
./build.properties
Run 菜单 | Run As | Eclipse Application)。您也可以右键单击该项目并选择 Run As | Eclipse Application . 
Building file: ../src/hello2.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -Wextra -c -fmessage-length=0 -Werror -MMD -MP -MF"src/hello2.d" -MT"src/hello2.o" -o "src/hello2.o" "../src/hello2.c"
Finished building: ../src/hello2.c
Building target: hello2
Invoking: GCC C Linker
gcc -o "hello2" ./src/hello2.o -lmylibname
/usr/bin/ld: cannot find -lmylibname
collect2: error: ld returned 1 exit status
make: *** [hello2] Error 1
.cproject文件来确定 id 中的魔法字符串领域。例如,在我的 .cproject为 -Wextra我可以看到这个:<option id="gnu.c.compiler.option.warnings.extrawarn.176373860" name="Extra warnings (-Wextra)" superClass="gnu.c.compiler.option.warnings.extrawarn" value="true" valueType="boolean"/>
template.xml 中转换为此命令:<!-- Set -Wall by checking the checkbox in the settings -->
<process
type="org.eclipse.cdt.managedbuilder.core.SetMBSBooleanOptionValue">
<simple name="projectName" value="$(projectName)" />
<complex-array name="resourcePaths">
<element>
<simple name="id" value=".*compiler\.option\.warnings\.extrawarn.*" />
<simple name="value" value="true" />
<simple name="path" value="" />
</element>
</complex-array>
</process>
gnu.c.compiler.option.warnings.extrawarn.176373860到正则表达式 .*compiler\.option\.warnings\.extrawarn.* .开头是.*以便这适用于 C 和 C++ 编译器选项,因为 C++ id 将以 gnu.cc.compiler[...] 开头然后我用 .* 摆脱了结尾因为在 template.xml 中您不知道编号和后缀关于c++ - 使用与另一个项目相同的设置在 Eclipse CDT 中创建一个新的 C++ 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33092746/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
很好奇,就使用rubyonrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提
假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于
我正在尝试使用ruby和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po