Skip to content

Commit 4bde4b0

Browse files
authored
different code
1 parent 7e008f3 commit 4bde4b0

4 files changed

Lines changed: 56 additions & 8 deletions

File tree

CMakeLists.txt

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
1-
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
2-
add_definitions(-std=c++11)
3-
set(CXX_FLAGS "-Wall")
4-
set(CMAKE_CXX_FLAGS, "${CXX_FLAGS}")
1+
cmake_minimum_required(VERSION 3.5)
52

6-
set(CMAKE_BUILD_TYPE Debug)
3+
project(hello_library)
74

8-
project(test)
5+
############################################################
6+
# Create a library
7+
############################################################
98

10-
add_subdirectory( "vendor/iptables-1.2.10" )
11-
add_subdirectory( "vendor/libtins" )
9+
#Generate the static library from the library sources
10+
add_library(hello_library STATIC
11+
src/Hello.cpp
12+
)
13+
14+
target_include_directories(hello_library
15+
PUBLIC
16+
${PROJECT_SOURCE_DIR}/include
17+
)
18+
19+
20+
############################################################
21+
# Create an executable
22+
############################################################
23+
24+
# Add an executable with the above sources
25+
add_executable(hello_binary
26+
src/main.cpp
27+
)
28+
29+
# link the new hello_library target with the hello_binary target
30+
target_link_libraries( hello_binary
31+
PRIVATE
32+
hello_library
33+
)

include/static/Hello.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef __HELLO_H__
2+
#define __HELLO_H__
3+
4+
class Hello
5+
{
6+
public:
7+
void print();
8+
};
9+
10+
#endif

src/Hello.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <iostream>
2+
3+
#include "static/Hello.h"
4+
5+
void Hello::print()
6+
{
7+
std::cout << "Hello Static Library!" << std::endl;
8+
}

src/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "static/Hello.h"
2+
3+
int main(int argc, char *argv[])
4+
{
5+
Hello hi;
6+
hi.print();
7+
return 0;
8+
}

0 commit comments

Comments
 (0)