Compiling C++ programs using the copasi library

54 views
Skip to first unread message

Marc Lefranc

unread,
Dec 7, 2016, 6:39:47 AM12/7/16
to copasi-u...@googlegroups.com
Dear all,

we are trying to learn how to use the copasi C++ methods in a C++
program, as in the examples given in the copasi/bindings/cpp_examples
directory of the source tree.

I was wondering if there was a way to install the include files and some
kind of library inside, say, /usr/local, and then use these files
afterwards when compiling our own programs, or is pointing to the files
inside the source directory the only way to go?

It could be nice to include the include and library files with the
executable package, or to have a separate development package.

Best,
Marc

--
Laboratoire de Physique des Lasers, Atomes, Molécules
Bat P5, UFR de Physique
Université Lille 1 Sciences et Technologies
F-59655 Villeneuve d'Ascq CEDEX (FRANCE)
Tel : +33 (0)3 20 33 64 50 ; FAX : +33 (0)3 20 33 70 20
http://www.phlam.univ-lille1.fr/spip.php?article565&lang=en
Site SCIENCE NON LINEAIRE : http://nonlineaire.univ-lille1.fr/SNL/
Experimental Chaos and Complexity Conference:
http://experimentalchaosconference.org/

Frank Bergmann

unread,
Dec 7, 2016, 8:00:30 AM12/7/16
to COPASI User Forum
Hello Marc, 

I'm afraid we don't yet have an install target for the COPASI C++ API. But i can make that easier for the next version. By end of next week i should have something in the repository. 

For now: 

- yes you do need to point to the copasi source directory (the one containing the 'copasi' folder), so that all header files from there can be reached
- after a cmake build you will find in the build directory/copasi a static library file COPASISE against which (and all its dependencies) you would have to link
- you would also need to recall the compile definitions (CXXFLAGS) that you chose for your configuration

best
Frank

Marc Lefranc

unread,
Dec 7, 2016, 8:59:43 AM12/7/16
to copasi-u...@googlegroups.com
Hi Frank,

thank you for clarifying this. I have another related question. I have 25 years of experience with compiling large source packages (linux kernel, Emacs, gcc, etc.), using configure, Makefiles, etc. but I am very unfamiliar with cmake and I had difficulties locating precise instructions for building COPASI.

I understand that one creates a build_copasi directory where the build process will take place and that one configures the build using cmake-gui DIR. In the example, the actual command is cmake-gui ../COPASI. It is not clear to me what is the directory argument in this example. A generic name for the COPASI source directory?

Sorry if this is a dumb question.

Best,
Marc
--
You received this message because you are subscribed to the Google Groups "COPASI User Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to copasi-user-fo...@googlegroups.com.
To post to this group, send email to copasi-u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/copasi-user-forum/2cd322bc-5de7-4e5b-8813-89af1d615e7d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Frank Bergmann

unread,
Dec 7, 2016, 9:52:52 AM12/7/16
to COPASI User Forum
Hello Marc, 

cmake makes it so much more easy for us to ensure that we can build on many different platforms. But you have a point that we can do a better point of documenting the build system. To make it easier to build COPASI we actually now bundle up the dependencies of COPASI in a separate repository where some time ago I also tried to add at least basic build instructions: 



To your question: cmake strongly encourages out of source builds so that it is easier to have several builds using different compile options. As such on creates the build directory, and once changed into it invokes cmake (or cmake-gui). By being invoked in the directory cmake then already knows by convention, that the current directory ought to be the build directory where it can place its files. It does however not know about where the sources are located, that is the first argument (or the first agument that is not using any of the many switches that cmake knows about). In your case ../COPASI. If you were to check out the COPASI git repository on another location on your hardrive you would replace ../COPASI by that location. 

I hope that makes it clear, 
best
Frank


  

Marc Lefranc

unread,
Dec 7, 2016, 11:04:18 AM12/7/16
to copasi-u...@googlegroups.com
Hi Franck,

thank you so much, that was very helpful. I got the development version and the official versions to build.

Best,
Marc
--
You received this message because you are subscribed to the Google Groups "COPASI User Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to copasi-user-fo...@googlegroups.com.
To post to this group, send email to copasi-u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Stefan Hoops

unread,
Dec 7, 2016, 7:10:37 PM12/7/16
to copasi-u...@googlegroups.com
Hello Marc,

You can move all header files which are beneath the copasi directory
and its subdirectories into any location you like, e.g.,
into /usr/local/include as well as the libraries /usr/local/lib. I
actually have script which will do that for you:

https://github.com/NIMML/ENISI-Dependencies/blob/master/project_copasi-install.sh

Enjoy!
Stefan
> > <mailto:copasi-user-fo...@googlegroups.com>.
> > To post to this group, send email to
> > copasi-u...@googlegroups.com
> > <mailto:copasi-u...@googlegroups.com>.
> > <https://groups.google.com/d/msgid/copasi-user-forum/58346f3f-cf4f-49f9-b11f-fa63d96f2f22%40googlegroups.com?utm_medium=email&utm_source=footer>.

Marc Lefranc

unread,
Dec 8, 2016, 4:54:14 AM12/8/16
to copasi-u...@googlegroups.com
Hi Stefan,

jusst perfect. Thank you so much.

