Convert app to c++
This commit is contained in:
parent
069f8c8465
commit
c35b33b613
8 changed files with 64 additions and 16 deletions
3
.vscode/launch.json
vendored
3
.vscode/launch.json
vendored
|
@ -26,7 +26,8 @@
|
||||||
"text": "-gdb-set disassembly-flavor intel",
|
"text": "-gdb-set disassembly-flavor intel",
|
||||||
"ignoreFailures": true
|
"ignoreFailures": true
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"preLaunchTask": "CMake: build"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
19
.vscode/tasks.json
vendored
Normal file
19
.vscode/tasks.json
vendored
Normal file
|
@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -1,8 +1,11 @@
|
||||||
# Specifies the minimum version of CMake required to configure the project.
|
# Specifies the minimum version of CMake required to configure the project.
|
||||||
cmake_minimum_required(VERSION 3.10)
|
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.
|
# 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.
|
# 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)
|
# 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)
|
add_subdirectory(libs/lib3)
|
||||||
|
|
||||||
# Defines an executable target named 'cmake_tutorialApp' from the source file 'src/app.c'.
|
# 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.
|
# Links the executable target 'cmake_tutorialApp' to the specified libraries.
|
||||||
# - PRIVATE: Indicates that 'cmake_tutorialApp' needs these libraries for its own compilation/linking,
|
# - PRIVATE: Indicates that 'cmake_tutorialApp' needs these libraries for its own compilation/linking,
|
||||||
|
|
|
@ -3,4 +3,12 @@
|
||||||
// are part of lib1.h's public interface. For simple calls in lib1.c,
|
// are part of lib1.h's public interface. For simple calls in lib1.c,
|
||||||
// including in lib1.c is sufficient.
|
// including in lib1.c is sufficient.
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
void lib1_function();
|
void lib1_function();
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -1,3 +1,11 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
void lib2_function(); // Function declaration for lib2
|
void lib2_function(); // Function declaration for lib2
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <stdio.h> // Standard I/O header is needed here because printf is used within this header-only function.
|
#include <stdio.h> // 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.
|
// Declared as static to prevent multiple definition errors.
|
||||||
// Since this is a header-only function, it will be included and compiled
|
// Since this is a header-only function, it will be included and compiled
|
||||||
// into every translation unit that includes lib3.h. 'static' limits its
|
// 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");
|
printf("This is a function from Header-Only Library 3.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
13
src/app.c
13
src/app.c
|
@ -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 <stdio.h> // 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;
|
|
||||||
}
|
|
14
src/app.cpp
Normal file
14
src/app.cpp
Normal file
|
@ -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 <iostream>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cout << "Hello from main application!" << std::endl;
|
||||||
|
// Call functions from the linked libraries
|
||||||
|
lib1_function();
|
||||||
|
lib2_function();
|
||||||
|
lib3_function();
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue