1

Okay, so I know Java and have fiddled around with libGdx for quite a while now. C++ is the "language-to-know" in the Game Development industry, it seems, and since I want to be a game developer when I graduate, I have determined that it is nothing but beneficial to learn the language. I have learned the basics of memory-management and have applied my knowledge by;

  1. Learning how to parse complex text formats (you know, anything more complex than xml)
  2. Writing a parser for a pseudo-language that I can use to serialize a C++ Object with and express basic math and command/function functionality.

Now I want to apply my knowledge doing something more interesting; making a small game! I would prefer putting off learning how microprocessors and GPU work until ~College, so I need to use a framework of some sort. To do this I need to be able to import code from an external library. In Java, we generally put our libraries into a libs folder which is linked to the core project by using fancy maven/gradle set ups.

I set up the GCC compiler and downloaded the latest Code::Blocks binaries and installed them on my outdated Windows laptop (It was quite an annoying surprise that I had to download a compiler and IDE separately, as I am an Eclipse boy). The reason I am using Code::Blocks and not Visual Studio C++?

I am broke and cannot afford express, and Community is still 2 frickin gigs and runs like molasses going uphill on a cold winter day (my computer only has 2 gigs of RAM because I was too cheap to put in an extra $200 into a laptop that has a rough lifespan of 1 year) while Code::Blocks is 500 megs and runs like a charm.

Anyway, enough of my ranting, the problem is that in Java we can import an external library with a few clicks in any self-respecting IDE. C++ seems to be different. I googled several libraries that would handle my needs adequately, as I just needed a rendering library. Oxygine seems to be the best, with Angel2D being the second one on my list. I did some googling yahooing but found little of use. As a matter of fact, it seems that C++ lacks the concept of 'importing' external libraries. #import seems to only work on core language libraries and project files. The closest thing I have found was dynamically loading libraries, but even this is not clear.

Jax
  • 402
  • 7
  • 24
  • First hit on google: http://www.learncpp.com/cpp-tutorial/a3-using-libraries-with-codeblocks/ may be of help – Galik May 26 '16 at 22:40
  • If you are looking to learn C++ for self-education and not to work on a particular existing project, I think you are best off to learn to use a non-IDE method of compiling, like GNU makefiles, or CMake. Even better, your first programs should be a single .cpp file and compiled at command-line with a single invocation to `gcc` or `clang`. This is by far the simplest way to learn the principles of compiling and linking, and what the various flags and options do. IMO IDE is best after you have already learned to do it that way. Too many think there is a point-and-click solution to linker errors. – Chris Beck May 26 '16 at 22:50

1 Answers1

2

The story in C++ and in Java are not that dissimilar here (though how #include works in C++ is quite different from how import works in Java). In both cases, there are:

  • Symbols used at compile-time
  • Definitions/implementations used at run-time

The import statement in Java and the #include statement in C++ effectively take care of the first. In both languages, the second one is a result of how the code is configured / invoked / bundled; in Java, which *.jar file actually ultimately provides the imported symbols is determined by the "classpath", while in C++, it is dependent on the specific linker (for GCC, passing -lname indicates the name of the library, and -Lpath/to/dir specifies candidate directories to lookup, though various environment variables can override the actual library that is ultimately loaded).

While drag-and-drop may work in some IDEs*, this is really not a great solution (neither for C++ nor for Java), as IDE-specific build systems are very difficult to automate, reproduce, or share with other developers. You'll find that in the industry, it is far more common to create a commandline build configuration using a build system such as Bazel, Gradle, CMake, or Make. The configurations used by these systems are easier to share between IDEs and, importantly, can easily be invoked by continuous integration / testing systems. Most IDEs support adding a build / test step that simply invokes an arbitrary command, which can run these build systems. If you set that up, you add new library dependencies simply by editing the build configuration.

*Sorry to disappoint, but I've tried several C++ IDEs on Windows, and I do not know of any of them that will let you simply drag and drop libraries in them.

Michael Aaron Safyan
  • 93,612
  • 16
  • 138
  • 200
  • Unfortunately I have put off learning how to use the command line as long as possible - not that it seems overly complicated, just that I am dyslexic and walls of text hurt my eyes (I am big on generously indenting and spacing my code and on the windows command line). Do you have a suggestion as to which I should start out with (CMake or GCC)? – Jax Jun 01 '16 at 17:28
  • @DJMethaneMan I would strongly recommend using "Bazel" for your build system. (All of the above would use GCC as the compiler under the hood, though). – Michael Aaron Safyan Jun 02 '16 at 02:47