Best,
Marc

Frank Bergmann

unread,
Dec 8, 2016, 8:30:24 AM12/8/16
to COPASI User Forum

Hello Marc, 

I've pushed some changes into the develop branch of COPASI. That will make it easier to compile & link against COPASISE when using cmake. I've added some basic documentation here: 


But the idea is to additionally define an additional flag for cmake (COPASI_INSTALL_C_API=ON) that will cause the headers and libraries to be installed upon make install. Since we also include the cmake configuration to be installed into lib/cmake, it can be readily imported without the need to specify exactly against which library COPASI was linked against. 

A full cmakefile to link against COPASI can be found here: 


best
Frank


Marc Lefranc

unread,
Dec 9, 2016, 9:05:20 AM12/9/16
to copasi-u...@googlegroups.com
Hello Frank,

thank you very much, this is very helpful.

Best,
Marc

--
You received this message because you are subscribed to the Google Groups "COPASI User Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to copasi-user-fo...@googlegroups.com.
To post to this group, send email to copasi-u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/copasi-user-forum/02b0fed7-b585-4d7c-a97b-6ad44f521e4f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Stephan MG

unread,
Jul 7, 2025, 8:25:05 AMJul 7
to COPASI User Forum
Dear all,

i fail to link my program (after following the instructions above to) using the provided CMakeLists.txt.

My simple main.cpp is:
#include <copasi/core/CRootContainer.h>

int main(int argc, char** argv) {
   // Initialize COPASI root container
   CRootContainer::init(argc, argv, true);
   return 0;
}

The error I receive: 

[100%] Linking CXX executable example
/usr/bin/ld: /home/sgrein/copasi-install/lib/libCOPASISE.a(CRootContainer.cpp.o): in function `CRootContainer::init(int, char**, bool const&)':
CRootContainer.cpp:(.text+0x5bb): undefined reference to `pRootContainer'
/usr/bin/ld: CRootContainer.cpp:(.text+0x5e6): undefined reference to `pRootContainer'
/usr/bin/ld: CRootContainer.cpp:(.text+0x5f0): undefined reference to `pRootContainer'
/usr/bin/ld: CRootContainer.cpp:(.text+0x5ff): undefined reference to `pRootContainer'
/usr/bin/ld: /home/sgrein/copasi-install/lib/libCOPASISE.a(CRootContainer.cpp.o): in function `CRootContainer::destroy()':
CRootContainer.cpp:(.text+0x676): undefined reference to `pRootContainer'
/usr/bin/ld: /home/sgrein/copasi-install/lib/libCOPASISE.a(CRootContainer.cpp.o):CRootContainer.cpp:(.text+0x685): more undefined references to `pRootContainer' follow
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/example_copasi_program.dir/build.make:113: example] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/example_copasi_program.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

Any help would be appreciated.

Kind regards,
Stephan

Frank Bergmann

unread,
Jul 7, 2025, 8:27:21 AMJul 7
to COPASI User Forum
Hello Stephan, 

you are missing a define in your main program. Before including the root container, you need to define: 

```
#define COPASI_MAIN
#include <copasi/core/CRootContainer.h>
```

this is only needed in your main file. 

best
Frank

Stephan MG

unread,
Jul 8, 2025, 7:55:25 AMJul 8
to COPASI User Forum
Hi Frank,

thanks for the answer - meanwhile I had looked through the other examples, and could figure it out already.

Is this "magic" define somewhere documented (or are there others I should be aware of)? Thanks again!

Kind regards,
Stephan

Stephan MG

unread,
Jul 8, 2025, 7:55:30 AMJul 8
to COPASI User Forum
Also, in my libcopasise-static-config.cmake (after make install) - I find EXPAT::EXPAT in the INTERFACE_LINK_LIBRARIES.

But that didn't work for me - I added find_package(EXPAT REQUIRED) to my project's CMakeLists.txt - I use cmake 4.0.3.

Maybe you can clarify what I'm doing wrong, as I guess that addition to the CMakeLists.txt  shouldn't be required when using the libcopasise-static-config.cmake 
(I'm following this: https://copasi.org/static/API_Documentation/ and started with the CMakeLists.txt template gist there, also posted in this thread I think)

Kind regards,
Stephan

Frank Bergmann schrieb am Montag, 7. Juli 2025 um 14:27:21 UTC+2:

Frank Bergmann

unread,
Jul 8, 2025, 8:35:49 AMJul 8
to COPASI User Forum
Hello Stephan, 

thanks for pointing this out. That gist is indeed 9 years old and worked perfectly back then. Essentially what is needed is to add the files in the copasi/CMakeModules directory to the projects CMAKE_MODULE_PATH. That way it can find the dependencies. 

I'll update the documentation and perhaps create a template GitHub project for using the API. I won't get around to doing that today, but will follow up here, when it is done. 

best
Frank

Stephan MG

unread,
Jul 8, 2025, 8:49:57 AMJul 8
to COPASI User Forum
Hi Frank,

thanks again. I think this is the the cleanest approach.

No rush to create a template or update the documentation for me specifically, but the community will probably appreciate an updated description on how to compile and link COPASI C++ applications.

Kind regards,
Stephan
Reply all
Reply to author
Forward
0 new messages