-6

I'm a beginner when it comes to c++ and overall including libraries, so I spent the good part of my last 3 days trying to install various GUI libraries and trying to make them work with Visual Studio, but none of these tries were successful.

It comes down to the problem of having to include the files and link the libraries. It seems, at least to me, extremely tedious and time consuming having to copy paste everything in those boxes in Visual Studio.

I need a helping hand to figure out what I'm doing wrong, here is how I tried:

Visual Studio 2017 - gtkmm library with the windows installer I download the required Gtk+ and install it successfully. I open the properties of my project, go to the includes and paste the required paths. I go to the linker and proceed to paste those paths. Accept,try to paste a hello world program with the includes -> everything is underlined with red.

And this isn't even the actual gtkmm implementation.

Now my question is, did I forget a step or is it just the basic snippet that doesn't work (I'll spare you from posting it).

What do I do, when the tutorial for the library tells me to include 2 or 3 files whilst I have like 20 in my folder?

Also, is it somehow bad practice to place the libraries onto a different drive?

Sorry if I sound lost, but that's pretty much how I feel in those tutorials..

Edit, just in case, this is the snippet I'm referring to:

#include <gtk/gtk.h>

int main(int argc, char *argv[]) {

gtk_init(&argc, &argv);

g_printf("GTK+ version: %d.%d.%d\n", gtk_major_version,
    gtk_minor_version, gtk_micro_version);
g_printf("Glib version: %d.%d.%d\n", glib_major_version,
    glib_minor_version, glib_micro_version);

return 0;
}

g_printf, glib_major_version, glib_minor_version and glib_micro_version are red underlined, but not gtk_major_version

EDIT:

Thank you for the suggestions and the in-depth tutorial although questions like this don't fit stackoverflow.

Can you tell me how to include huge amounts of header and lib files when they are in many folders? Do you I need to access all folders manually and include them?

mxOx2kL
  • 3
  • 9
  • I don't understand. The title talks about GUI in general. There are other GUIs than GTK, such as Qt, WxWidgets and Microsoft MFC Forms. What are you having issues with? – Thomas Matthews Aug 28 '17 at 20:54
  • If you just need something that works and is cross platform, well documented and easy to use; check out [Qt](https://www.qt.io). But this question is really somewhat off-topic for SO. – Jesper Juhl Aug 28 '17 at 20:54
  • There are also MFC applications written in Visual C++. – Anton Savelyev Aug 28 '17 at 20:56
  • @ThomasMatthews I gave Qt a shot, but when I read in the ToS that they refer to a "free product" as something that is still going to cost, I turned my back to it. The reason this is a general question is that my scenario above is happening with all libraries I tried to install, so I assume it has to do with the overall setup – mxOx2kL Aug 28 '17 at 20:59
  • @JesperJuhl but is it really completely free? I would assume that a free version wouldn't require one to register. Also, may I ask why this question is offtopic? Isn't this part of coding questions, which stackoverflow is used for? – mxOx2kL Aug 28 '17 at 21:02
  • @AntonSavelyev thank you for the suggestion, I will use it if I don't succeed with other external libraries. The reason I want to try them out is just finding out how to setup up everything and making it work...which isn't quite working out at the moment. – mxOx2kL Aug 28 '17 at 21:04
  • @mxOx2kL the free Qt version is under the [GPL](https://en.m.wikipedia.org/wiki/GNU_General_Public_License) license - so yes. Off topic because [Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam.](https://stackoverflow.com/help/on-topic). – Jesper Juhl Aug 28 '17 at 21:04
  • The C++ standard is oblivious of graphics and GUI. You need to use the libraries for the task. – Ron Aug 28 '17 at 21:53
  • I will try out the Qt version, their ToS were kind of confusing (maybe cause I didn't read everything). Do you have a suggestion how to handle huge amounts of header/lib file includes? In the gtkmm library, they are all in various folder which are not recognized by the compiler – mxOx2kL Aug 29 '17 at 14:01

1 Answers1

0

Yes, you undoubtedly missed a step in Visual Studio. No, its not bad to install it on another drive.

The general idea is:

1) Install the library somewhere on your machine. Doesn't really matter where. Take note of the "lib" directory and the "include" directory paths.

  • The include directory contains header files which allow your code to understand the forward declarations of the code your trying to use.
  • The lib directory contains the binaries (dll for dynamic linking, lib for static linking). Sometimes there are different binaries for release/debug. I'd link the debug library and worry about the release code when you get there
  • Note, sometimes they want you to compile the code yourself and create the binaries. They will include compile instructions. After you create the binaries you can go back to step 1 here and repeat the steps. This is because they either don't want to precompile binaries for your platform or their project philosophy is to do it yourself.

2) In Visual Studio you have to tell the compiler (separately) where the new additional include and library directories are. On 2017 that is...

  • Include Directory: Project > {Name} Properties > C/C++ > General > Additional Include Directories
  • Library Directory: Project > {Name} Properties > Linker > General > Additional Library Directories

3) Now include the libraries (binaries) themselves. On 2017 that is...

  • Library Binaries: Project > {Name} Properties > Linker > Input > Additional Dependencies

They should provide you a list of binaries to include in the project if there are external dependencies or they have broken their project up into multiple libraries for modularity.

If you want to program in C/C++, this is a process you're going to go through again and again. Its a bit arcane, but once you get it down, its not going to surprise you.

Edit:

Oh, and as an aside, people have mentioned Qt. This framework is a little different in regards to Visual Studio. Its very involved to set up the dependencies yourself because they have included language extensions and a tool for creating GUIs. For this reason, there is a tool (which is quite nice) for creating Qt projects from a template. This sets up all the compiler steps, includes, and linked libraries for you.

In my opinion its probably the best and most mature of the GUI libraries for C/C++ on Windows and is also cross platform.

Josh
  • 12,602
  • 2
  • 41
  • 47
  • Thank you so much for your in depth explanation. I followed those steps initially too, but it seems like I have to select ALL headers and lib files separately, because the folder are not visible to the compiler. Is there any workaround? I will try out Qt again, since, as you mentioned, it's free, but I still would like to know how to handle "huge" library includes like gtkmm, where you have tons of folders with headers and libs. – mxOx2kL Aug 29 '17 at 13:58
  • @mxOx2kL There is no case where you have to include every individual file in project settings. An incorrect or misunderstood include directory/include library setting is likely the culprit. Further, if inside the main "include" directory there are subfolders, you need to include that in your header #include directive in your code. Example might be the graphics SFML library, which has a path such that "include\SFML\". If you put the "include" path in your visual studio settings, the header #include directive in your cpp file looks like #include . – Josh Aug 29 '17 at 17:38