Skip to content

Commit c84408e

Browse files
committed
define extern C also functions implemented in qgsgrassgislib.cpp, it should make functions visible on Windows
1 parent c4d8e5a commit c84408e

File tree

3 files changed

+81
-11
lines changed

3 files changed

+81
-11
lines changed

src/providers/grass/CMakeLists.txt

Lines changed: 76 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,67 @@ SET ( FUNCTIONS
116116
"G_zero"
117117
)
118118

119+
# List of functions which are implemented in qgsgrassgislib.cpp and
120+
# thus we only need prototype
121+
SET ( FUNCTION_PROTOTYPES
122+
"G__gisinit"
123+
"G_parser"
124+
"G_set_error_routine"
125+
"G_warning"
126+
"G_fatal_error"
127+
"G_done_msg"
128+
"*G_find_cell2"
129+
"*G_find_cell"
130+
"G_open_cell_old"
131+
"G_close_cell"
132+
"G_open_raster_new"
133+
"G_open_cell_new"
134+
"G_raster_map_is_fp"
135+
"G_read_fp_range"
136+
"G_read_range"
137+
"G_debug"
138+
"G_message"
139+
"G_verbose_message"
140+
"G_set_quant_rules"
141+
"G_get_raster_row"
142+
"G_get_raster_row_nomask"
143+
"G_get_c_raster_row"
144+
"G_get_c_raster_row_nomask"
145+
"G_get_f_raster_row"
146+
"G_get_f_raster_row_nomask"
147+
"G_get_d_raster_row"
148+
"G_get_d_raster_row_nomask"
149+
"G_get_map_row"
150+
"G_get_map_row_nomask"
151+
"G_put_raster_row"
152+
"G_check_input_output_name"
153+
"G_get_cellhd"
154+
"G_database_units_to_meters_factor"
155+
"G_begin_distance_calculations"
156+
"G_distance"
157+
"G_legal_filename"
158+
"G_tempfile"
159+
"G_mapset"
160+
"G_location"
161+
"G_write_colors"
162+
"G_quantize_fp_map_range"
163+
"G_read_raster_cats"
164+
"G_write_raster_cats"
165+
"G_short_history"
166+
"G_write_history"
167+
"G_maskfd"
168+
"G_command_history"
169+
"G_set_cats_title"
170+
"G_read_history"
171+
"G_read_colors"
172+
"G_make_aspect_fp_colors"
173+
)
174+
175+
SET ( FUNCTIONS_ALL
176+
${FUNCTIONS}
177+
${FUNCTION_PROTOTYPES}
178+
)
179+
119180
# Read GRASS header file and create functions mapping
120181
FILE(READ "${GRASS_INCLUDE_DIR}/grass/gisdefs.h" HEADER_FILE)
121182

@@ -130,7 +191,7 @@ LIST ( APPEND PROTOTYPES "#define GRASS_GISDEFS_H\n" )
130191
LIST ( APPEND PROTOTYPES "extern \"C\"\n" )
131192
LIST ( APPEND PROTOTYPES "{\n" )
132193
LIST ( APPEND PROTOTYPES "#include <grass/gis.h>\n" )
133-
LIST ( APPEND PROTOTYPES "int GRASS_LIB_EXPORT G_set_error_routine(int (*)(const char *, int))\;\n" )
194+
#LIST ( APPEND PROTOTYPES "int GRASS_LIB_EXPORT G_set_error_routine(int (*)(const char *, int))\;\n" )
134195

135196
SET ( FUNCTIONS_MAP "// Auto generated by cmake, do not edit\n" )
136197
LIST ( APPEND FUNCTIONS_MAP "#include \"qgsgrassgislibfunctions.h\"\n" )
@@ -144,9 +205,8 @@ FOREACH( ROW ${HEADER_FILE} )
144205
#MESSAGE (STATUS, "ROW: ${ROW}")
145206
# Parse function declaration
146207
STRING( REGEX REPLACE ".*(G_[^\\(]*)\\(.*" "\\1" FUNCTION_NAME "${ROW}" )
147-
FOREACH( FN ${FUNCTIONS})
208+
FOREACH( FN ${FUNCTIONS_ALL})
148209
IF ( "${FN}" STREQUAL "${FUNCTION_NAME}" )
149-
LIST ( APPEND FUNCTIONS_MAP "// ${ROW}\n" )
150210
# \\*? and \\** patterns do not work, why?
151211
STRING( REGEX REPLACE "^[ \t]*(.*)G_.*" "\\1" FUNCTION_TYPE "${ROW}" )
152212
STRING( REGEX REPLACE "\\*" "" FUNCTION_TYPE "${FUNCTION_TYPE}" )
@@ -170,15 +230,21 @@ FOREACH( ROW ${HEADER_FILE} )
170230
STRING( REPLACE ";" ", " PARAM_NAMES "${PARAM_NAMES}" )
171231
STRING( REPLACE ";" ", " PARAMS "${PARAMS}" )
172232

