From f8d7fdda5d274dbbec0b11122c76e772cd5a3957 Mon Sep 17 00:00:00 2001 From: dl92 Date: Sun, 11 Jan 2026 23:53:13 +0000 Subject: [PATCH] initial commit - linking static lib to executable --- .../executable_staticlib/A/CMakeLists.txt | 7 +++++++ .../executable_staticlib/A/LibA/CMakeLists.txt | 15 +++++++++++++++ .../executable_staticlib/A/LibA/func1.cxx | 6 ++++++ .../cmake_ys/executable_staticlib/A/LibA/func1.h | 3 +++ .../executable_staticlib/A/TestA/CMakeLists.txt | 13 +++++++++++++ .../executable_staticlib/A/TestA/testA.cxx | 9 +++++++++ .../executable_staticlib/B/CMakeLists.txt | 2 ++ .../executable_staticlib/B/TestB/CMakeLists.txt | 6 ++++++ .../executable_staticlib/B/TestB/testB.cxx | 8 ++++++++ .../cmake_ys/executable_staticlib/CMakeLists.txt | 5 +++++ 10 files changed, 74 insertions(+) create mode 100644 cplusplus/cmake_ys/executable_staticlib/A/CMakeLists.txt create mode 100644 cplusplus/cmake_ys/executable_staticlib/A/LibA/CMakeLists.txt create mode 100644 cplusplus/cmake_ys/executable_staticlib/A/LibA/func1.cxx create mode 100644 cplusplus/cmake_ys/executable_staticlib/A/LibA/func1.h create mode 100644 cplusplus/cmake_ys/executable_staticlib/A/TestA/CMakeLists.txt create mode 100644 cplusplus/cmake_ys/executable_staticlib/A/TestA/testA.cxx create mode 100644 cplusplus/cmake_ys/executable_staticlib/B/CMakeLists.txt create mode 100644 cplusplus/cmake_ys/executable_staticlib/B/TestB/CMakeLists.txt create mode 100644 cplusplus/cmake_ys/executable_staticlib/B/TestB/testB.cxx create mode 100644 cplusplus/cmake_ys/executable_staticlib/CMakeLists.txt diff --git a/cplusplus/cmake_ys/executable_staticlib/A/CMakeLists.txt b/cplusplus/cmake_ys/executable_staticlib/A/CMakeLists.txt new file mode 100644 index 0000000..6d04d26 --- /dev/null +++ b/cplusplus/cmake_ys/executable_staticlib/A/CMakeLists.txt @@ -0,0 +1,7 @@ +add_subdirectory(TestA) +add_subdirectory(LibA) + +target_link_libraries(TestA +PRIVATE + LibA +) \ No newline at end of file diff --git a/cplusplus/cmake_ys/executable_staticlib/A/LibA/CMakeLists.txt b/cplusplus/cmake_ys/executable_staticlib/A/LibA/CMakeLists.txt new file mode 100644 index 0000000..d0660bf --- /dev/null +++ b/cplusplus/cmake_ys/executable_staticlib/A/LibA/CMakeLists.txt @@ -0,0 +1,15 @@ + + +add_library(LibA) +target_sources(LibA + PRIVATE + func1.cxx + + PUBLIC + FILE_SET HEADERS + FILES + func1.h + + +) + diff --git a/cplusplus/cmake_ys/executable_staticlib/A/LibA/func1.cxx b/cplusplus/cmake_ys/executable_staticlib/A/LibA/func1.cxx new file mode 100644 index 0000000..6af7b9d --- /dev/null +++ b/cplusplus/cmake_ys/executable_staticlib/A/LibA/func1.cxx @@ -0,0 +1,6 @@ +namespace LibA { +double sqrt(double x) +{ + return -42; +} +} \ No newline at end of file diff --git a/cplusplus/cmake_ys/executable_staticlib/A/LibA/func1.h b/cplusplus/cmake_ys/executable_staticlib/A/LibA/func1.h new file mode 100644 index 0000000..bf00781 --- /dev/null +++ b/cplusplus/cmake_ys/executable_staticlib/A/LibA/func1.h @@ -0,0 +1,3 @@ +namespace LibA { +double sqrt(double x); +} diff --git a/cplusplus/cmake_ys/executable_staticlib/A/TestA/CMakeLists.txt b/cplusplus/cmake_ys/executable_staticlib/A/TestA/CMakeLists.txt new file mode 100644 index 0000000..f9a44ba --- /dev/null +++ b/cplusplus/cmake_ys/executable_staticlib/A/TestA/CMakeLists.txt @@ -0,0 +1,13 @@ + +add_executable(TestA) + +target_sources(TestA +PRIVATE +testA.cxx +) + +target_link_libraries(TestA +PRIVATE + LibA +) + diff --git a/cplusplus/cmake_ys/executable_staticlib/A/TestA/testA.cxx b/cplusplus/cmake_ys/executable_staticlib/A/TestA/testA.cxx new file mode 100644 index 0000000..269678d --- /dev/null +++ b/cplusplus/cmake_ys/executable_staticlib/A/TestA/testA.cxx @@ -0,0 +1,9 @@ +#include "iostream" +#include "func1.h" + +int main() +{ + + std::cout<<"hello world"<