Доброго времени суток.
Вчера мною была создана
тема, где у меня возникали проблемы с компиляцией исходного c++ кода с использованием libgd библиотеки.
В итоге, не без помощи на этом ресурсе, получилось все подключить, но возникла новая
проблема - функция, реализация которой описана в gd_filter.c никак не позволяет скомпилировать исполняемый файл. Есть 2 сценария, не совсем уверен во втором, поэтому сначала приведу первый :
/* Bring in gd library functions */
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include "src/gd.h"
//#include "src/gd_filter.c"
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);
/* Do the same for a JPEG-format file. */
jpegout = fopen("test.jpg", "wb");
gdImageContrast(im,20);
/* 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>gcc CPPImageCorrector.cpp -o CPPImageCorrector.exe -lgd.dll
C:\Users\0BD6~1\AppData\Local\Temp\cc3tfPz0.o:CPPImageCorrector.cpp:(.text+0x5a)
: undefined reference to `_imp__gdImageContrast@12'
collect2.exe: error: ld returned 1 exit status
Если подключаю gd_filter.c :
/* Bring in gd library functions */
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include "src/gd.h"
#include "src/gd_filter.c"
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);
/* Do the same for a JPEG-format file. */
jpegout = fopen("test.jpg", "wb");
gdImageContrast(im,20);
/* 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>gcc CPPImageCorrector.cpp -o CPPImageCorrector.exe -lgd.dll
In file included from src/gd_intern.h:29:0,
from src/gd_filter.c:7,
from CPPImageCorrector.cpp:6:
src/msinttypes/inttypes.h:33:2: error: #error "Use this header only with Microso
ft Visual C++ compilers!"
#error "Use this header only with Microsoft Visual C++ compilers!"
^
In file included from src/msinttypes/inttypes.h:43:0,
from src/gd_intern.h:29,
from src/gd_filter.c:7,
from CPPImageCorrector.cpp:6:
src/msinttypes/stdint.h:33:2: error: #error "Use this header only with Microsoft
Visual C++ compilers!"
#error "Use this header only with Microsoft Visual C++ compilers!"
^
In file included from src/gd_intern.h:29:0,
from src/gd_filter.c:7,
from CPPImageCorrector.cpp:6:
src/msinttypes/inttypes.h:278:1: error: '_inline' does not name a type
_inline
^
In file included from CPPImageCorrector.cpp:6:0:
src/gd_filter.c:40:18: error: function 'int gdImageScatter(gdImagePtr, int, int)
' definition is marked dllimport
BGD_DECLARE(int) gdImageScatter(gdImagePtr im, int sub, int plus)
^
src/gd_filter.c: In function 'int gdImageScatter(gdImagePtr, int, int)':
src/gd_filter.c:40:18: warning: 'int gdImageScatter(gdImagePtr, int, int)' redec
lared without dllimport attribute: previous dllimport ignored [-Wattributes]
src/gd_filter.c: At global scope:
src/gd_filter.c:54:18: error: function 'int gdImageScatterColor(gdImagePtr, int,
int, int*, unsigned int)' definition is marked dllimport
BGD_DECLARE(int) gdImageScatterColor(gdImagePtr im, int sub, int plus, int colo
rs[], unsigned int num_colors)
^
src/gd_filter.c: In function 'int gdImageScatterColor(gdImagePtr, int, int, int*
, unsigned int)':
src/gd_filter.c:54:18: warning: 'int gdImageScatterColor(gdImagePtr, int, int, i
nt*, unsigned int)' redeclared without dllimport attribute: previous dllimport i
gnored [-Wattributes]
src/gd_filter.c: At global scope:
src/gd_filter.c:69:18: error: function 'int gdImageScatterEx(gdImagePtr, gdScatt
erPtr)' definition is marked dllimport
BGD_DECLARE(int) gdImageScatterEx(gdImagePtr im, gdScatterPtr scatter)
^
src/gd_filter.c: In function 'int gdImageScatterEx(gdImagePtr, gdScatterPtr)':
src/gd_filter.c:69:18: warning: 'int gdImageScatterEx(gdImagePtr, gdScatterPtr)'
redeclared without dllimport attribute after being referenced with dll linkage
src/gd_filter.c: At global scope:
src/gd_filter.c:131:18: error: function 'int gdImagePixelate(gdImagePtr, int, un
signed int)' definition is marked dllimport
BGD_DECLARE(int) gdImagePixelate(gdImagePtr im, int block_size, const unsigned
int mode)
^
src/gd_filter.c: In function 'int gdImagePixelate(gdImagePtr, int, unsigned int)
':
src/gd_filter.c:131:18: warning: 'int gdImagePixelate(gdImagePtr, int, unsigned
int)' redeclared without dllimport attribute: previous dllimport ignored [-Wattr
ibutes]
src/gd_filter.c: At global scope:
src/gd_filter.c:192:18: error: function 'int gdImageNegate(gdImagePtr)' definiti
on is marked dllimport
BGD_DECLARE(int) gdImageNegate(gdImagePtr src)
^
src/gd_filter.c: In function 'int gdImageNegate(gdImagePtr)':
src/gd_filter.c:192:18: warning: 'int gdImageNegate(gdImagePtr)' redeclared with
out dllimport attribute: previous dllimport ignored [-Wattributes]
src/gd_filter.c: At global scope:
src/gd_filter.c:228:18: error: function 'int gdImageGrayScale(gdImagePtr)' defin
ition is marked dllimport
BGD_DECLARE(int) gdImageGrayScale(gdImagePtr src)
^
src/gd_filter.c: In function 'int gdImageGrayScale(gdImagePtr)':
src/gd_filter.c:228:18: warning: 'int gdImageGrayScale(gdImagePtr)' redeclared w
ithout dllimport attribute: previous dllimport ignored [-Wattributes]
src/gd_filter.c: At global scope:
src/gd_filter.c:265:18: error: function 'int gdImageBrightness(gdImagePtr, int)'
definition is marked dllimport
BGD_DECLARE(int) gdImageBrightness(gdImagePtr src, int brightness)
^
src/gd_filter.c: In function 'int gdImageBrightness(gdImagePtr, int)':
src/gd_filter.c:265:18: warning: 'int gdImageBrightness(gdImagePtr, int)' redecl
ared without dllimport attribute: previous dllimport ignored [-Wattributes]
src/gd_filter.c: At global scope:
src/gd_filter.c:313:18: error: function 'int gdImageContrast(gdImagePtr, double)
' definition is marked dllimport
BGD_DECLARE(int) gdImageContrast(gdImagePtr src, double contrast)
^
src/gd_filter.c: In function 'int gdImageContrast(gdImagePtr, double)':
src/gd_filter.c:313:18: warning: 'int gdImageContrast(gdImagePtr, double)' redec
lared without dllimport attribute: previous dllimport ignored [-Wattributes]
src/gd_filter.c: At global scope:
src/gd_filter.c:376:18: error: function 'int gdImageColor(gdImagePtr, int, int,
int, int)' definition is marked dllimport
BGD_DECLARE(int) gdImageColor(gdImagePtr src, const int red, const int green, c
onst int blue, const int alpha)
^
src/gd_filter.c: In function 'int gdImageColor(gdImagePtr, int, int, int, int)':
src/gd_filter.c:376:18: warning: 'int gdImageColor(gdImagePtr, int, int, int, in
t)' redeclared without dllimport attribute: previous dllimport ignored [-Wattrib
utes]
src/gd_filter.c: At global scope:
src/gd_filter.c:421:18: error: function 'int gdImageConvolution(gdImagePtr, floa
t (*)[3], float, float)' definition is marked dllimport
BGD_DECLARE(int) gdImageConvolution(gdImagePtr src, float filter[3][3], float f
ilter_div, float offset)
^
src/gd_filter.c: In function 'int gdImageConvolution(gdImagePtr, float (*)[3], f
loat, float)':
src/gd_filter.c:421:18: warning: 'int gdImageConvolution(gdImagePtr, float (*)[3
], float, float)' redeclared without dllimport attribute: previous dllimport ign
ored [-Wattributes]
src/gd_filter.c: At global scope:
src/gd_filter.c:484:18: error: function 'int gdImageSelectiveBlur(gdImagePtr)' d
efinition is marked dllimport
BGD_DECLARE(int) gdImageSelectiveBlur( gdImagePtr src)
...
И так далее (ограничение на публикацию - 10000 символов).
gd.h строка 1135:
BGD_DECLARE(int) gdImageContrast(gdImagePtr src, double contrast);
В очередной раз прошу всех знающих помочь и объяснить, Что Я Делаю Не Так?
Использую для компиляции только MinGW из CMD из под Администратора.
Некоторые моменты касательно того, как библиотека была собрана можно прочитать в моей вчерашней
теме.