diff --git a/.vscode/launch.json b/.vscode/launch.json index fd04cfa..60f9d06 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -26,7 +26,8 @@ "text": "-gdb-set disassembly-flavor intel", "ignoreFailures": true } - ] + ], + "preLaunchTask": "CMake: build" } diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..5fb03c0 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,19 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "cmake", + "label": "CMake: build", + "command": "build", + "targets": [ + "all" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [], + "detail": "CMake template build task" + } + ] +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fbb035..fe26c61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,11 @@ # Specifies the minimum version of CMake required to configure the project. cmake_minimum_required(VERSION 3.10) +set(SMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + # Defines the name of the project. This name is used for various CMake targets and variables. -project(cmake_tutorial C) +project(cmake_tutorial C CXX) # Configures CMake to generate a 'compile_commands.json' file in the build directory. # This file is used by many IDEs and language servers (e.g., VS Code, CLion) @@ -17,7 +20,7 @@ add_subdirectory(libs/lib2) add_subdirectory(libs/lib3) # Defines an executable target named 'cmake_tutorialApp' from the source file 'src/app.c'. -add_executable(cmake_tutorial src/app.c) +add_executable(cmake_tutorial src/app.cpp) # Links the executable target 'cmake_tutorialApp' to the specified libraries. # - PRIVATE: Indicates that 'cmake_tutorialApp' needs these libraries for its own compilation/linking, diff --git a/libs/lib1/inc/lib1.h b/libs/lib1/inc/lib1.h index 5639815..fe90b0c 100644 --- a/libs/lib1/inc/lib1.h +++ b/libs/lib1/inc/lib1.h @@ -3,4 +3,12 @@ // are part of lib1.h's public interface. For simple calls in lib1.c, // including in lib1.c is sufficient. +#if defined(__cplusplus) +extern "C" { +#endif + void lib1_function(); + +#if defined(__cplusplus) +} +#endif \ No newline at end of file diff --git a/libs/lib2/inc/lib2.h b/libs/lib2/inc/lib2.h index e5b2c0f..4f0258f 100644 --- a/libs/lib2/inc/lib2.h +++ b/libs/lib2/inc/lib2.h @@ -1,3 +1,11 @@ #pragma once +#if defined(__cplusplus) +extern "C" { +#endif + void lib2_function(); // Function declaration for lib2 + +#if defined(__cplusplus) +} +#endif diff --git a/libs/lib3/inc/lib3.h b/libs/lib3/inc/lib3.h index 8065939..26c94b1 100644 --- a/libs/lib3/inc/lib3.h +++ b/libs/lib3/inc/lib3.h @@ -1,6 +1,10 @@ #pragma once #include // Standard I/O header is needed here because printf is used within this header-only function. +#if defined(__cplusplus) +extern "C" { +#endif + // Declared as static to prevent multiple definition errors. // Since this is a header-only function, it will be included and compiled // into every translation unit that includes lib3.h. 'static' limits its @@ -9,3 +13,7 @@ static void lib3_function() { printf("This is a function from Header-Only Library 3.\n"); } + +#if defined(__cplusplus) +} +#endif diff --git a/src/app.c b/src/app.c deleted file mode 100644 index cf11f94..0000000 --- a/src/app.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "lib1.h" // Header for Library 1 (static library) -#include "lib2.h" // Header for Library 2 (static library) -#include "lib3.h" // Header for Library 3 (header-only library) -#include // Standard I/O functions like printf - -int main() { - printf("Hello from main application!\n"); - // Call functions from the linked libraries - lib1_function(); - lib2_function(); - lib3_function(); - return 0; -} diff --git a/src/app.cpp b/src/app.cpp new file mode 100644 index 0000000..b6404ab --- /dev/null +++ b/src/app.cpp @@ -0,0 +1,14 @@ +#include "lib1.h" // Header for Library 1 (static library) +#include "lib2.h" // Header for Library 2 (static library) +#include "lib3.h" // Header for Library 3 (header-only library) +#include + +int main() +{ + std::cout << "Hello from main application!" << std::endl; + // Call functions from the linked libraries + lib1_function(); + lib2_function(); + lib3_function(); + return 0; +}