undefined reference to 'RunSwmmDll(char*, char*, char*)'

Hello,
I have tried to 'google' this seemingly basic problem but all the suggestions I have found don't work.
I have a calling program "trial_1.cpp"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h>
#include "swmm5.h"
#include "swmm5_iface.h"

using namespace std;

char *inpfile;
char *rptfile;
char *outfile;

int main()
{
    RunSwmmDll(inpfile, rptfile, outfile);
}
that calls a function "RunSwmmDll".
This function is declared in "swmm5_iface.h"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// swmm5_iface.h
//
// Header file for SWMM 5 interfacing functions
//
// #include this file in any C module that references the functions
// contained in swmm5_iface.c.
//
extern int    SWMM_Nperiods;           // number of reporting periods
extern int    SWMM_FlowUnits;          // flow units code
extern int    SWMM_Nsubcatch;          // number of subcatchments
extern int    SWMM_Nnodes;             // number of drainage system nodes
extern int    SWMM_Nlinks;             // number of drainage system links
extern int    SWMM_Npolluts;           // number of pollutants tracked
extern double SWMM_StartDate;          // start date of simulation
extern int    SWMM_ReportStep;         // reporting time step (seconds)

int    RunSwmmExe(char* cmdLine);
int    RunSwmmDll(char* inpFile, char* rptFile, char* outFile);
int    OpenSwmmOutFile(char* outFile);
int    GetSwmmResult(int iType, int iIndex, int vIndex, int period, float* value);
void   CloseSwmmOutFile(void);


and defined in "swmm5_iface.c";
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// swmm5_iface.c
//
// Example code for interfacing SWMM 5 with C/C++ programs.
//
// Remember to #include the file swmm5_iface.h in the calling program.

#include <stdio.h>
//#include <windows.h>
#include "swmm5.h"

int    SWMM_Nperiods;                  // number of reporting periods
int    SWMM_FlowUnits;                 // flow units code
int    SWMM_Nsubcatch;                 // number of subcatchments
int    SWMM_Nnodes;                    // number of drainage system nodes
int    SWMM_Nlinks;                    // number of drainage system links
int    SWMM_Npolluts;                  // number of pollutants tracked
double SWMM_StartDate;                 // start date of simulation
int    SWMM_ReportStep;                // reporting time step (seconds)

int    RunSwmmExe(char* cmdLine);
int    RunSwmmDll(char* inpFile, char* rptFile, char* outFile);
int    OpenSwmmOutFile(char* outFile);
int    GetSwmmResult(int iType, int iIndex, int vIndex, int period, float* value);
void   CloseSwmmOutFile(void);

static const int SUBCATCH = 0;
static const int NODE     = 1;
static const int LINK     = 2;
static const int SYS      = 3;
static const int RECORDSIZE = 4;       // number of bytes per file record

static int SubcatchVars;               // number of subcatch reporting variables
static int NodeVars;                   // number of node reporting variables
static int LinkVars;                   // number of link reporting variables
static int SysVars;                    // number of system reporting variables

static FILE*  Fout;                    // file handle
static int    StartPos;                // file position where results start
static int    BytesPerPeriod;          // bytes used for results in each period
static void   ProcessMessages(void);
/*
//-----------------------------------------------------------------------------
int RunSwmmExe(char* cmdLine)
//-----------------------------------------------------------------------------
{
  int exitCode;
  STARTUPINFO si;
  PROCESS_INFORMATION  pi;

  // --- initialize data structures
  memset(&si, 0, sizeof(si));
  memset(&pi, 0, sizeof(pi));
  si.cb = sizeof(si);
  si.wShowWindow = SW_SHOWNORMAL;

  // --- launch swmm5.exe
  exitCode = CreateProcess(NULL, cmdLine, NULL, NULL, 0,
			 0, NULL, NULL, &si, &pi);

  // --- wait for program to end
  exitCode = WaitForSingleObject(pi.hProcess, INFINITE);

  // --- retrieve the error code produced by the program
  GetExitCodeProcess(pi.hProcess, &exitCode);

  // --- release handles
  CloseHandle(pi.hProcess);
  CloseHandle(pi.hThread);
  return exitCode;
}

*/
//-----------------------------------------------------------------------------
int RunSwmmDll(char* inpFile, char* rptFile, char* outFile)
//-----------------------------------------------------------------------------
{
  int err;
  double elapsedTime;

  // --- open a SWMM project
  err = swmm_open(inpFile, rptFile, outFile);
  if (!err)
  {
    // --- initialize all processing systems
    err = swmm_start(1);
    if (err == 0)
    {
      // --- step through the simulation
      do
      {
        // --- allow Windows to process any pending events
        ProcessMessages();

        // --- extend the simulation by one routing time step
        err = swmm_step(&elapsedTime);

        /////////////////////////////////////////////
        // --- call progress reporting function here,
        //     using elapsedTime as an argument
        /////////////////////////////////////////////

      } while (elapsedTime > 0.0 && err == 0);

      // --- close all processing systems
      swmm_end();
    }
  }

  // --- close the project
  swmm_close();
  return err;
}


In addition to the above mentioned files, all the other required files have also been added to the project.

The problem is that all the time I try to build this project, it says undefined reference to 'RunSwmmDll(char*, char*, char*)'.
I frankly speaking can't figure out what the cause of this error is!!!!!
Any help is highly appreciated!!!!
Could you try copying temporarily the function and what it needs in the same file as the main(), in order to validate if it is a file inclusion/linking issue or something else ?

EDIT : Are you trying to build swmm5_iface.c in a second project built as a DLL? In that case, it's normal that the main EXE project that uses the DLL doesn't find symbols for the functions defined in the DLL. What IDE are you using?
Last edited on
Bartoli,

Yes I am trying to build swmm5_iface.c as a DLL. I am using CODEBLOCKS as the IDE.
Undefined reference indicates that the compiler knows the prototype, but the linker cannot find the object code containing the function i.e. the linker cannot find the library file containing the function.

Firstly, have you successfully, separately from everything else, built the swmm5_iface.c DLL? If so, somewhere in Code::Blocks there will be an option to specify library directories, and library files.

Note also that if you're compiling swmm5_iface.c as C code, but then trying to use it in a C++ program, you may have trouble unless you use the appropriate extern code (I must confess I'm not so sure on this, as I tend not to build C code for inclusion in C++ programmes very often). I suggest you make that easier and compile swmm5_iface.c as C++
Last edited on
Topic archived. No new replies allowed.