Skip to content

Commit 4f63bb1

Browse files
authored
Merge pull request #715 from OpenSimulationInterface/592-problems-with-dynamic-linking
Clean README and enhanced install instructions for protobuf in Docu
2 parents 7699763 + fefe981 commit 4f63bb1

11 files changed

+113
-68
lines changed

README.md

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,47 +20,11 @@ For usage examples, please refer to the official documentation:
2020
- [OSMPCNetworkProxy](https://github.com/OpenSimulationInterface/osi-sensor-model-packaging/tree/master/examples/OSMPCNetworkProxy)
2121

2222
## Installation
23-
##### Dependencies
24-
Install `cmake` 3.10.2:
25-
```bash
26-
$ sudo apt-get install cmake
27-
```
28-
Install `pip3` and missing python packages:
29-
```bash
30-
$ sudo apt-get install python3-pip python3-setuptools
31-
```
32-
Install `protobuf`:
33-
```bash
34-
$ sudo apt-get install libprotobuf-dev protobuf-compiler
35-
```
3623

37-
38-
##### Build and install for `C++` usage:
39-
```bash
40-
$ git clone https://github.com/OpenSimulationInterface/open-simulation-interface.git
41-
$ cd open-simulation-interface
42-
$ mkdir build
43-
$ cd build
44-
$ cmake ..
45-
$ make
46-
$ sudo make install
47-
```
48-
49-
##### Install for `Python` usage:
50-
Local:
51-
```bash
52-
$ git clone https://github.com/OpenSimulationInterface/open-simulation-interface.git
53-
$ cd open-simulation-interface
54-
$ sudo pip3 install virtualenv
55-
$ virtualenv -p python3 venv
56-
$ source venv/bin/activate
57-
$ python3 -m pip install .
58-
```
59-
60-
Global:
61-
```bash
62-
$ git clone https://github.com/OpenSimulationInterface/open-simulation-interface.git
63-
$ cd open-simulation-interface
64-
$ sudo pip3 install .
65-
```
66-
For Windows installation see [here](https://opensimulationinterface.github.io/osi-documentation/open-simulation-interface/doc/windows.html) for more information.
24+
For detailed installation instructions, please refer to the official documentation:
25+
- [Setting up OSI](https://opensimulationinterface.github.io/osi-antora-generator/asamosi/latest/interface/setup/setting_up_osi.html)
26+
- [Installing _protobuf_ for static / dynamic linking](https://opensimulationinterface.github.io/osi-antora-generator/asamosi/latest/interface/setup/installing_prerequisites.html)
27+
- [Installing OSI for C++ on Linux](https://opensimulationinterface.github.io/osi-antora-generator/asamosi/latest/interface/setup/installing_linux_cpp.html)
28+
- [Installing OSI for Python on Linux](https://opensimulationinterface.github.io/osi-antora-generator/asamosi/latest/interface/setup/installing_linux_python.html)
29+
- [Installing OSI for C++ on Windows](https://opensimulationinterface.github.io/osi-antora-generator/asamosi/latest/interface/setup/installing_windows_cpp.html)
30+
- [Installing OSI for Python on Windows](https://opensimulationinterface.github.io/osi-antora-generator/asamosi/latest/interface/setup/installing_windows_python.html)

doc/open-simulation-interface_user_guide.adoc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ include::./architecture/trace_file_example.adoc[leveloffset=+3]
7171

7272
include::./architecture/formatting_scripts.adoc[leveloffset=+3]
7373

74-
== Setting up OSI
74+
75+
// Setting up OSI
76+
include::./setup/setting_up_osi.adoc[leveloffset=+1]
77+
78+
include::./setup/installing_prerequisites.adoc[leveloffset=+2]
7579

7680
include::./setup/installing_linux_cpp.adoc[leveloffset=+2]
7781

doc/setup/including_osi_dev_projects.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ TODO: Content to be added in future release.
88

99
// TODO: Add description of this task.
1010

11-
**Prerequisites**
11+
Prerequisites::
1212

1313
//TODO: Add prerequisites.
1414

15-
**Steps**
15+
Steps::
1616

1717
// TODO: Add steps.
1818

19-
**Result**
19+
Result::
2020

2121
// TODO: Add result.

doc/setup/installing_linux_cpp.adoc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ include::{root-path}_config.adoc[]
44
endif::[]
55
= Installing OSI for C++ on Linux
66

7-
**Prerequisites**
7+
Prerequisites::
88

9-
* You have installed _cmake_.
10-
* You have installed _protobuf_.
11-
* You must have super user privileges.
9+
* You have installed everything described in <<top-installing-osi-prerequisits>>.
1210
13-
**Steps**
11+
Steps::
1412

1513
. Open a terminal.
1614
. Clone the Open Simulation repository.

doc/setup/installing_linux_python.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ include::{root-path}_config.adoc[]
44
endif::[]
55
= Installing OSI for Python on Linux
66

7-
**Prerequisites**
7+
*Prerequisites::
88
9+
* You have installed everything described in <<top-installing-osi-prerequisits>>.
910
* You have installed _pip3_.
1011
* You have installed _python-setuptools_.
11-
* You have installed _protobuf_.
1212
* For a local installation, you have installed _virtualenv_.
1313
14-
**Steps**
14+
Steps::
1515
1616
. Open a terminal.
1717
. Clone the Open Simulation repository.
@@ -42,7 +42,7 @@ source venv/bin/activate
4242
.. Local installation
4343
+
4444
----
45-
pip3 install .
45+
python3 -m pip install .
4646
----
4747
+
4848
.. Global installation

doc/setup/installing_macos.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ TODO: Content to be added in future release.
88

99
// TODO: Add description of this task.
1010

11-
**Prerequisites**
11+
Prerequisites::
1212

1313
//TODO: Add prerequisites.
1414

15-
**Steps**
15+
Steps::
1616

1717
// TODO: Add steps.
1818

19-
**Result**
19+
Result::
2020

2121
// TODO: Add result.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
ifndef::include-only-once[]
2+
:root-path: ../
3+
include::{root-path}_config.adoc[]
4+
endif::[]
5+
[#top-installing-osi-prerequisits]
6+
= Installing protobuf for static / dynamic linking
7+
8+
== Prerequisites
9+
10+
* You have installed _cmake_ (version 3.10.2 or higher)
11+
* You must have superuser privileges
12+
13+
Static linking is the recommended way to package OSI FMUs for sharing with others to be integrated in a co-simulation: They should have minimal external dependencies in order to ensure maximum portability.
14+
For other use cases like first trials to get started with OSI, dynamic linking could be an option as well.
15+
16+
== Windows
17+
18+
Dynamic Linking (NOT RECOMMENDED)::
19+
20+
Since on Windows symbols are not exported per default, it can be kind of annoying to deal with this during _protobuf_ header generation (see for example https://groups.google.com/g/protobuf/c/PDR1bqRazts).
21+
That is an important reason to use static linking.
22+
23+
Static Linking::
24+
25+
Static linking might require to manually build _protobuf_.
26+
It is important to notice that on Windows you can also specify how to link against the C runtime.
27+
Basically, this can be set in CMake, e.g. https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html
28+
29+
Therefore, it could make sense to still dynamically link against the C Runtime when statically linking _protobuf_ / OSI.
30+
(This is important e.g. when building shared libraries, since a static C runtime will create an isolated heap for your dll, which can lead to segfaults depending on what you expose on your public interfaces.)
31+
32+
The easiest way to achieve static linking on Windows without setting all the stuff manually in Cmake and building _protobuf_ is to actually **install static _protobuf_ with dynamic c-runtime with vcpkg**:
33+
34+
----
35+
vcpkg install --triplet=x64-windows-static-md protobuf
36+
----
37+
38+
Build::
39+
40+
For the cmake configuration, we can directly specify our vcpkg installation:
41+
----
42+
cmake .. -DVCPKG_TARGET_TRIPLET=x64-windows-static-md -DCMAKE_TOOLCHAIN_FILE=C:/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake -A x64
43+
cmake --build . --config Release
44+
----
45+
46+
== Linux
47+
48+
Dynamic linking (NOT RECOMMENDED)::
49+
50+
As already mentioned, shared linking is possible on Linux, but NOT RECOMMENDED.
51+
However, for dynamic linking install _protobuf_ (version 3.0.0 or higher) with apt:
52+
----
53+
sudo apt-get install libprotobuf-dev protobuf-compiler
54+
----
55+
In the CMakeLists of the OSI project, `LINK_WITH_SHARED_OSI` has to be enabled.
56+
57+
Static linking::
58+
59+
A common error here is to just install _protobuf_ with apt and link against it.
60+
This means that your OSI is build statically but still linking dynamically against _protobuf_.
61+
Here, again either _protobuf_ has to build statically from source or some solution e.g. vcpkg needs to be utilized.
62+
We recommend the following (as in the README of the OSI project):
63+
64+
Install _protobuf_ (version 3.0.0 or higher) from source with `CXXFLAGS="-fPIC"` to allow static linking of your OSI FMUs (replace <version> with preferred release):
65+
----
66+
wget https://github.com/protocolbuffers/protobuf/releases/download/<version>/protobuf-all-<version>.tar.gz
67+
tar -xzf protobuf-all-<version>.tar.gz
68+
cd protobuf-<version>/
69+
./configure --disable-shared CXXFLAGS="-fPIC"
70+
make
71+
sudo make install
72+
sudo ldconfig
73+
----

doc/setup/installing_windows_cpp.adoc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ include::{root-path}_config.adoc[]
44
endif::[]
55
= Installing OSI for C++ on Windows
66

7-
**Prerequisites**
7+
Prerequisites::
88

9-
* You have installed _cmake_ as an administrator.
10-
* You have installed _protobuf_ as an administrator.
9+
* You have installed everything described in <<top-installing-osi-prerequisits>>.
1110
12-
**Steps**
11+
Steps::
1312

1413
. Open a terminal as administrator.
1514
. Clone the Open Simulation repository.

doc/setup/installing_windows_python.adoc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ include::{root-path}_config.adoc[]
44
endif::[]
55
= Installing OSI for Python on Windows
66

7-
**Prerequisites**
7+
Prerequisites::
88

9+
* You have installed everything described in <<top-installing-osi-prerequisits>>.
910
* You have installed _Python_ with administrator rights.
1011
* Make sure _Python_ is added to `PATH`.
1112
12-
**Steps**
13+
Steps::
1314

1415
. Open a terminal.
1516
. Clone the Open Simulation repository.

doc/setup/setting_up_osi.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ifndef::include-only-once[]
2+
:root-path: ../
3+
include::{root-path}_config.adoc[]
4+
endif::[]
5+
[#top-setting-up-osi]
6+
= Setting up OSI

0 commit comments

Comments
 (0)