understanding c++, compilation etc [closed] - c++

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Do you know a good, concise (not a book, possibly free documentation) reference that explains the basics of how a c++ compiler works? I think it'd be beneficial for better understanding some rules of c++ programming.

GCC Internals free ebook.
The purpose of this book is to address
the demands of GCC hackers. We start
with a description of GCC 3.4.1
architecture focusing on the source
code parser. We chose this version of
GCC because we used this version
mostly. Then we address the problem of
extension development. We present the
GCC Extensibility Modules (GEM)
project in the next chapter. GEM
provides a number of hooks throughout
GCC source code. It is implemented as
a patch to GCC. A GEM-based compiler
extension is developed as a
stand-alone program. When the
extension is completed, only its
source code is distributed compared
with distributing the source code of
the GCC if GEM is not used. We give
examples that demonstrate GEM
programming at the end of the book.
(EDIT: Sorry, I missed you don't want a book. But I still think this is great resource of information you are looking for. You certainly don't need to read it as a whole, you can go only through the sections you are interested in.)

I found this university site which explains the steps of the compilation process. It covers how to compile your code into an executable, a shared library, or a dynamically linked library using GCC. It also covers how the compiler knows where to look for header files and libraries, and other topics.

Related

Different compilers, different syntax [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
How to compensate the differences between the syntax of different compilers of the same programming language? How could I know which one is standard and used worldwide to make projects?
For example: I worked 4 months on Borland C++ compiler to learn C++ but now I saw the syntax of Borland, Visual C++ and Developer C++ is different. I am confused, need some guidance...
The first solution is to not use parts which are specific to one compiler or another. Before you use a feature of the language, check on the internet to see if it's specific to any one compiler. If it is, then don't use it.
Other than that, actually making a C/C++ program which is compilable by different compilers is a task which takes effort. It doesn't "just happen", because the compilers each have their own quirks, their own level of support of the standard etc. Even writing compliant C99/C++11 code you might still see issues. So one solution is to actually compile the program with different compilers on a regular basis (say, as part of testing before pushing code to the central repository) and make sure that all of them can compile the code, and the resulting software can run.
As for "standard" compilers, on Linux and Mac gcc and clang can be considered "gold". On Windows, the compilers by Microsoft are standard.

C++ with 2 compilers [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I have a project which I would like to code on both an Ubuntu and a Windows machine. On Ubuntu I'm using gcc, and on windows I would like to use MSVC.
Is it a good idea to compile the same code with 2 different compilers like this? Or would I run into issues down the road?
Thanks.
It is an excellent idea. In the past, I've found a bunch of bugs in my code that I could only see after switching compilers.
If you want to compile for different platforms, you have to compile with different compilers (even if they are different versions of the same compiler).
If you compile with both GCC and MSVC, you will find you can't use a lot of the extensions that each compiler provides. You will also find annoyances like MSVC puts an underscore on the front of functions like _open. Basically, this comes down to "welcome to the wonderful world of portable coding".
On the other hand, once you start writing code for two compilers, it becomes much easier to add a third - and I would recommend adding Clang to the mix as a cheap and cheerful static analysis tool.
Microsoft is making it easy, by allowing you compile code directly from Visual Studio on a Linux box. It's pretty cool.
https://blogs.msdn.microsoft.com/vcblog/2016/03/30/visual-c-for-linux-development/

How to use libraries in C++? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Hello I'm new to coding in C++, thankfully I'm quickly learning how to use it. So far I've heard of libraries and how they can be used in an application.
My questions is are:
What do I need to do after I download ANY library?
How do I #include "library.h" or #include <library> and use it
in a project without intellisense or the compiler going nuts?
What if the library is header only?
What should I look for?
Are there any apps I need?
What if there's no build folder?
Usually the instructions are unclear to me, maybe it's because I'm still green.
Please try to explain this in an easy to follow manner like if you were teaching it to someone that knows NOTHING: I've tried to follow other guides but with no luck.
Beforehand, thank you very much!
If it's header-only, including the header is enough. Otherwise, a library can be any piece of code in any form (source in various languages, binary, shared, static, ...). It's impossible to cover all the cases, each library is supposed to come with its own documentation.
Each and every library has a specific license (eg MIT, GPL, LGPL etc) for it's use. There can be differences between uses (eg personal, academic and commercial etc) but often not. It's quite easy to learn about the major licenses and how they might apply to your use case on the internet. But if you are doing this for commercial purposes or have any doubt whatsoever consult a lawyer.

How can I make C++ in C? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Well, i was learning, again, a little bit of c and was with a little curious about how did the C++ inventor made it. And some facts lead me to the information, that he created it using pure C(obviously), so i was thinking if there is any source or anything that could help me to do things in C, that i can do in C++, like templates, namespace, class, reference and others it doesn't matter how difficult it is, i want to at least have more notion, so if anyone know a reliable source and well written i would be glad.
Yes, many, many years back, the first C++ compiler, by Bjarne Stroustrup was a "frontend for a C compiler".
Today, it certainly isn't anywhere like that. Modern C++ compilers generate code directly from C++ constructs in intermediate form for the backend to process into machine code for the target. This allows the compiler to do a more direct job, and not rely on the C compiler "understanding" what is going on.
This page contains some reference material on the cfront:
http://www.softwarepreservation.org/projects/c_plus_plus/index.html#cfront
That page also has links for the 3.0.3 archived sources as unpacked and compressed form.
Note however that this release is 21.5 years old, and would thus, if it was a person be able to order alcohol in a US Bar after showing ID. This is NOT the modern standard C++ by any measure (and it may or may not generate code that is suitable for a modern C compiler, I have no idea)
With this quote to go with the 3.0 release from 1991:
Bjarne Stroustrup notes, "A warning that Cfront 3 is pre-standard and
emphatically not recommended for use or further development might be
in place."
Edit:
I did download the code in the (compressed) link above. It certainly doesn't compile on Linux without effort. More effort than I am willing to spend, really. One of the problems is that it's pre-ANSI C, so the compile complains about various functions not being declared (for example strcpy, strcat, etc), and there are OS choices, none of which is Linux.
I also don't think it is necessarily the best place to start learning compiler techniques.

why does this imapclient g++ compiling gets errors [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Im a beginner level Java coder and I decided to get into C++ coding. After reading the basics (similar enought to Java) decided to try the apoach of reading other peoples code.
I found the following code of an imap mail client, but when triing to compile it with g++ (gcc 4.6.3) it shows some errors that seem to have something to do with the scope of the used namespaces.
Where is the error here or what kind of error should i be 'googling' for?, 'cause I couldn find the answer there.
Here's a link to the code, 'cause Im not sure about licensing issues (like if I should be citing the author):
imap_email_client
Thanks in advance for all your help and sorry for all the forum rules missconceptions i could have commited.
The code you referenced isn't any C++ code, but code written in a language called C#.
On the other hand g++ is just a C++ compiler. Meaning it doesn't know any C# and it will not compile any C# code.
You'll need a C# compiler instead to compile the code you referenced. As Mono (see: http://www.mono-project.com/Main_Page) comes along with a C# compiler gmcs you might want to try if you're able to compile with
gmcs name-of-your-source-file
if it is installed on your system.
On my system I was able to compile the referenced sources with it.