173-
# Declare function type
174-
LIST ( APPEND FUNCTIONS_MAP "typedef ${FUNCTION_TYPE} ${POINTER} ${FUNCTION_NAME}_type(${PARAM_TYPES})\;\n\n" )
175-
LIST ( APPEND FUNCTIONS_MAP "${FUNCTION_TYPE} GRASS_LIB_EXPORT ${POINTER} ${FUNCTION_NAME} ( ${PARAMS} ) {\n" )
233+
# Declare all
176234
LIST ( APPEND PROTOTYPES "${FUNCTION_TYPE} GRASS_LIB_EXPORT ${POINTER} ${FUNCTION_NAME} ( ${PARAM_TYPES} )\;\n" )
177-
#LIST ( APPEND FUNCTIONS_MAP " QgsDebugMsg( \"Entered\" )\;\n" )
178235

179-
LIST ( APPEND FUNCTIONS_MAP " ${FUNCTION_NAME}_type* fn = (${FUNCTION_NAME}_type*) cast_to_fptr (QgsGrassGisLib::instance()->resolve( \"${FUNCTION_NAME}\" ))\;\n" )
180-
LIST ( APPEND FUNCTIONS_MAP " return fn( ${PARAM_NAMES} )\;\n")
181-
LIST ( APPEND FUNCTIONS_MAP "}\n\n" )
236+
# Define only those not implemented in qgsgrassgislib.cpp
237+
LIST (FIND FUNCTIONS "${FUNCTION_NAME}" FUNCTION_IDX)
238+
IF( ${FUNCTION_IDX} GREATER -1 )
239+
LIST ( APPEND FUNCTIONS_MAP "// ${ROW}\n" )
240+
# Declare function type
241+
LIST ( APPEND FUNCTIONS_MAP "typedef ${FUNCTION_TYPE} ${POINTER} ${FUNCTION_NAME}_type(${PARAM_TYPES})\;\n\n" )
242+
LIST ( APPEND FUNCTIONS_MAP "${FUNCTION_TYPE} GRASS_LIB_EXPORT ${POINTER} ${FUNCTION_NAME} ( ${PARAMS} ) {\n" )
243+
#LIST ( APPEND FUNCTIONS_MAP " QgsDebugMsg( \"Entered\" )\;\n" )
244+
LIST ( APPEND FUNCTIONS_MAP " ${FUNCTION_NAME}_type* fn = (${FUNCTION_NAME}_type*) cast_to_fptr (QgsGrassGisLib::instance()->resolve( \"${FUNCTION_NAME}\" ))\;\n" )
245+
LIST ( APPEND FUNCTIONS_MAP " return fn( ${PARAM_NAMES} )\;\n")
246+
LIST ( APPEND FUNCTIONS_MAP "}\n\n" )
247+
ENDIF ( ${FUNCTION_IDX} GREATER -1 )
182248
ENDIF ( "${FN}" STREQUAL "${FUNCTION_NAME}" )
183249
ENDFOREACH ( FN )
184250
ENDFOREACH( ROW )

src/providers/grass/qgsgrassgislib.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#include <stdarg.h>
1919
#include <QtGlobal>
2020

21+
// If qgsgrassgislibfunctions.h is included on Linux, symbols defined here
22+
// cannot be found (undefined symbol error) even if they are present in
23+
// the library (in code section) - why?
2124
#ifdef Q_OS_WIN
2225
#include "qgsgrassgislibfunctions.h"
2326
#endif
@@ -41,6 +44,7 @@
4144

4245
#include <QTextCodec>
4346

47+
#if 0
4448
extern "C"
4549
{
4650
#ifndef _MSC_VER
@@ -50,6 +54,7 @@ extern "C"
5054
#include <grass/Vect.h>
5155
#include <grass/version.h>
5256
}
57+
#endif
5358

5459
#if !defined(GRASS_VERSION_MAJOR) || \
5560
!defined(GRASS_VERSION_MINOR) || \

src/providers/grass/qgsgrassgislib.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
extern "C"
2121
{
2222
#include <grass/gis.h>
23-
#include <grass/form.h>
2423
}
2524

2625
#include <stdexcept>

0 commit comments

Comments
 (0)