Answer the question
In order to leave comments, you need to log in
Can't use functions from .c file even though it's declared in .h file. what to do?
Good day.
Yesterday I created a topic where I had problems compiling c++ source code using the libgd library.
As a result, not without help on this resource, it turned out to connect everything, but a new
problem arose - the function, the implementation of which is described in gd_filter.c, does not allow compiling an executable file in any way. There are 2 scenarios, not really sure about the second one, so I'll give the first one first:
/* 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 `[email protected]'
collect2.exe: error: ld returned 1 exit status
/* 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)
...
BGD_DECLARE(int) gdImageContrast(gdImagePtr src, double contrast);
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