You are not logged in.

#1 2008-06-24 14:16:48

bwayne
Member
Registered: 2007-11-07
Posts: 20

C++ CLI tools

Hi.  I'm taking an introductory programming course at my local university.  I'm learning C++, using Microsoft Visual Studio to compile, execute, and debug my code. 

I know about KDevelop, Eclipse, and Netbeans, but I prefer a command line interface. 

What FOSS tools are available for me to use to edit, compile, link, and debug C++ code in a command line only environment? 


Thanks.

Offline

#2 2008-06-24 14:30:56

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,385
Website

Re: C++ CLI tools

vi, gcc, gdb should do the job.

Offline

#3 2008-06-24 16:34:48

bwayne
Member
Registered: 2007-11-07
Posts: 20

Re: C++ CLI tools

OK.  Why wouldn't the code below compile with gcc while it compiles in MS-VS?
I'm currently attempting this on my OS X machine, though I've had the same errors within Arch and SuSE.   

##begin code#

//hello world
//testing cli tools

#include <iostream>

int main()
{
    std::cout << "Hello world.";
    std::cout << std::endl;
    return 0;
}

##end code##


Here's the error produced


bash-3.2# gcc hello.cpp
Undefined symbols:
  "___gxx_personality_v0", referenced from:
      ___gxx_personality_v0$non_lazy_ptr in ccITpMlu.o
  "std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
      __ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_$non_lazy_ptr in ccITpMlu.o
  "std::ios_base::Init::~Init()", referenced from:
      ___tcf_0 in ccITpMlu.o
  "std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))", referenced from:
      _main in ccITpMlu.o
  "std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
      _main in ccITpMlu.o
  "std::ios_base::Init::Init()", referenced from:
      __static_initialization_and_destruction_0(int, int)in ccITpMlu.o
  "std::cout", referenced from:
      __ZSt4cout$non_lazy_ptr in ccITpMlu.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Offline

#4 2008-06-24 16:45:49

Jessehk
Member
From: Toronto, Ontario, Canada
Registered: 2007-01-16
Posts: 152

Re: C++ CLI tools

GCC (the GNU compiler collection) compiles a variety of languges, but the default is C.

In order to compile C++ code, you can either specify the languge using the -x option and specify that you want to link with libstdc++ or just use the g++ command which does it all for you.

g++ <file>.cpp -o <executable name>

Offline

#5 2008-06-24 16:46:03

PeteMo
Member
From: H'Burg, VA
Registered: 2006-01-26
Posts: 191
Website

Re: C++ CLI tools

You need to use g++ to compile c++ code - g++ hello.cpp should do the trick

Offline

#6 2008-06-24 18:04:37

bwayne
Member
Registered: 2007-11-07
Posts: 20

Re: C++ CLI tools

Right on.  Using g++ compiled fine and the output executed.   

So is gdb a runtime debugger?

Offline

#7 2008-06-24 19:22:03

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: C++ CLI tools

bwayne wrote:

So is gdb a runtime debugger?

It sure is - pretty darn cool one too.

The user manual for GDB is available here - it's decently well written:  http://sourceware.org/gdb/current/onlin … b_toc.html

Offline

#8 2008-06-24 19:50:32

GogglesGuy
Member
From: Rocket City
Registered: 2005-03-29
Posts: 610
Website

Re: C++ CLI tools

PeteMo wrote:

You need to use g++ to compile c++ code - g++ hello.cpp should do the trick

Almost... gcc will compile the *.cpp files as c++. No problem there...
TS is getting a linker error. . It's just that during linking gcc won't add the libstdc++, while g++ will do that for you. So either will work:

g++ hello.cpp -o hello
gcc hello.cpp -o hello -lstdc++

Offline

#9 2008-06-24 20:09:17

bwayne
Member
Registered: 2007-11-07
Posts: 20

Re: C++ CLI tools

Cerebral wrote:

It sure is - pretty darn cool one too.

Awesome.

Cerebral wrote:

The user manual for GDB is available here - it's decently well written:  http://sourceware.org/gdb/current/onlin … b_toc.html

Thank you. 


Any and all resources you've found profitable in your programming career are more than welcome.

Offline

#10 2008-06-24 22:33:24

nj
Member
Registered: 2007-04-06
Posts: 93

Re: C++ CLI tools

valgrind is a nice tool to have. In its simplest and most popular form, it checks for any memory errors in your program. Memory errors can be very annoying to debug, so it can save you a headache or two.

The valgrind project comes with several other tools besides the memory checker, although you probably won't have much use for them when you are just starting out. toofishes has a nice writeup on the massif tool which is worth checking out.

Offline

#11 2008-08-14 23:43:13

bwayne
Member
Registered: 2007-11-07
Posts: 20

Re: C++ CLI tools

OK.  I've been using vim, g++ for a while now.  Im looking to make vim more like an IDE than simply a text editor.  For example, I'd like to be able to write the code and compile in one window. 

I've tried Netbeans and Eclipse to not result but frustration. 

How can I make my vim workflow more fluid?

Offline

#12 2008-08-15 04:37:29

wiremore
Member
Registered: 2005-08-23
Posts: 43

Re: C++ CLI tools

you could use emacs. Type M-x compile (M is meta, same as alt) and then type your compiler command line.

Offline

