step into system, CRTL functions with Eclipse in Linux - c++

I'm a whiz with Visual C++, but Linux development is new to me. In Visual Studio, it's easy to trace into any code implemented by the C run time libraries. I just need to make sure the sources are installed and I can step right into any function I'd like -- malloc(), cout::operator<<(), whatever.
I'm trying to develop using Eclipse's C++ package. How can I step into C run time routines there? Since Linux is open-source, how do I step into operating system routines? Seems like it should e possible -- am I missing debug information, source code, or both? Something in my configuration?
I'm using Ubuntu 12.10 at the moment. I'm using g++. I believe I'm using the Eclipse build system as I never imported a makefile project; I just started with a simple "Hello World" project from the C++ project wizard in Eclipse.
After hacking at this a bit:
I've installed the libstdc++6-4.2-dbg package thinking it would be debug symbols for the libstdc library:
sudo apt-get install libstdc++6-4.2-dbg
I've also installed dpkg-dev, since the next step said I needed it:
sudo apt-get install dpkg-dev
I tried installing libc6 sources into a directory under my home:
apt-get source libc6
At this point, trying to step into printf() tells me that printf.c is missing. I can't step into malloc or strlen, which suggests that I don't understand how the C runtime libraries are factored in Linux. How are libc, glib, and libstdc++ different? Which packages do I need?
If I ask Eclipse to open the printf.c file I do have (at ~/eglibc-2.15/stdio-common/printf.c), it doesn't open the file (doesn't adjust the debugging window to show the source) and repaints the window that shows the error message about not being able to find the file. (Can't find a source file at "printf.c" Locate the file or edit the source lookup path to include its location.)

Whilst, as a Kernel developer on Linux, I do agree that using the individual tools separately will be a good thing to learn, and as such Basile's answer is usefuel.
However, the stepping into C runtime libraries should be equally possible with Eclipse. But just because the OS is open source doesn't mean that it supports you clambering around inside it willy nilly - in fact, you CAN NOT step into the OS itself from user-mode code. You nee KGDB (google it), and you definitely need a second computer to attach to the one being debugged, because when you step into the kernel, you will essentially lock up the machine, at the very least in the context you are stepping, but most likely also prevent other work from being done until you get back out from the kernel, so for example, if you step into open(), at some point the entire filesystem may well stop working altogether until you are back out of whatever lock you are holding. This wll certainly upset some software. Note that this is just an example of how things may work unexpectedly when debugging the kernel, not strictly "I've done this and it happened" - I have debugged kernels with debuggers several times, and you do have to be careful with what you do, and you certainly can not run the debugger on the same machine, as the machine STOPS when you are debugging.
Going back to the usermode, which you CAN debug via Eclipse, essentially all you need to do is install the source code for the runtime library you are interested in, and go... Same principle as on Windows with visual studio - except that nearly all software you ever run on a Linux system is available as source code. You may need to recompile some libraries with debugging symbols, and just like in Windows, you need to make sure the debugger knows how to find the source code. Everything else should be handled by the debugger in Eclipse. I spent about three years using Eclipse for both local and remote debugging, and in general, it works. There are quirks in places, but that's the case with almost any debugger.
Good luck.

First, you don't need Eclipse to develop software on Linux. You should better learn to do that with independent tools (command line) like emacs or gedit (as editor), git (version control), make (builder) which runs the gcc or g++ compiler (both gcc & g++ are part of GCC, the Gnu Compiler Collection).
really, you'll learn a lot more by not depending upon Eclipse; it may just hide you the real commands which are doing the job, and you should understand what they really are.
You want to pass the -g -Wall options to GCC. The -g option asks for debug information, and the -Wall options asks for almost all warnings. Improve your code till no warnings are given.
And the operating system is providing syscalls (which are operations provided by the kernel to applications; from the application's point of view, a syscall is atomic so you cannot step into it; however strace may show you all the syscalls done by some execution). If you wanted to step by step inside system libraries like libc you need the debugging variant of it (e.g. some libc6-dbg package). But there is usually no need to dive inside system libraries.
See http://advancedlinuxprogramming.com/
Then, you will use gdb to debug the binary program.
So, step by step instructions inside a terminal:
edit your source files with emacs or gedit
learn how to use GCC: for a single source C++ program compile it with g++ -Wall -g source.cc -o progbin and type ./progbin in your terminal to run it. Only when the program is debugged and satisfactory would you compile it with optimizations (by giving the -O or -O2 flag to gcc or g++)
Use gdb to debug a program (compiled with -g).
for a multi-file C++ program, consider learning how to use make
use a version control system like git
For beginners, I suggest to avoid Eclipse, because it just hides to you what is really happening underneath (Eclipse is simply running other tools like the above commands)
Software development under Linux requires a different mindset than under Windows: you really are using your own loose combination of independent tools, so better to learn a bit each of them.
NB. to step inside "system" functions like malloc (which is above syscalls like mmap) you need the debug variant of the libc package with aptitude install libc6-dbg, and you need to set LD_LIBRARY_PATH to /usr/lib/debug etc...

Related

Install and run c++ program on machine that doesn't have a compiler

I have made a small c++ program using glfw, glut and dearImgui on linux machine. As i know, i have written this program so it should build on windows as well.
I would like to send this program to my friend who's running windows and doesn't have a compiler. How is it possible to build a program on a computer without a compiler?
Yes, you can make an installer for your c++ project that should allow your someone on windows to simply install and run it. There are multiple options for doing this but the first way that comes to mind for me is using cmake with cpack, but that would take learning how to use both, which, if you plan on continuing to use c++, is probably worth the effort in the long run.
Short term though, if you want to quickly send your project to your friend in a way he can run it, you can install a cross compiler for windows on your linux machine and just send him a compiled version for windows. Again, there are multiple options but I'm pretty certain MinGW should work for what you need, and be much simpler to learn quickly than cmake with cpack.

How to successfully run cudd library in window

is there any Binary Decision diagram (BDD) is available in windows.i tried to run cudd in vc++6.0..which is mention link
http://web.cecs.pdx.edu/~alanmi/research/soft/softPorts.htm
but it isn't working properly.i get compiler error while running a sample code
I compiled CUDD for Windows, but using MinGW not a Microsoft environment. My goal was that compiler since I use Dev-C as IDE.
I did a first try using Cygwin, but with no luck. The second try was with MSYS, an environment to run unix commands that come with MinGW for Windows. Note that CUDD uses a couple of POSIX libraries (such as ). Luckily they are used only in two secondary functions: CPU stats and a kind of fork that I didn't fully understood. Since I didn't need those, I simply commented the portion of code (in util/cpu_stats.c).
Then you only need to write a Makefile for MinGW in order to link the library!
If you need it, I can send to you the library already compiled.

Compile C++ code for AIX on Ubuntu?

Question in one sentence: How can I compile code for AIX using G++ on Ubuntu? (Assuming it is possible)
I hope that it is as simple as adding an option to the make file to specify target processor. I am a novice when it comes to most things compiler related.
Thank you in advance.
What you are looking for is a cross-compiling toolchain.
A toolchain includes a cross-compiler (a compiler that runs on the current platform but builds the binary code to run on another, on your case, AIX), the C or C++ library, and some other interesting tools.
I have successfully used buildroot in the past, which is a tool that automates the process of creating a cross-compiling toolchain. I know they support several target platforms, maybe AIX is among them.
If you want to compile your toolchain by hand, take a look at the Roll-your-own section on this page.
Another approach, probably easier on your case, would be to install a AIX system inside a virtual machine on Ubuntu. This way you would have access to a complete AIX system running inside your machine, giving the opportunity to develop and test your application under real conditions (or whatever reasons you may find interesting for doing such a thing).
You'll want to download the right version of g++ (i.e., one that generates code for POWER, or whatever you're running AIX on), and compile that to run under Ubuntu.
Try to compile with -maix32 or -maux64 (like g++ -m32 file.cxx), it it doesn't work it means that it's not supported by your compiller.

Compiling command line Linux program on Windows [duplicate]

This question already has answers here:
C++ cross-compiler from Windows to Linux [closed]
(5 answers)
Closed 9 years ago.
I need to write a relatively simple command line C++ program to be run a Linux environment. However, I would like to code as well as compile this on Windows. The reason I don't want to port it to Linux is because it requires MySQL interactions, and that would require some messy porting (IMO). It does not have to run on Windows; I just want to compile it on Windows because I want to use my preferred IDE's.
I've looked up on Cygwin for this task, but I haven't been able to find any documentation to do what I'm trying to do.
(I'm assuming "..don't want to port it to Linux.." is a typo for "..from Linux" and that you want the code to run in Linux as you said in your first sentence. This means cygwin or mingw would only be used as cross compilers and aren't going to be very useful.)
This program already builds and works (or mostly works) on Linux, right? No reason to change that. Use your preferred editor (probably the one in your IDE) to edit the files and then just run the build system (probably make) in a Linux system (possibly in a VM). Export the files using a samba share (especially easy from a VM) so you can edit and automatically save remotely.
Note that you seem fine ditching every other feature of your IDE (debugger and compiler, mainly) and just using the editor part anyway.
Ah, are you not starting from any existing project and want to write this from scratch? If so, porting doesn't make any sense. You want to write cross-platform code. (Cross-platform or "portable code" being related to, but different than, the act of "porting code" from one platform to another.)
The code is then both "Windows code" and "Linux code" at the same time, and you can use any compiler on Windows that can accept the code. Usually this happens by you sticking to standard libraries and other portable libraries, or writing shims for non-portable libraries to give them a portable interface, with the compiler supporting the C++ Standard.
You can use your preferred IDE's compiler and debugger in this case, and don't need cygwin or mingw. (Unless they're used by your preferred IDE. :P)
MinGW + MSYS
MinGW provides the functionality, MSYS gives a linux-like command prompt to use MinGW at.
When you get cygwin, install the C++ compiler/build tools, e.g., gcc, g++, make, autotools, etc. I think these are all you need, but I may be wrong. In any case the Cygwin installer is easy to use, and should bring in any dependencies.
Once you have these setup, you can configure your IDE to use g++ as your default compiler. You also need to set your library and include paths correctly such that they point to the relative /usr/include and /usr/lib directories under $CYGWIN (%CYGWIN%).
(Your other option is to use MinGW set of tools, in which case the IDE setup is more or less the same.)
Install cygwin (tutorial) and you'll have an EXE that gives you the command line prompt you're looking for.
The Cygwin installer should have an option for installing whatever compiler you're looking for (gcc?).
Here's another relevant tutorial.

Brand new to C (how to compile?)

I would like to know what I should use to compile in C. I am brand new to programing in general and would greatly appreciate a comprehensive explanation of this process. I am on Windows Vista.
I heard about something called "djgpp" that is free and effective for windows.
For the answer to this question and many others you may have as you start out, try [this website][1] which has beginner tutorials. [Here's the page][2] on compilers and getting set up. An excerpt on what compilers you can use:
Windows/DOS
Code::Blocks and MINGW
Borland
DJGPP
Dev-C++ and Digital Mars
Windows Only
Microsoft Visual C++
nix
g++ is a C++ compiler that comes with most *nix distributions.
gcc is a C compiler that comes with most *nix distributions.
Macintosh
- XCode
Personally, I'd also recommend you strongly to read [The C Programming Language by Kernighan and Ritchie.][3] It will really help you understand both core principles of programming as well as C-specific details.
[1]: http://www.cprogramming.com/tutorial/c/lesson1.html
[2]: http://www.cprogramming.com/compilers.html
[3]: http://www.amazon.com/C-Programming-Language-2nd-Ed/dp/0131103709/ref=ed_oe_h
Visual Studio Express is a free version of Microsoft's leading IDE for Windows, and it includes a C development environment (editor, compiler, debugger).
Depends on which platform, but on Linux, Mac OS X and similar (including Cygwin), gcc is most common.
Say I have a script named myapp.c:
#import <stdio.h>
int main(){
printf("Hi!\n");
return 0;
}
To compile it from the command line using gcc is very simple, just run:
gcc myapp.c
..that outputs the binary as "a.out" (the default filename). To run the compiled app, just do..
./a.out
#which outputs: Hi!
Or put it somewhere within your $PATH (for example, /usr/bin or ~/bin/) and run a.out
You can specify the output filename with the -o flag:
gcc myapp.c -o myapp
./myapp
# output: Hi!
As for more complete guides, "Learn C for Cocoa" is a good, quick guide on the C language, and covers compiling. If you're interested in learning ObjC, the next part of the guide is also great.
On Windows, I would recommend looking into Visual Studio, specifically the Express editions (which are free).
There's no "Visual C", but the Visual C++ edition will compile C code (since C++ is an extension of C). There's also an option to "Compile as C code" somewhere in the build options.
Finally, The C Programming Language book covers, well, everything.
I would recommend using gcc and getting comfortable with the command line, if you plan on doing C for any extended amount of time. *nixes probably have it built in, and on Windows you can install MingW GCC and use it the same way.
I find this helpful because I feel like C was designed hand-in-hand with Unix, so it's better to stick with the command line than use an IDE off the bat. Most tutorials will probably assume you are using gcc. Also, if you're just learning C with gcc, you just type gcc -o outputfile sourcefile.c, whereas if you're starting with an IDE you'll have to figure out how the IDE works.
On the learning front, definitely pick up Kernighan and Ritchie's "The C Programming Language" as it's the definitive book on C. Rather slim volume, and easy to read.
Just a note, another helpful compiler flag for gcc is -g, as in gcc -o output -g -Wall sourcefile.c. -g enables debugging symbols, which will be useful in the future when you want to start debugging with gdb. This is another reason why you should start with gcc rather than an IDE, it makes it easier to move on to gdb.
You could always use MS Visual C++, but I think it's too complicated for a beginner. I personally recommend Notepad++ for editing as it doesn't do too much for you, but it formats the code nicely. Of course, once you become more experienced you might want to move on to a full-blown IDE with project management and such (or better yet, emacs ;)) but when you're just starting out simpler is probably better.
If you're on Unix (i.e. Linux, Mac OS X, FreeBSD, Windows under Cygwin, etc.) I recommend the GNU Compiler Collection (gcc). To compile a file hello.c, run this at the command prompt:
gcc hello.c
This compiles hello.c to the executable a.out. If you want a better-named executable, try this:
gcc -o hello hello.c
This compiles hello.c to the executable hello. Some more helpful flags:
gcc -Wall -Wextra -o hello hello.c
This turns on lots of helpful warnings that will probably help you catch bugs in your code.
On Windows, many people use Microsoft Visual C++, but I have no real experience with Windows. As I referenced above, you can install Cygwin, and then use the above steps, but many prefer pure-Windows compiling. Also, MinGW is a native-Windows port of gcc. It's all a matter of preference, though.
Welcome to programming!
You might want to start in the right track and install a copy of Linux in your box. Try Ubuntu cuz it's easy to install and learn
Next learn to use the console! It will help you so much in the next years.
Once ubuntu is installed you need to install C compiler and basic libraries just typing in the console
sudo apt-get install gcc build-essential
Then just create a C file and run
gcc myprogram.c -o myprogram
This will generate an exec file called yourprogram, run it using
./myprogram
Here are some useful links:
Ubuntu Home
Compiling/Running C in Ubuntu Forums
Linux Tutorial - READ THIS!
I would recommend downloading Microsoft Visual C++ Express Edition. http://www.microsoft.com/express/vc/ DJGPP will work as a compiler but does not provide an editor or coding environment. Compiling your code involves going to the command line. Some have suggested using gcc or MinGW but both of those programs behave similarly to DJGPP. Using a separate editor and compiling your code from the command line is not really the way that software is typically written in a Windows environment. Visual C++ will allow you to write and compile either C or C++ code.
Microsoft Visual C++ is a free of cost development environment which includes an editor and a compiler. Simply download the installer executable and run it to install. The installer will download the necessary software from the Internet and install it on your computer. The installer will download about 200MB of software so it may take up to an hour to download depending on your connection speed.
Once you have Visual C++ installed, start a new project and write your code. You can then compile and build it right from inside Visual C++ and see the output. Start by writing a simple command line program and then work up to more interesting programs.
For windows now you can use gcc as mentioned above but also MSC. You can get the compiler for free with the Visual Studio Express bundle for Visual C++ Express
Invoking the compiler from the command line is fine for small apps as you're getting used to the C syntax, but as you move along, you will find that entering the myriad options gets tedious, and you will want to use a build tool. make is a basic but powerful way of compiling your projects easily. Editing makefiles by hand can be tedious, and will get in the way of your learning, so I'd suggest skipping right over that and go for the autotools toolchain.
Ok Josiah, first of all, be sure to have a C compiler installed on your system. On Linux, Mac, there's a compiler installed just out of the box, called the GCC compiler. And on Windows, you need to instal one, I recommend you to instal an IDE (like devshed) that includes an editor, compiler, debugger... all that you need to develop a C/C++ application.
In order to compile over Linux/Mac, first of all you'll need a source file (a text file with your code) and save it with a .c or .cpp extension. Then open your terminal and type:
gcc <fileName.c>
You should replace <fileName.c> with your filename (the full path, or first go to the files location and just type the file name).
This will create a .o file (and object file) in the same path of your source file, this is the executable file for your computer!
On windows, if you already installed an IDE, is easier, you just click the compile button and there ya go!
I hope this to be helpful to you