gtksourceview compiling in code blocks - c++

i want to use gtksourceview in my c++ project. I dig around the IDE of code::blocks and really find it helpfull. i specify gtkmm directory in linker and include options but as i look for gtksourceview i found a libgtksourceview-2.0-0.dll file i really don't know how to add this in code::blocks and use gtksourceview. I am have programming experience in C for microcontrollers just and now i have not really idea about the compilation process of gcc and g++. and can i able to add the file directives as
#include <gtksourceview/gtksourceview.h>
please help
sorry if it seems so basic question for someone but i really stuck of to compile the code and then asking.
I am using windows by the way.
Thanks in advance

There are two different things: the runtime libraries and the development headers. The former allows you to run the applications (also to link them), the later to compile them. Either you are missing the header files (gtksourceview.h in your example) or setting the PATH in your IDE to find the header files.
Check the manual for 'Including libraries'.

Related

How properly specify the #include paths in c++ to make your program portable

I've been struggling back and forth with this for a while now looking stuff up and asking questions and I'm still at a crossroads. What I've done so far and where I'm currently at based on what I've been told is this: I've added 2 directories to my repo: src for my .cpp files and include for my .hpp files. In my include directory I have all the .hpp files directly in the folder where as in my src directory I have several sub-directories grouping my .cpp files according to the purpose they serve e.g. \src\ValuationFunctions\MonteCarloFunctions\FunctionHelpers.
I've changed the name of all the #include "header.h" to #include "..\include\header.h". This works for my main file which is directly in the src folder but I found now that it doesn't work for my .cpp files that are in sub-directories like in my example above, it would seem I would have to navigate back to the root folder doing something like #include "../../..\include\header.h" which obviously can't be the way to go.
How do I make this work, am I even on the right track here? I have uploaded my repo to github (https://github.com/OscarUngsgard/Cpp-Monte-Carlo-Value-at-Risk-Engine) and the goal is for someone to be able to go there, see how the program is structured, clone the repo and just run it (I imagine this is what the goal always is? Or does some responsibility usually fall on the cloner of the repo to make it work?).
I'm using Windows and Visual Studios, help greatly appreciated.
How properly specify the #include paths in c++ to make your program portable
Please read the C++11 standard n3337 and see this C++ reference website. An included header might not even be any file on your computer (in principle it could be some database).
If you use some recent GCC as your C++ compiler, it does have precompiled headers and link-time optimization facilities. Read also the documentation of its preprocessor. I recommend to enable all warnings and debug info, so use g++ -Wall -Wextra -g.
If you use Microsoft VisualStudio as your compiler, it has a documentation and provides a cl command, with various optimization facilities. Be sure to enable warnings.
You could consider using some C++ static analyzer, such as Clang's or Frama-C++. This draft report could be relevant and should interest you (at least for references).
The source code editor (either VisualStudioCode or GNU emacs or vim or many others) and the debugger (e.g. GDB) and the version control system (e.g. git) that you are using also have documentation. Please take time to read them, and read How to debug small programs.
Remember that C++ code can be generated, by tools such as ANTLR or SWIG.
A suggestion is to approach your issue in the dual way: ensure that proper include paths are passed to compilation commands (from your build automation tool such as GNU make or ninja or meson). This is what GNU autoconf does.
You could consider using autoconf in your software project.
I've changed the name of all the #include "header.h" to #include "..\include\header.h".
I believe it was a mistake, and you certainly want to use slashes, e.g. #include "../include/header.h" if you care about porting your code later to other operating systems (e.g. Linux, Android, MacOSX, or some other Unixes). On most operating systems, the separator for directories is a / and most C++ compilers accept it.
Studying the source code of either Qt or POCO could be inspirational, and one or both of these open source libraries could be useful to you. They are cross-platform. The source code of GCC and Clang could also be interesting to look into. Both are open source C++ compilers, written in C++ mostly (with some metaprogramming approaches, that is some generated C++ code).
See also this and that.
In program development, it is often necessary to use toolkits developed by others. Generally speaking, in Visual Studio, source files are rarely used, and most of them use header files and link libraries that declare classes. If you want to use these classes, you need to include the name of the header file in the file, such as #include "cv.h". But this is not enough, because this file is generally not in the current directory, the solution is as follows:
Open "Project-Properties-Configuration Properties-C/C++-General-Additional Include Directory" in turn and add all the paths.
For all kinds of IDEs, we can do similar operations to include directories. So for those who clone the project, it is quite normal to modify the directory contained in the project.

MSXML6.lib import doesn't seem to be working properly. CODE BLOCKS, MSXML2.h?

On a 64 bit system, Windows 10, using CODEBLOCKS with the MingW/GCC compiler. I need to use the
MSXML6.lib library and include the msxml6.h header.
The library is included with a current Windows SDK (which I have installed).
I have the appropriate linker path set up in CODE BLOCKS.
The problem is my #include <msxml6.h> directive does not work. The only header files the compiler finds are:
<msxml.h>, <msxml2.h>, <msxml2did.h>, and <msxmldid.h>.
Internet and SE/SO search of my problem turns up this:
MsXml6 failing to link properly
Not quite what I'm looking for.
Tried the CODE BLOCKS forum. Perusing there, they are not all to welcoming of library and linker questions. This is ok, that's their rules, but not really all that helpful.
Anyone seen anything like this before? Is there someplace I can go to get the right header file for that library? For some reason, the library is there but header is missing from the SDK.

What C++ implementation/library is my IDE using? (NetBeans, MacOSX)

Can anyone tell me how an IDE like NetBeans or any for that matter gather all the standard C++ libraries? For example, I created a new Netbeans C++ application, and included iostream and it worked no problem. However, if I do a search for filename "iostream" on my MacOSX Snow Leapord, it finds it in the path
/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/IOKit/stream
Does that mean that my IDE is using my operating system's C++ library? It's strange because all of these files are "copyright apple" - so I'm assuming that this is a C++ implementation modified by Apple?
I was under the impression that there was 1 standard C++ libary and all compilers used that. Is Netbeans somehow just gathering the same library that Xcode is bundled with?
Essentially, I'd like to view the source of some C++ headers to gather more information about their inner-workings, but I'm worried that I am using some super-heavyweight, Apple-modified core lib that may not even be legal to use because it's under some Apple liscense.
Thanks everyone
NetBeans is just an IDE, it doesn't come with a compiler or any C++ libraries. Since it looks like you already had Xcode installed, NetBeans automatically uses compilers and libraries associated with Xcode. I have no idea what the apple licenses are, but since you bought and own your Mac, I don't think there is a problem using those headers.
Also, to view headers, just right click the code and Go To -> C++ Declaration or Header Files.
There is a place you installed g++, and your include files all come from there.
You can add additional header files by using the gcc -I switch, and that is implemented in Netbeans in the build tool chain option
further information here
I don't have a mac in hand right now, but I guess the include files will be in somewhere like:
/usr/share/g++
EDIT:
You can find the code assistance pop-up include files at:
Tools -> Options -> C/C++ -> Code Assistance

What Should be the Structure of a C++ Project?

I have recently started learning C++ and coming from a Ruby environment I have found it very hard to structure a project in a way that it still compiles correctly, I have been using Code::Blocks which is brilliant but a downside is that when I add a new header file or c++ source file, it will generate some code and even though it is only a mere 3 or 4 lines, I do not know what these lines do. First of all I would like to ask this question:
What do these lines do?
#ifndef TEXTGAME_H_INCLUDED
#define TEXTGAME_H_INCLUDED
#endif // TEXTGAME_H_INCLUDED
My second question is, do I need to #include both the .h file and the .cpp file, and in which order.
My third question is where can I find the GNU GCC Compiler that, I beleive, was packaged with Code::Blocks and how do I use it without Code::Blocks? I would rather develop in a notepad++ sort of way because that is what I'm used to in Ruby but since C++ is compiled, you may think differently (please give advice and views on that as well)
Thanks in advance, ell.
EDIT: I'm on Windows XP & thanks for the lighting fast replies!
To answer your questions:
The lines are include guards. They prevent the header file being included more than once in any given translation unit. If it was included multiple times, you would probably get multiple definition errors.
Header files are #included in .cpp files and in other headers. .cpp files are not normally #included.
The C++ compiler that comes with Code::Blocks is called MinGW GCC, and can be found in the bin directory of the MinGW installation. To find it, do a Windows search via explorer for 'g++'. To use it, you will need to put the directory it is in on your search path. Note the version of the compiler that ships with Code::Blocks is quite old - you can get a much more recent version from here.
That's an inclusion guard, to prevent a .h file from being included twice. Besides saving time, this is often in fact required to avoid defining things twice.
You should include only the .h. The .c file will be linked to your program in some form. For small programs, you can just pass all the .c files to gcc, but larger programs will involve intermediate .o files or even libraries (static or dynamic).
You can definitely work without an IDE. There are many ways to install the gcc compiler on Windows, including Cygwin and MinGW. I think you are correct that Code::Blocks comes with a gcc executable, but I don't know where it is or what version.
Those lines make it so that if a file is #included twice, everything will continue to work. That in turn lets you treat header-file dependencies as a simple directed graph, which is definitely easiest.
You don't #include .cpp files. (Well, not unless you're an evil programmer. Don't do it!)
I'll let others (or google!) tell you about gcc, but it might help if you were to describe what platform you're using.
All of your questions have been answered by others, except this:
I would rather develop in a notepad++
sort of way because that is what I'm
used to in Ruby but since C++ is
compiled, you may think differently
(please give advice and views on that
as well)
I think this is a very bad idea. A fully fledged IDE with an integrated debugger, jump to symbol definitions, refactoring capabilities, a profiler, intellisense and more is practically a must for any real world project.
And the absolute best is Visual Studio* with Visual Assist X**. Code::Blocks pales in comparison ;)
* If you study in a university you can usually get it for free through MSDNAA; otherwise there the Visual Studio Express edition whicih is free
** 30 days evaluation period

C++ Lib/Headers in Emacs

Where could I find C++ libraries in my emacs? I have already installed emacs on my computer and already using it lately. I just want to add boost libraries in emacs so I could use them.
Emacs is a text editor, it doesn't compile your code.
It doesn't know (or need to know) anything about your libraries.
However, there are commands for running the compiler from inside emacs, I've never done it myself, I use command line compiling and makefiles for bigger projects.
I would write the program using the boost libraries (or any libraries) just like normal.
I'm guessing you'd use GCC to compile as you're using emacs to edit.
When compiling you need to tell the compiler (GCC) where to look for the header files and the libraries.
For example,
in your program you will have a line like
#include <library.h>
then compile it using
g++ myprogram.cpp -I/path/to/header/files -L/path/to/library
If your program is more than a couple of files, I would recommend writing a makefile for it and including all the required compiler flags and search paths in the makefile.
You need to supply them in your make script, or you can set an environment value for GCC. Take a look at this question.
You could use CEDET to setup parsing of header files. Please look to my CEDET config for example