initial commit - linking static lib to executable

This commit is contained in:
dl92
2026-01-11 23:53:13 +00:00
parent a9d1275ad2
commit f8d7fdda5d
10 changed files with 74 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
add_subdirectory(TestA)
add_subdirectory(LibA)
target_link_libraries(TestA
PRIVATE
LibA
)

View File

@@ -0,0 +1,15 @@
add_library(LibA)
target_sources(LibA
PRIVATE
func1.cxx
PUBLIC
FILE_SET HEADERS
FILES
func1.h
)

View File

@@ -0,0 +1,6 @@
namespace LibA {
double sqrt(double x)
{
return -42;
}
}

View File

@@ -0,0 +1,3 @@
namespace LibA {
double sqrt(double x);
}

View File

@@ -0,0 +1,13 @@
add_executable(TestA)
target_sources(TestA
PRIVATE
testA.cxx
)
target_link_libraries(TestA
PRIVATE
LibA
)

View File

@@ -0,0 +1,9 @@
#include "iostream"
#include "func1.h"
int main()
{
std::cout<<"hello world"<<std::endl<<LibA::sqrt(5);
}

View File

@@ -0,0 +1,2 @@
add_subdirectory(TestB)

View File

@@ -0,0 +1,6 @@
add_executable(TestB)
target_sources(TestB
PRIVATE
testB.cxx
)

View File

@@ -0,0 +1,8 @@
#include "iostream"
int main()
{
std::cout<<"hello world"<<std::endl;
}

View File

@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.23)
project(learning2)
add_subdirectory(A)
add_subdirectory(B)