Skip to content

Commit

Permalink
DLL-Export data in libmatc on Windows.
Browse files Browse the repository at this point in the history
For data to be exported from a DLL on Windows, it has to be marked with
a `dllexport` attribute. For users of the DLL, the same symbol has to be
marked with a `dllimport` attribute.

Do that with `listheaders` in libmatc to avoid linker errors like the
following for ElmerGUI:
```
D:/a/_temp/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ElmerGUI/Application/CMakeFiles/ElmerGUI.dir/vtkpost/matc.cpp.obj:matc.cpp:(.rdata$.refptr.listheaders[.refptr.listheaders]+0x0): undefined reference to `listheaders'
```
  • Loading branch information
mmuetzel committed Aug 26, 2024
1 parent fd3f80e commit b550a33
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 17 deletions.
7 changes: 7 additions & 0 deletions ElmerGUI/matc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ FILE(GLOB SOURCES "src/*.c")

IF(NOT(WITH_ELMERGUI))
ADD_LIBRARY(matc ${SOURCES})
IF(${BUILD_SHARED_LIBS})
target_compile_definitions(matc PRIVATE BUILD_MATC_DLL)
set_target_properties(matc PROPERTIES
WINDOWS_EXPORT_ALL_SYMBOLS ON)
ELSE()
target_compile_definitions(matc PUBLIC MATC_STATIC)
ENDIF()
INSTALL(TARGETS matc RUNTIME DESTINATION "bin" LIBRARY DESTINATION "lib"
ARCHIVE DESTINATION "lib" COMPONENT "elmergui")
ENDIF()
56 changes: 39 additions & 17 deletions ElmerGUI/matc/src/elmer/matc.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


/*
* $Id: matc.h,v 1.2 2007/06/08 08:12:19 jpr Exp $
* $Id: matc.h,v 1.2 2007/06/08 08:12:19 jpr Exp $
*
* $Log: matc.h,v $
* Revision 1.2 2007/06/08 08:12:19 jpr
Expand All @@ -24,7 +24,7 @@
* Revision 1.2 1998/08/01 12:34:49 jpr
*
* Added Id, started Log.
*
*
*
*/

Expand All @@ -46,6 +46,28 @@
#define EXT extern
#endif

#if !defined (_WIN32) || defined (MATC_STATIC)
# define MATC_API
#elseif defined (_WIN32)
# if defined (BUILD_MATC_DLL)
# if defined (__GNUC__)
/* GCC */
# define MATC_API __attribute__ ((dllexport))
# else
/* MSVC */
# define MATC_API __declspec(dllexport)
# endif
# else
# if defined (__GNUC__)
/* GCC */
# define MATC_API __attribute__ ((dllimport))
# else
/* MSVC */
# define MATC_API __declspec(dllimport)
# endif
# endif
#endif

/*******************************************************************
LIST HANDLING DEFINITIONS
*******************************************************************/
Expand All @@ -60,22 +82,22 @@ typedef struct list {
*/
#ifdef MODULE_MATC

EXT LIST listheaders[5] = {
MATC_API EXT LIST listheaders[5] = {
{
NULL, "Allocations" /* memory allocations */
}, {
NULL, "Constants" /* global CONSTANTS */
NULL, "Constants" /* global CONSTANTS */
}, {
NULL, "Currently defined VARIABLES" /* global VARIABLES */
}, {
}, {
NULL, "Builtin Functions" /* internal commands */
}, {
NULL, "User Functions" /* user defined functions */
}
};
#else

EXT LIST listheaders[];
MATC_API EXT LIST listheaders[];

#endif

Expand Down Expand Up @@ -182,7 +204,7 @@ typedef struct command
#define COMSIZE sizeof(COMMAND)

#define CMDFLAG_PW 1 /* element by element operation */
#define CMDFLAG_CE 2 /* command can be executed when
#define CMDFLAG_CE 2 /* command can be executed when
preprocessing if constant
arguments. */

Expand Down Expand Up @@ -211,7 +233,7 @@ typedef struct function
typedef enum symbols {
nullsym, leftpar, rightpar, indopen, indclose, power, times, ptimes, divide,
plus, minus, reduction, transpose, eq, neq, lt, gt, le, ge, and, or, not,
assignsym, apply, resize, vector, statemend, argsep, name, number, string,
assignsym, apply, resize, vector, statemend, argsep, name, number, string,
funcsym, import, export, ifsym, thensym, elsesym, whilesym, forsym,
beginsym, endsym, breaksym, comment, systemcall
} SYMTYPE;
Expand All @@ -236,7 +258,7 @@ char csymbols[] = {
/*--------------------------------------------------------------------*/

char *reswords[] = {
"function", "import", "export", "if", "then", "else", "while", "for",
"function", "import", "export", "if", "then", "else", "while", "for",
"begin", "end", "break", NULL
};

Expand Down Expand Up @@ -370,7 +392,7 @@ typedef struct clause

EXT FILE *math_in, *math_out, *math_err;

/*
/*
see doread(), error() in matc.c
*/
EXT jmp_buf *jmpbuf;
Expand All @@ -379,8 +401,8 @@ EXT int term;

#ifdef VAX
struct desc
{
int length;
{
int length;
char *addr;
} ;
#endif
Expand Down Expand Up @@ -409,7 +431,7 @@ void error( char *format, ... )
va_start( args, format );
#ifdef STRING_OUTPUT
if ( math_out_count+512 > math_out_allocated )
{
{
math_out_allocated += 512;
math_out_str = (char *)realloc( math_out_str, math_out_allocated );
}
Expand All @@ -433,7 +455,7 @@ void PrintOut( char *format, ... )
va_start( args, format );
#ifdef STRING_OUTPUT
if ( math_out_count+512 > math_out_allocated )
{
{
math_out_allocated += 512;
math_out_str = (char *)realloc( math_out_str, math_out_allocated );
}
Expand All @@ -449,11 +471,11 @@ extern void PrintOut( char *format, ... );
#endif

/*******************************************************************
function prototypes
*******************************************************************/
function prototypes
*******************************************************************/
#include "fnames.h"

/*******************************************************************
graphics package definitions
*******************************************************************/
*******************************************************************/
#include "gra.h"

0 comments on commit b550a33

Please sign in to comment.