Warnings during compilation, but programme works; what is to do? - c++

I compile the following programme from source (code is written in C++): http://www.stanford.edu/group/hadlylab/ssc/index.html
The author recommends to use the g++ compiler with g++ *.cpp -fpermissive.
As this is recommend for Linux machines, while I am working on a Mac (OS X 10.7), I cannot say if this works as intended on my machine.
I get a lot of warnings, but the code compiles and eventuelly runs without any further error messages.
However, I am still worried that the script could be faulty, because of the compilation errors/warnings, and because of following the compile description for Linux, while compiling it under OS X 10.7.
Hence my question:
Should I (a) be worried that the programme could produce faulty results,
or (b) ignore the warnings during compilation because it compiles and is executable,
or (c) should I try another compiler, and if so, which one could do the job?

Presumably your difficulties related to changes in the version of
the build tools (make, automake, etc)
the compiler and related tools (g++, ld, ldd, libtool, etc)
the libraries on the system
between the earlier versions of Mac OS and the current one.
Your first step is going to be finding out what changed between 10.6 and 10.7.
Then go through the build mechanism (is there a configure script or something else?) looking for places it depends on one of those things.
Finally you start reading documentation to find out how to existing build infrastructure to account for the new build environment.

Related

Can I have a local C++ compiler different from the one in linux environment?

Newbie in Linux.
I have a linux developer machine at my organization which has a compiler which is old.
gcc --version gives the following
gcc (GCC) 4.4.7 ...
I have a small piece of code that came from a different machine that uses a lot of C++11 features.
Obviously, compiling it in my current linux box gives a lot of errors.
Compiler upgrade in the linux box is completely out of question due to legacy issues.
So I have two options,
rewrite everything to suit C++98 / 03 standards, or
which is a question
Can I have an updated version the gcc compiler copied within my local directory and use it to compile my code within that folder ?
It shouldn't affect the compilation of my Organizational code outside this folder which uses the older gcc compiler that comes with Linux.
I haven't researched anything much unless this is possible.
Basically I wouldn't want to touch any of my global settings lest it would break my project.
But I would like to have a folder within my local path and work with an updated compiler to compile and test my code from another machine.
Yes.
This is done all the time for ARM cross-compilation for SBCs like Raspberry Pi and Android devices.
A specific GCC based toolchain like Lenaro is unpacked in a different folder such as /opt to cross compile ARM software on X86 machines.
You can manually run the desired binary with full path, or source a script to temporarily set environment variables to use build automation tools such as make.
I could not find an easy to use package for you with a quick search, but you can either build one following instructions here or manually download a package from updated distro like Ubuntu, and unpack it by hand in to any directory you want.

Clang based on platform in CMake

I'm setting up a cross platform build environment. For that reason I've chosen to go for clang, for the, correct me if I'm wrong reasons:
Using the "same" compiler for different platform would potentially reduce the quirks that arise when getting gcc code to work with MSVC
Clang with its MSVC compatible ABI would let me work with the WINAPI as if I were using MSVC.
My question is: How do I get CMake to, based on the platform, find the correct clang to use, that is clang-cl in Windows and clang on *nix platforms ?
Please note that I'll be using Ninja generator for CMake, and the project is Qt based, if that matters.
You (the project author) don't get to choose the compiler, the user that invokes CMake chooses the compiler.
The only thing you can do from within the CMakeLists is abort with an error if you are not happy with the choice that the user made.
There are a couple of ways how the user can specify to CMake which compiler to use. Popular examples include setting the respective environment variables, passing it via -DCMAKE_CXX_COMPILER on the first CMake run (and only on the first run; you cannot change this later without re-configuring from scratch!), or by using a toolchain file.
On Visual Studio, you can also use the -T option to select a build toolchain. This allows you to build with clang from Visual Studio.
You should document in your project's Readme which compiler you expect your users to configure for CMake and maybe give them a small example how to do this via one of the methods above.

Problems with gdb 7.5.1 debugging executable built via g 4.7.2

I've been updating my Mac toolchain in order to take advantage of C++11 features and eventually get pretty-print debugging of STL data structures. I used Homebrew to build the gcc 4.7.2 compiler. I've been able to recompile the source of my current project using this new compiler. However all versions of gdb that I've tried have various problems when setting breakpoints, viewing source code or viewing local variables.
The version of gdb that I believe is installed as part of the Xcode command-line tools, version 6.3.50, has trouble displaying various template-based variables. I've also built and tried to use several other gdb versions (7.3.1, 7.4.1 & 7.5.1), but each gdb version has problems that make it difficult to impossible to set breakpoints, view source code and view variables. Specifically, these gdb versions don't know the source file or line number of functions defined in header files, breakpoints can't be set in these header-file functions, and many local variables have been "optimized out".
Has anybody else experienced these problems, and if so have you been able to resolve them? Which versions should I be using in my toolchain in order to avoid these problems?
For the record, my development is on a recent MBP running the latest Mountain Lion updates. My IDE is Eclipse Juno with CDT version 8.1.1. And, yes, I've code signed all versions of gdb that I've built and attempted to use.
Thanks for any input,
Bob
many local variables have been "optimized out".
Is this happening while debugging optimized code? If so, that is expected. You may not have seen this happening before, because older GCC didn't quite optimize that much.
To fix: build your to-be-debugged code with -g -O0 flags.

step into system, CRTL functions with Eclipse in Linux

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

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.