Categories
IT Tricks Random

Install a library compiled in Codeblocks with MinGW

[ad_1]
#Install #library #compiled #Codeblocks #MinGW

How to use one of the versions of CodeBlocks compatible with the MinGW compiler to retrieve binaries from external libraries? Know in this article, the necessary requirements to install a library compiled in Codeblocks from MinGW and some methods to be successful in the operation.

  • Requirements

  • Methods

  • Comments

    • DLL files

    • Relative or absolute paths

    • Do not copy the external library into the Codeblocks MinGW directories

    • Terminology

Requirements

  • Have a version of Codeblocks that works with the MinGW compiler.
  • Have the binary of an external library that is also compiled for MinGW.

In the example below, we will use the library libcurl to demonstrate the chosen method. Know that, the method can be used with Codeblocks using MinGW for any library compiled for MinGW.

Methods

Unpacking in a directory that centralizes the external libraries used

Unzip the file containing the compiled library in a not too complicated directory, preferably a name without spaces, for example

c:libscurl-7.28.1-devel-mingw32

Codeblocks project integration: 2 steps

There are two things to consider when using Codeblocks so that a project can integrate an additional library:

1. Tell the compiler where to find the files with the extension H, allows this to generate errors when we insert the #include corresponding to the library in the source code.

we will make this indication in the Project – Build options…, then we click on the project root (in Debug or Target, otherwise the parameters would only apply at the destination).

In the window “Search directories” – Add – look for the library directory containing the H extensions. For example, in the case of libcurl, in

c:libscurl-7.28.1-devel-mingw32include

and select that directory.

2. Provide the editor with links to find the library binaries .

The fact of indicating to the editor links that serve to find the library binaries, allows to generate the executable after compilation. In the MinGW environment, the library binaries are files with an extension THE

This will be done in Project – Build options … , then we click on the project root, not on Debug or Target. Otherwise, the parameters would only apply at the destination, unless debug libraries are used.

Search in the window “Linker settings” – Add – the library directory containing the extensions A (for example, in the case of libcurl, in c: libs curl-7.28.1-devel-mingw32 lib) and select the parts of the library that the project needs.

Comments

DLL files

Depending on how you set up your project (dynamic or static link), you may have to copy .dll to the executable directory (or to the Windows PATH) so that the dynamic download of the library can be done.

In the case of libcurl, DLLs are in the

c:libscurl-7.28.1-devel-mingw32bin

They could be added, for example, in the directory Target of the project, containing the executable generated by the compilation (or somewhere in the PATH), and this will only be necessary in compilation with dynamic linking and, to launch the executable outside the development environment.

If you have not already done so, you will see, during execution (double-clicking the EXE file, that is, a message will warn you that this or that DLL was not found.

Relative or absolute paths

When setting up Codeblocks (see steps 2.2.1 and 2.2.2), after selecting a resource, you will be asked to answer this question Keep this as a relative path? (Maner this as a relative path?)

If the answer is affirmative, it means that CodeBlocks will not maintain the absolute path to the specified resource (ex:

c:libscurl-7.28.1-devel-mingw32liblibcurl.a

), but only the relative path in relation to the project directory (ex: something like

......libscurl-7.28.1-devel-mingw32liblibcurl.a

).

It is useful to specify a relative path if resources are available in the project directory, as the project will remain compile on another machine with CodeBlocks, since the resources are in the same place in relation to the project directory and that, whatever the location of the project on the new machine.

In return, if the resources are elsewhere (it is better to place them elsewhere, to bring libraries together in an identified place, where projects can find them, such as c: libs and avoid duplicating them), and if we move the project, the references will be broken. In this case, it is better to specify absolute paths.

Do not copy the external library into the Codeblocks MinGW directories

This can work and you can find tutorials that will tell you what to do.

However, I do not recommend this, unless you want to:

  • mess up the installation of CodeBlocks
  • having to reinstall all of your libraries to update CodeBlocks or MinGW and the default CodeBlocks or MinGW directories will be deleted and recreated in the process
  • not knowing where that version of the library is located that only compiles with that source that you use
  • not knowing how to update their libraries

Terminology

In the lines above, we use the term library, although the English term library is used a lot by programmers.

Photo: © Roman Samborskyi – 123RF.com

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *