N
N
Nikita Savinykh2017-01-15 20:59:50
C++ / C#
Nikita Savinykh, 2017-01-15 20:59:50

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.

Now a question.
There is a simple example, which was taken solely for performance testing:
/* 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);
}

When I try to compile the source code on the command line, I get the following (blank lines added for readability):
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

A huge request to knowledgeable people, explain what I'm doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2017-01-15
@Ukio_G

You didn't tell the linker the path to the library, and he doesn't know where to get method implementations from the gd.h header file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question