installing external 'library?' in codeblocks - c++

I'm new to programming and wanted to check this program called primesieve. http://primesieve.org/
I have windows 7 with codeblocks ide.
I tried searching for a way to execute the program but couldnt find anything useful.
I have never added a library (is that called a library?) before so please help.
similar:
Installing c library in codeblocks
cant install GMP library in codeblocks

You should have received a .h (or .hpp) file and a .lib file, most likely with the names primesieve.h (or primesieve.hpp) and primesieve.lib (or something similar).
If you didn't receive those files in your download, then you may have to download the source. It should definitely have the .h/.hpp file, but it's possible you'll need to generate the .lib file yourself. There should be instructions for your system.
You need to include the .h/.hpp file in your source code. You need to link against the .lib file. This part is described in the articles you linked.

Related

How to use C++ libraries?

I am a Python developer and I have not used C++ since university. I am doing scientific programming with python, mainly. I wanted to try C++ to see if it is better performance-wise.
I am quite new in C++. I have found dlib library, which seemed a good library as it had many interesting features. But when I downloaded it, I found several folder full of .h and .cpp files.
In Python, I would have installed a wanted library using pip or something, then use it in my project using import.
Is there a similar installation for c++ libraries? Or do I have to look among all those .h and .cpp files and decide which ones I need in my project then copy them? Or how do I use the dlib library?
I have searched a lot on google but I could not find any indication on how to use a c++ library or install a new package to be used.
I use Visual Studio Community 2017 and Windows 10 if that matters.
To integrate a library, you need two kinds of things:
header files (usually *.h) with the declarations required to let the compiler know about the features in the library (a little similar to an import statement);
compiled library files (usually *.lib) containing the precompiled executable code itself, to let the linker assemble the final executable file.
In some cases (especially for templated code), a library can be made of header files only. In other cases, the package doesn't contain a ready-made library file and you have to build it yourself or manually include the source files (*.c/cpp) in your project.
Not speaking of the innumerable optional settings that you may have to adjust to comply with the specifics of the generated code, such as function calling convention, struct alignment...
Last but not least, some libraries are connected to at run-time only. They are called Dynamic Link Libraries and involve yet different procedures.
All of this is relatively complex and close to black magic for beginners. If you are very lucky, you will find some library documentation telling you which options to use for your compiler. If you can, start from an existing sample project that works!
For dlib, check http://dlib.net/compile.html.
Be ready for a cultural shock when you will compare to the ease of use of the Python modules.
It is quite a broad question, but I'll do my best.
First of all, in C++ libraries consist of header files and precompiled part (.lib,.dll on Windows, .a, .so on Linux). To use them in your project you have to inform your program (and compiler) about features that library has (by #including their header file) and linker to include that library binaries.
pip is package manager, which automatically downloads, builds and installs library that you want in your system. In C++ there is no such single tool at the moment and there steps must be done more or less manually.
For dowloading you usually end up with git or downloading the zip archive with source (do it here). Once you have sources you have to build it.
In order to achieve multiplatformity libraries usually does not get shipped with concrete build system description (Visual Studio Project on Windows or makefile on Linux etc.), but are created in more general tool CMake, which abstracts them. E.g. dlib does that. With use of CMake (For start I recommend CMake-GUI, which is installed with CMake on Windows) you can generate Visual Studio Project, which later you can open and compile to generate .lib file. How exactly to do it follow dlib compilation description.
Once you have you lib and headers files on your disk you can add headers and .lib to your Visual Project and use as any other C++ library. (Seems old, but should work)
As far as I know, there are no tools similar to pip for C++. What you have to do depends on your working environment and the respective library.
In case of dlib there are instructions on the project homepage for Visual Studio. Basically, it involves compiling the whole library alongside your own project by copying a single source file to it and setting up include pathes.
From http://dlib.net/compile.html:
Compiling on Windows Using Visual Studio 2015 or Newer
All you need to do is create an empty console project. Then add dlib/all/source.cpp to it and add the folder containing the dlib folder to the #include search path. Then you can compile any example program by adding it to your project.
Again, note that dlib will only be able to work with jpeg and png files if you link in libjpeg and libpng. In Visual Studio, the easiest way to do this is to add all the libjpeg, libpng, and zlib source files in the dlib/external folder into your project and also define the DLIB_PNG_SUPPORT and DLIB_JPEG_SUPPORT preprocessor directives. If you don't know how to configure Visual Studio then you should use CMake as shown above since it will take care of everything automatically.
You have to download them, put them in your project directory, and then include them almost the same way you would do in python. You need to include only the .h files.
Example for test.h:
#include "test.h"
Hope this helps!

Netbeans C++ using MinGW and the libnoise library

Using netbeans 7.2 and the most recent version of MinGW (using installer) I can't use the libnoise library. I am properly including the header files, the auto completion confirms this, however the library is simply not working. There is a .lib file and a .dll. I have tried every possible combination of adding them under project > properties > Build > Linker as well as putting the .dll in the base project directory. Despite all this I am still getting undefined reference errors whenever I try and run the code. Does anyone know what to do?
I know that it is possible to link import library files (*.lib) with MinGW, but I still suggest to recompile libnoise.
With the current Makefile, this is not very easy and may break. Thus I've written a CMake script, which doesn't only work on Windows, but should work on all CMake supported platforms. In addition to this, I've cleaned up the directory structure. The code itself hasn't been touched and when you build a library it should essentially be the same as the current one.
libnoise on GitHub
After you've built your shared library, you'll have a libnoise.dll.a and libnoise.dll file. You then add libnoise.dll.a to the linking settings and put the DLL itself next to the binary, or in the working directory.
You have to link the lib file (= adding it to linker libraries) and put the dll to
<project root>/dist/<...>/
(where your exe is put to). There's no need to add the dll to linker too.
Can you please post the error message you get?

Installing C++ DLL, Header files, and Lib files in Windows

What I am trying to do is exactly like the instructions on this website:
http://www.cprogramming.com/tutorial/sdl/setup.html
The only problem is that I didn't download the version of Code Blocks that comes with the mingw32 compiler. I got the latest release from http://www.equation.com/servlet/equation.cmd?fa=fortran and installed it in 'C:\gcc'. So, the folders that it is asking me to move files into don't exist.
The article asked me to download this file:
SDL-devel-1.2.15-mingw32.tar
Then in that file move the 'include\SDL' folder into the 'C:\Program Files\CodeBlocks\include'. (I don't have a CodeBlocks\include folder)
It then asked me to move the 'SDL.dll' to 'C:\Windows' which I was able to do.
Finally it wanted me to copy the contents of the 'lib' folder into the 'CodeBlocks\lib' folder. (Another folder I don't have because I installed my compiler separately from the Code Blocks install)
Since I installed my compiler at 'C:\gcc' I tried to add the files into the 'C:\gcc\include' and 'C:\gcc\lib' files, but that didn't work.
I am not very familiar with the process of using 3rd party libraries. I usually use Java where you can just stick the .jar file in with your code. Do I need the .dll, include, and lib files. Where do I actually need to put them? I would also appreciate knowing why as well?

Working with DLL in a C++ application

I'm planning to use id3lib in my application. I'm looking for a way to use the library as a DLL. I've noticed that they released the library in various form: one of which is windows binary. My target platform in Windows, and I'll use Qt 4.8. After I extract the files in windows binary, I found the following files in Release folder:
id3lib.dll
id3lib.exp
id3lib.lib
I know how to use a DLL in Qt given the DLL, one or more header files where function prototypes resides, and with or without the *.lib file. This package doesn't come with a header file.
How am I supposed to use this package without any header file? What's the purpose of the *.lib and *.exp files here? As far as I know *.lib files are used for static linking with functions which I don't want in my program.
You've just missed the header. It is available under the include subfolder (see here), also the .lib file is still needed for linking, even if you'll be using the DLL.
The usual course is to use a header file #included in the C++ file, the .lib file to link to and the .dll is required at run time.
The header file should/may be in another package as the same header is probably used for different kinds of linking strategies.
At worst you should be able to use a tool such as depends.exe to view the exported symbols and create your own h file to match - but it would be better to find a .h file issued with the release.

Build libiconv library

I want to convert S-JIS string to EUC string. I searched on the internet and find out libiconv library which can do that. I downloaded version 1.9 for windows and did converting.
However, there are some characters which this library can not convert. I also found new version of libiconv 1.13 but there is no library for windows to download, just have source to build.
I tried to build in cygwin and get some files as the below.
libiconv.dll.a
libiconv.la
...
Could you please to guide me to build library.
Thanks,
Ankata
I do not have experience about using libiconv under windows. But it seems that your problem is mainly a compiling problem.
libiconv.dll: the file where libiconv function entrys is stored
libiconv.la : in my opinion, should be a lib file used to link the entry address information to your programm
Besides, these file, you also need the "header" files that libiconv should provide.
You include the header file when you edit your code using libicon, and add the libiconv.la file to your link file list when you compile your code.
If you want run your program, you should put the libiconv.dll under the exe file folder.
As well, if you want to run your program out of cygwin environment, you may also need to copy cygwin1.dll under your exe folder.
Just some suggestion, wish it could help you.