Use of Epanet toolkit with Code Blocks (C language)

Hello all. I am new to this community and also to C programming. I am learning with the EPANET toolkit (EPANET 2_2.h) and I am using the IDE Codeblocks so I ask kindly you to bear with me if my question if too basic

I have a general problem with all the functions that I call on my script from the header Epanet2_2.h.

For example: as simple as a function to open the Epanet inp File.

This function is listed in the Epanet2_2.h header as:
int DLLEXPORT EN_open(EN_Project ph, const char inpFile, const char rptFile, const char outFile);

When I try to use this function in my script, I write it as:

int EN_open(EN_Project ph, “Filename.inp”, “”, “”); (no rpt files required in this case)

However, codeblocks returns the following error:

error: expected declaration specifiers or ‘…’ before string constant.

I am somehow using the function wrong but I have no idea why.

I did try to predefine the file name as a random variable as:

const char A = “Filename.inp”;

and then rewriting the function as:
int EN_open(EN_Project ph, A, “”, “”);

but that also get a similar error:
error: expected declaration specifiers or ‘…’ before A.

Can someone shed some light on this?

Thank you very much in advance.

I would suggest you to use visual studio instead of code blocks. Its easy to link epanet and visual studio.

Hola Carlos
Puedes dar un vistazo a los libros de iniciación a la programación con la toolkit de epanet en varios lenguajes por si te es de ayuda.
Versión español, aquí
Versión inglés, aquí

Un saludo

1 Like

Hi Carlos, there are some details in the code that you must correct.
When you are going to call the EN_open function, you should not indicate the data types:

int EN_open(EN_Project ph, “Filename.inp”, “”, “”);

Also, to create a project you can do the following:

EN_Project ph;
EN_createproject(&ph);
EN_open(ph, “Filename.inp”, “”, “”);

You can see some examples in the following link http://wateranalytics.org/EPANET/toolkit-usage.html.

Try those changes and tell me if it works.
Greetings
Sergio

1 Like

Hola Oscar! Muchísimas gracias por este material. Le estaré dando un vistazo.

Saludos,

Hi Sergio, thanks for the comments.
I had already tried that alternative. I keep getting an error from codeblocks. "undefined reference to __imp_EN_createproject and same to EN_open… it looks as though codeblock does not recognize the funcion even though the library has been brought in with #include “epanet2_2.h”
only by calling the data type (int) is how codeblock does not return an error.

And yes, I had read all the info you sent me on the link. It was very useful and it’s actually what I’m using as a base code to perform hydraulic simulations and retrieve results. It seems to me at this point that it’s an issue with Codeblocks, I might need to try with another IDE.

Thanks again,

Hola de nuevo, Oscar. Estupendo tu aporte. Decidi usar DEV y practicar con los ejemplos que aparecen en el libro de iniciacion. Tengo dos preguntas: En ejemplo que aparece alli con DEV C++ (pagina 90) me aparece un error al compilar y crear el archivo Makefile.
El error dice: recipe for target "ConnectAPIEpanet.exe failed Sabras decirme a que se debe ese error?

Tambien queria saber sobre el archivo de extension “.o”, pues tambien tengo el siguente error:
C:\Users\Medion\OneDrive\Desktop\API.Epanet.Verbindung\Proyecto 1\g++.exe [Error] …/Proyecto\ 1/ConnectAPIEpanet.o: No such file or directory
Esto a pesar de que el archivo de extension .o si esta en el directorio.

Muchisimas gracias de nuevo.
Carlos

Hola Carlos

He descargado el código, a través del enlace de la página 89, y solo he modificado la ruta del fichero Epanet (Net3) para que el resultado se muestre en la consola (Figura de abajo). Intenta realizar esos cambios y me cuentas si ha funcionado. El error que me describes, a mí no me aparece. Si estás desarrollando código desde cero, probablemente sea un error de configuración previa.
En caso de que el error persista, sube el código y lo revisamos.

Un saludo.