Compiling C++ with textmate

5.5k views Asked by At

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)
3

There are 3 answers

0
Simon Whitaker On

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.)

1
justin On

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.

0
Clintm On

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