From e26d76a581e6eda4866b8dab5e51a26250bdf2fb Mon Sep 17 00:00:00 2001 From: Philipp Rosenberger Date: Thu, 16 Feb 2023 18:51:17 +0100 Subject: [PATCH 1/4] Enhancement of documentation for better explaining static/dynamic linking Signed-off-by: Philipp Rosenberger --- doc/setup/build_install_example.adoc | 57 +++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/doc/setup/build_install_example.adoc b/doc/setup/build_install_example.adoc index a5c3d83..275a48a 100644 --- a/doc/setup/build_install_example.adoc +++ b/doc/setup/build_install_example.adoc @@ -2,6 +2,61 @@ ifndef::include-only-once[] :root-path: ../ include::{root-path}_config.adoc[] endif::[] + += Static / dynamic linking for co-simulation + +== Windows + +**Dynamic Linking** + +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). +So basically thats one reason to use static linking. + +**Static Linking** + +Static linking might require to manually build protobuf. +Its important to notice that on windows you can also specify how to link against the C runtime (not sure how this works on linux). +Basically this can be set in CMake e.g. https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html + +So when statically linking it makes sense to still dynamically link against the C Runtime. +(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) + +The easiest way to achieve this on Windows without setting all the stuff manually in Cmake and building protobuf +is to actually use vcpkg: + +**Install static protobuf:** + +---- +vcpkg install --triplet=x64-windows-static-md protobuf +---- + +This vcpkg triplet enables static linking with dynamic c-runtime. + +**Build:** + +For cmake configuration we can directly specify our vcpkg installation: +---- +cmake .. -DVCPKG_TARGET_TRIPLET=x64-windows-static-md -DCMAKE_TOOLCHAIN_FILE=C:/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake -A x64 +cmake --build . --config Release +---- + +== Linux + +There is already a good answer from pmai so here some additional points to this. + +**Dynamic linking** + +As already mentioned by pmai shared linking is an option on linux. +`LINK_WITH_SHARED_OSI` has to be enabled. + +**Static linking** + +A common error here is to just install protobuf with apt and link against it. +This means that your OSI is build statically but still linking dynamically against protobuf. +Here, again either protobuf has to build statically from source or some solution e.g. vcpkg needs to be utilized. + = Building and installing examples OSMP includes three examples located in `_osmp_/examples`: @@ -19,7 +74,7 @@ Demonstrates a simple C network proxy that can send and receive OSI data via TCP **Prerequisites** * You have installed _cmake_ version 3.10.2 or higher. -* You have installed _protobuf_ version 3.0.0 or higher. +* You have installed _protobuf_ version 3.0.0 or higher according to the way of linking of your choice, as described above. **Steps** From 6df9126f9884e2f091a91d58b04792f2af339d3f Mon Sep 17 00:00:00 2001 From: Philipp Rosenberger Date: Thu, 16 Feb 2023 20:44:10 +0100 Subject: [PATCH 2/4] Added link to detailed install instructions Signed-off-by: Philipp Rosenberger --- doc/setup/build_install_example.adoc | 57 +--------------------------- 1 file changed, 1 insertion(+), 56 deletions(-) diff --git a/doc/setup/build_install_example.adoc b/doc/setup/build_install_example.adoc index 275a48a..004f9e8 100644 --- a/doc/setup/build_install_example.adoc +++ b/doc/setup/build_install_example.adoc @@ -3,60 +3,6 @@ ifndef::include-only-once[] include::{root-path}_config.adoc[] endif::[] -= Static / dynamic linking for co-simulation - -== Windows - -**Dynamic Linking** - -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). -So basically thats one reason to use static linking. - -**Static Linking** - -Static linking might require to manually build protobuf. -Its important to notice that on windows you can also specify how to link against the C runtime (not sure how this works on linux). -Basically this can be set in CMake e.g. https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html - -So when statically linking it makes sense to still dynamically link against the C Runtime. -(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) - -The easiest way to achieve this on Windows without setting all the stuff manually in Cmake and building protobuf -is to actually use vcpkg: - -**Install static protobuf:** - ----- -vcpkg install --triplet=x64-windows-static-md protobuf ----- - -This vcpkg triplet enables static linking with dynamic c-runtime. - -**Build:** - -For cmake configuration we can directly specify our vcpkg installation: ----- -cmake .. -DVCPKG_TARGET_TRIPLET=x64-windows-static-md -DCMAKE_TOOLCHAIN_FILE=C:/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake -A x64 -cmake --build . --config Release ----- - -== Linux - -There is already a good answer from pmai so here some additional points to this. - -**Dynamic linking** - -As already mentioned by pmai shared linking is an option on linux. -`LINK_WITH_SHARED_OSI` has to be enabled. - -**Static linking** - -A common error here is to just install protobuf with apt and link against it. -This means that your OSI is build statically but still linking dynamically against protobuf. -Here, again either protobuf has to build statically from source or some solution e.g. vcpkg needs to be utilized. - = Building and installing examples OSMP includes three examples located in `_osmp_/examples`: @@ -73,8 +19,7 @@ Demonstrates a simple C network proxy that can send and receive OSI data via TCP **Prerequisites** -* You have installed _cmake_ version 3.10.2 or higher. -* You have installed _protobuf_ version 3.0.0 or higher according to the way of linking of your choice, as described above. +* You have installed all prerequisites according to the way of linking of your choice, as described in <>. **Steps** From d2b2a9796d1f51f934aef7ff219114b22852afbc Mon Sep 17 00:00:00 2001 From: Philip Windecker Date: Mon, 13 Mar 2023 12:38:03 +0100 Subject: [PATCH 3/4] Removed empty line between include and page title (empty line before title can have technical implications) Signed-off-by: Philip Windecker --- doc/setup/build_install_example.adoc | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/setup/build_install_example.adoc b/doc/setup/build_install_example.adoc index 004f9e8..a252641 100644 --- a/doc/setup/build_install_example.adoc +++ b/doc/setup/build_install_example.adoc @@ -2,7 +2,6 @@ ifndef::include-only-once[] :root-path: ../ include::{root-path}_config.adoc[] endif::[] - = Building and installing examples OSMP includes three examples located in `_osmp_/examples`: From f33e35c10be1a033f333ffc65498bdd71be94a82 Mon Sep 17 00:00:00 2001 From: "Pierre R. Mai" Date: Mon, 27 Mar 2023 12:04:07 +0200 Subject: [PATCH 4/4] Adjust target anchor as per review Signed-off-by: Pierre R. Mai Co-authored-by: Philip Windecker <95633467+philipwindecker@users.noreply.github.com> --- doc/setup/build_install_example.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/setup/build_install_example.adoc b/doc/setup/build_install_example.adoc index a252641..840d97c 100644 --- a/doc/setup/build_install_example.adoc +++ b/doc/setup/build_install_example.adoc @@ -18,7 +18,7 @@ Demonstrates a simple C network proxy that can send and receive OSI data via TCP **Prerequisites** -* You have installed all prerequisites according to the way of linking of your choice, as described in <>. +* You have installed all prerequisites according to the way of linking of your choice, as described in <>. **Steps**