Problems Importing Libraries to My C++ Project, How to Fix This

Problems importing libraries to my c++ project, how to fix this?

It's a common misconception, that the current IDE used, is responsible for getting errors like stated in the question.

See for example

  • c++ lib in two same project ,one can work but the other can 't
  • Issue linking libxml++ and glib libraries with CodeBlocks IDE for C++ Windows
  • ...

The problem is almost never related to the currently used IDE.

In the most cases the solution boils down, to supply the actual toolchain's compiler/linker with the appropriate path's to search for included headers, to be linked libraries.

One of the major applicable answers for the linker related problems are

  • What is an undefined reference/unresolved external symbol error and how do I fix it?
  • undefined reference to `WinMain@16'

Most of the common IDEs provide features to configure this for a specific project. Here are some samples


Eclipse-CDT

Include path settings:
enter image description here

Library & library search path settings
enter image description here


Visual Studio 2013

enter image description here


Code Blocks
enter image description here
enter image description here


**DEV C++ (Bloodshed C++)

As from their FAQ:

9. How can i use the OpenGL library and others ?

All the libraries that comes with Mingw reside in the Lib directory. They are all named in the following way: lib*.a
To link a library with your project, just add in Project options, Further option files :

-lopengl32

This is for including the libopengl32.a library. To add any other library, just follow the same syntax:
Type -l (L in lowercase) plus the base name of the library (filename without lib and the .a extension).

You may also consider putting a -L option there to add directory pathes searched for libraries.


Qt Creator

In order to add include paths you have to open up the .pro file and then add
the directories to the INCLUDEPATH variable. These paths are separated by spaces. Reference can be found here.

Showing INCLUDEPATH


If none of the above samples applies for your actually used IDE/toolchain, I hope you're able to get the point of abstraction:

It's an issue how to provide compiling/linking options to your actual toolchain. The IDE used to setup the context is a minor point here.

How to import external libraries and projects into my C++ Project with the GUI?

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.

Using a C++ Library in a C Project causes a long list of errors

This problem looks like a bug in MinGW GCC.

  • Using GCC 3.4.5: Error as posted above
  • Using GCC 4.7.2: No Error

Also make sure -lstdc++ is the last (!) of your -l flags.

Imported Type Library no longer working

I ended up re-importing the type libraries needed and deleting the old ones, as suggested by Remy Lebeau. It was Microsoft's libraries for Message Queues and XML in my case.

Note that some other issues giving similar error messages CAN be that the compiler is just confused :). Try compiling without NO_STRICT defined.

Can't import library to project

GAE does not support python modules with C extensions. In their own words:

Application code written for the Python environment must be written exclusively in Python. Extensions written in the C language are not supported.

  • http://code.google.com/appengine/docs/whatisgoogleappengine.html

$ cloc Orange-2.0.0b/
1625 text files.
1508 unique files.
305 files ignored.

http://cloc.sourceforge.net v 1.53 T=5.0 s (251.4 files/s, 62502.0 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Python 714 25736 24393 90413
C++ <-- !!! 125 16505 5423 61998
HTML 235 8643 95 29406
C 22 2436 5794 14876
C/C++ Header 134 5982 4497 13878
CSS 6 318 81 1373
make 10 81 23 318
Javascript 1 14 52 91
SQL 5 5 5 50
DOS Batch 5 3 1 20
-------------------------------------------------------------------------------
SUM: 1257 59723 40364 212423
-------------------------------------------------------------------------------


Related Topics



Leave a reply



Submit