#13 2008-08-15 04:40:41

wiremore
Member
Registered: 2005-08-23
Posts: 43

Re: C++ CLI tools

vim also has a :make command. You can type ":make foo" to compile your program "foo.cpp." This invokes the "make" command, which you should also learn about.

Offline

#14 2008-08-16 01:43:05

bwayne
Member
Registered: 2007-11-07
Posts: 20

Re: C++ CLI tools

OK.  I've never used emacs.  I appreciate the suggestion but I'm not keen on learning another editor.  I still haven't gotten all the way through vimtutor yet!

So I can compile from within vim.  That gets me part of the way there.  I'm imagining there's some way I can split konsole into multiple windows so that I can have have one for editing/compiling and another for running/debugging.  I'd like to be able to switch between the two modes with a keystroke, not having to take my hands from the keyboard. 

Nothing sucks more than having to click on another term and then having to re-find the main row on the keyboard every time I want to recompile and run.

Offline

#15 2008-08-16 05:20:25

TjPhysicist
Member
From: Waterloo, Canada
Registered: 2008-04-12
Posts: 126
Website

Re: C++ CLI tools

waht i do in vim for small stuff that i dont care to write a Makefile for (so cant do :make <blah blah>). I just do :!g++ <path to file and name>. I even created a little batch file, all i have to do was feed in the path to the c++ file relative to the directory where i keep all my C++ files. So its usually just file names (big projects are inside subfolder, but the got makefiles). and it will compile and execute. vim displays the output underneath the where u typed ' :'. its relatively easy to write up if ure too lazy tell me i can dig up my old one (havent programmed in a while).


So essentially when i am coding a file say, Test.cpp. and i wish to compile and run. All i do is type in (:!cppexecute Test) and the batch file with the help of gcc/g++ will compile, link, clean up object files, and the execute the file created by linkage. I never bothered to write one that tests if the file is C or CPP according to extension and then does the appropriate command. I had 2 batch files Cexecute and Cppexecute. It's not that hard to combine them , again a simple if..then...fi statement. Again if ur too lazy (as i often am) i may be able to dig up the batch file for you. I know i shd have it here somewhere.

-Tj

Last edited by TjPhysicist (2008-08-16 05:24:31)


-Tj
Now reborn as Tjh_ (to keep it similar to my username in other places)

Offline

#16 2008-08-16 06:56:08

neotuli
Lazy Developer
From: London, UK
Registered: 2004-07-06
Posts: 1,204
Website

Re: C++ CLI tools

You may find ddd useful for a more visual interface to gdb.


The suggestion box only accepts patches.

Offline

#17 2008-08-16 17:23:45

bwayne
Member
Registered: 2007-11-07
Posts: 20

Re: C++ CLI tools

Actually, my programs haven't gotten around to the complexity of requiring a run-time debugger.  Most of my bugs are compile-time, with a few being logical (e.g. forgetting to reset the column value to 0 before searching the second row of a 2D array; that one took a little bit to figure out). 

The book I'm using hasn't even gotten to object oriented programming; that's the very last chapter. 

I'll keep ddd in mind, though.  I appreciate the suggestion.

@TjPhysicist
That's an interesting idea.  I'm very new to programming in general so I'd like to see your batch files to study them.  I haven't yet reached the skill level of being able to code a program that accepts arguments from the command line.  I think studying your batches will be useful to me.  Thanks!

Offline

#18 2008-08-18 13:27:56

JacksonEMG
Member
From: ~/
Registered: 2008-08-18
Posts: 2

Re: C++ CLI tools

Well I doubt you will reach .NET work in an introductory programming course (though, every school is different), but I want to suggest you check out http://www.mono-project.com/Main_Page if you ever need to run .NET code on anything outside of Windows and MS Visual Studio. They're usually not as caught up to the actual framework but should do what you need to do.

Offline

#19 2008-08-18 18:06:06

bwayne
Member
Registered: 2007-11-07
Posts: 20

Re: C++ CLI tools

@JacksonEMG

Actually the text that the university is using has a section on .NET at the end of every chapter, comparing the C++ method to the .NET method.  Speaking as a novice programmer, the .NET methods seem useful and sometimes simpler than the analogous C++ way of doing things. 

Also Visual Studio 2005 has pooped out on me, so I'm not even working within Windows or VS anymore.  I've been looking for a good multiplatform IDE but I keep coming back to using vim and cli tools.  Eclipse looks fairly powerful but I don't know how to write makefiles.  And I never seem to get started with Netbeans.  I go through the tutorials but ... meh.  Too dang complicated for a simple program with one source file.

I like the simplicity of the command line tools, though the workflow when using such tools doesn't seem as streamlined.

Offline

#20 2008-08-18 23:59:09

T-Dawg
Forum Fellow
From: Charlotte, NC
Registered: 2005-01-29
Posts: 2,736

Re: C++ CLI tools

PeteMo wrote:

You need to use g++ to compile c++ code - g++ hello.cpp should do the trick

You can also just do 'make' at it will automatically choose the correct compiler to use wink

Offline

#21 2008-08-19 00:51:41

bwayne
Member
Registered: 2007-11-07
Posts: 20

Re: C++ CLI tools

That seems handy.  I'll have to check the man page.

Offline

Board footer

Powered by FluxBB