Dear GMT friends,
I try to Compile the api C example code:
#include "gmt.h"
int main (int argc, char *argv[]) {
void *API; /* The API control structure */
struct GMT_DATASET *D = NULL; /* Structure to hold input dataset */
struct GMT_GRID *G = NULL; /* Structure to hold output grid */
char input[GMT_STR16] = {""}; /* String to hold virtual input filename */
char output[GMT_STR16] = {""}; /* String to hold virtual output filename */
char args[128] = {""}; /* String to hold module command arguments */
/* Initialize the GMT session */
API = GMT_Create_Session ("test", 2U, 0, NULL);
/* Read in our data table to memory */
D = GMT_Read_Data (API, GMT_IS_DATASET, GMT_IS_FILE, GMT_IS_PLP, GMT_READ_NORMAL, NULL,
"@table_5.11", NULL);
/* Associate our data table with a virtual file */
GMT_Open_VirtualFile (API, GMT_IS_DATASET, GMT_IS_PLP, GMT_IN, D, input);
/* Create a virtual file to hold the resulting grid */
GMT_Open_VirtualFile (API, GMT_IS_GRID, GMT_IS_SURFACE, GMT_OUT, NULL, output);
/* Prepare the module arguments */
sprintf (args, "-R0/7/0/7 -I0.2 -D1 -St0.3 %s -G%s", input, output);
/* Call the greenspline module */
GMT_Call_Module (API, "greenspline", GMT_MODULE_CMD, args);
/* Obtain the grid from the virtual file */
G = GMT_Read_VirtualFile (API, output);
/* Close the virtual files */
GMT_Close_VirtualFile (API, input);
GMT_Close_VirtualFile (API, output);
/* Write the grid to file */
GMT_Write_Data (API, GMT_IS_GRID, GMT_IS_FILE, GMT_IS_SURFACE, GMT_READ_NORMAL, NULL,
"junk.nc", G);
/* Destroy the GMT session */
GMT_Destroy_Session (API);
};
Then set:
inc=`gmt-config --cflags`
lib=`gmt-config --libs`
gcc example1.c $inc $lib -o example1
But given error:
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\yangleir\AppData\Local\Temp\ccJ1yhUf.o:main.c:(.text+0xba): undefined reference to `_imp__GMT_Create_Session'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\yangleir\AppData\Local\Temp\ccJ1yhUf.o:main.c:(.text+0x10a): undefined reference to `_imp__GMT_Read_Data'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\yangleir\AppData\Local\Temp\ccJ1yhUf.o:main.c:(.text+0x150): undefined reference to `_imp__GMT_Open_VirtualFile'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\yangleir\AppData\Local\Temp\ccJ1yhUf.o:main.c:(.text+0x18c): undefined reference to `_imp__GMT_Open_VirtualFile'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\yangleir\AppData\Local\Temp\ccJ1yhUf.o:main.c:(.text+0x1df): undefined reference to `_imp__GMT_Call_Module'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\yangleir\AppData\Local\Temp\ccJ1yhUf.o:main.c:(.text+0x1fb): undefined reference to `_imp__GMT_Read_VirtualFile'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\yangleir\AppData\Local\Temp\ccJ1yhUf.o:main.c:(.text+0x21e): undefined reference to `_imp__GMT_Close_VirtualFile'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\yangleir\AppData\Local\Temp\ccJ1yhUf.o:main.c:(.text+0x23a): undefined reference to `_imp__GMT_Close_VirtualFile'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\yangleir\AppData\Local\Temp\ccJ1yhUf.o:main.c:(.text+0x286): undefined reference to `_imp__GMT_Write_Data'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\yangleir\AppData\Local\Temp\ccJ1yhUf.o:main.c:(.text+0x297): undefined reference to `_imp__GMT_Destroy_Session'
collect2.exe: error: ld returned 1 exit status
The compile environment is MINGW64 gcc under win10.
Could someone give me some clues?