Answer the question
In order to leave comments, you need to log in
How to build third-party libraries in a C++ project?
Good day.
Of extreme interest is the question of how to properly build third-party libraries using the MSYS and MinGW tools, as well as include the compiled libraries in the code.
Actually, the essence of a particular situation:
There was a need to work with images (increasing contrast and cropping an image), a Google search pointed me to the libgd library, along with which additional modules for working with jpeg,png,tff and so on were downloaded (link to libgd - https://libgd.github.io/ ).
After a VERY long torment, libgd.dll and libgd.a were built by various hooks and crooks.
As far as I understand, libgd.a is a library for MinGW
www.cyberforum.ru/cpp-beginners/thread978847.html :
Libraries for MinGW have extension .a and prefix lib ( ie libsndfile-1.a ).
You either need to download the libraries for MinGW or build them yourself.
/* Bring in gd library functions */
#include "src/gd.h"
/* Bring in standard I/O so we can output the PNG to a file */
#include <stdio.h>
int main() {
/* Declare the image */
gdImagePtr im;
/* Declare output files */
FILE *pngout, *jpegout;
/* Declare color indexes */
int black;
int white;
/* Allocate the image: 64 pixels across by 64 pixels tall */
im = gdImageCreate(64, 64);
/* Allocate the color black (red, green and blue all minimum).
Since this is the first color in a new image, it will
be the background color. */
black = gdImageColorAllocate(im, 0, 0, 0);
/* Allocate the color white (red, green and blue all maximum). */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Draw a line from the upper left to the lower right,
using white color index. */
gdImageLine(im, 0, 0, 63, 63, white);
/* Open a file for writing. "wb" means "write binary", important
under MSDOS, harmless under Unix. */
pngout = fopen("test.png", "wb");
/* Do the same for a JPEG-format file. */
jpegout = fopen("test.jpg", "wb");
/* Output the image to the disk file in PNG format. */
gdImagePng(im, pngout);
/* Output the same image in JPEG format, using the default
JPEG quality setting. */
gdImageJpeg(im, jpegout, -1);
/* Close the files. */
fclose(pngout);
fclose(jpegout);
/* Destroy the image in memory. */
gdImageDestroy(im);
}
C:\CPPImageCorrecing>g++ CPPImageCorrector.cpp -o CPPImageCorrector.exe
C:\Users\0BD6~1\AppData\Local\Temp\ccy0WVTF.o:CPPImageCorrector.cpp:(.text+0x26)
: undefined reference to `[email protected]'
C:\Users\0BD6~1\AppData\Local\Temp\ccy0WVTF.o:CPPImageCorrector.cpp:(.text+0x51)
: undefined reference to `[email protected]'
C:\Users\0BD6~1\AppData\Local\Temp\ccy0WVTF.o:CPPImageCorrector.cpp:(.text+0x7c)
: undefined reference to `[email protected]'
C:\Users\0BD6~1\AppData\Local\Temp\ccy0WVTF.o:CPPImageCorrector.cpp:(.text+0xb6)
: undefined reference to `[email protected]'
C:\Users\0BD6~1\AppData\Local\Temp\ccy0WVTF.o:CPPImageCorrector.cpp:(.text+0xfb)
: undefined reference to `[email protected]'
C:\Users\0BD6~1\AppData\Local\Temp\ccy0WVTF.o:CPPImageCorrector.cpp:(.text+0x11a
): undefined reference to `[email protected]'
C:\Users\0BD6~1\AppData\Local\Temp\ccy0WVTF.o:CPPImageCorrector.cpp:(.text+0x140
): undefined reference to `[email protected]'
collect2.exe: error: ld returned 1 exit status
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question