编译 C++与文字伙伴
我在编译包含其他 cpp 文件的 cpp 时遇到问题 所以我有 Main.cpp Numbers.h 和 Numbers.cpp ,似乎 TextMate 只编译我的 Main.cpp 并且不包含其余部分。我尝试使用 xcode,它工作正常。
这是 TextMate cmd+R 的错误:
未定义的符号: “Numbers::Numbers(int)”,引用自: _main 在 ccMrD1Eq.o 中 “Numbers::print()”,引用自: _main 在 ccMrD1Eq.o 中 ld:未找到符号 collect2: ld 返回 1 退出状态
有什么建议吗?
顺便说一句,这是调用的命令:
#!/usr/bin/env ruby
require ENV["TM_SUPPORT_PATH"] + "/lib/tm/executor"
require ENV["TM_SUPPORT_PATH"] + "/lib/tm/save_current_document"
mode = ENV["TM_SCOPE"].slice(/.*?\bsource\.((?:obj)?c(\+\+)?)/, 1)
case mode
when "c"
g = "GCC"
env = "C"
ext = "c"
lang = "c"
when "c++"
g = "GXX"
env = "CXX"
ext = "cc"
lang = "c++"
when "objc"
g = "GCC"
env = "OBJC"
ext = "m"
lang = "objective-c"
when "objc++"
g = "GXX"
env = "OBJCXX"
ext = "mm"
lang = "objective-c++"
end
TextMate.save_current_document(ext)
TextMate::Executor.make_project_master_current_document
flags = ENV["TM_#{env}_FLAGS"] || "-Wall -include stdio.h #{"-include iostream" unless mode[/c\+\+$/].nil?} #{"-framework Cocoa" unless mode[/^obj/].nil?}"
args = [ENV["TM_#{g}"] || g.downcase.gsub("x", "+"), flags + " -x #{lang}", ENV["TM_FILEPATH"]]
TextMate::Executor.run(args, :version_args => ["--version"], :version_regex => /\A([^\n]*) \(GCC\).*/m)
I have problem with compiling cpp that include another cpp files
so I have Main.cpp Numbers.h and Numbers.cpp and it seems that TextMate only compile my Main.cpp and doesn't include the rest. I tried using xcode and it was working fine..
Here is the error from TextMate cmd+R:
Undefined symbols:
"Numbers::Numbers(int)", referenced from:
_main in ccMrD1Eq.o
"Numbers::print()", referenced from:
_main in ccMrD1Eq.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Any suggestion?
Btw, here is the invoked command:
#!/usr/bin/env ruby
require ENV["TM_SUPPORT_PATH"] + "/lib/tm/executor"
require ENV["TM_SUPPORT_PATH"] + "/lib/tm/save_current_document"
mode = ENV["TM_SCOPE"].slice(/.*?\bsource\.((?:obj)?c(\+\+)?)/, 1)
case mode
when "c"
g = "GCC"
env = "C"
ext = "c"
lang = "c"
when "c++"
g = "GXX"
env = "CXX"
ext = "cc"
lang = "c++"
when "objc"
g = "GCC"
env = "OBJC"
ext = "m"
lang = "objective-c"
when "objc++"
g = "GXX"
env = "OBJCXX"
ext = "mm"
lang = "objective-c++"
end
TextMate.save_current_document(ext)
TextMate::Executor.make_project_master_current_document
flags = ENV["TM_#{env}_FLAGS"] || "-Wall -include stdio.h #{"-include iostream" unless mode[/c\+\+$/].nil?} #{"-framework Cocoa" unless mode[/^obj/].nil?}"
args = [ENV["TM_#{g}"] || g.downcase.gsub("x", "+"), flags + " -x #{lang}", ENV["TM_FILEPATH"]]
TextMate::Executor.run(args, :version_args => ["--version"], :version_regex => /\A([^\n]*) \(GCC\).*/m)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
TextMate 仅对您当前正在编辑的 .cpp 文件进行简单编译。与 Xcode 或其他完整开发环境不同,它不会编译项目中的其他源文件或执行链接。
(在 TextMate 中,单击 Bundles > Bundle Editor > Show Bundle Editor,然后在 C 部分中选择 Run,当您“运行”.cpp 文件时,您将确切地看到 TextMate 正在做什么。)
TextMate only does a simple compile of the .cpp file you're currently editing. Unlike Xcode or other full development environments it won't compile other source files in the project or perform linking.
(In TextMate click Bundles > Bundle Editor > Show Bundle Editor, then choose Run in the C section and you'll see exactly what TextMate is doing when you "Run" a .cpp file.)
您可能需要添加其他命令行参数...
您可以通过更改变量 TM_CXX_FLAGS 向 g++ 添加其他命令行参数。
执行此操作的最佳方法可能是添加每个项目变量:
http://manual.macromates.com/en/environment_variables#project_dependent_variables
如果更改是意味着是全局的,您可以将其添加到 TextMate 的静态变量部分
http://manual.macromates.com/en/environment_variables#static_variables
You probably need to add additional command line parameters...
You can add additional command line parameters to g++ by altering the variable TM_CXX_FLAGS.
The best way to do this is probably to add a per project variable:
http://manual.macromates.com/en/environment_variables#project_dependent_variables
If the change is meant to be global you can add it to TextMate's static vars section
http://manual.macromates.com/en/environment_variables#static_variables
我没有足够的信息来确定您正在调用的命令。
如果它是 Xcode.tmbundle Build and Run,那么它正在调用 xcodebuild——您应该能够在 Xcode 中重现并修复错误。
i don't have enough info to be certain of the command you're invoking.
if it's Xcode.tmbundle Build and Run, then it's invoking xcodebuild -- you should be able to reproduce and fix the error in Xcode.