File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ )
Original file line number Diff line number Diff line change 1+ #ifndef __HELLO_H__
2+ #define __HELLO_H__
3+
4+ class Hello
5+ {
6+ public:
7+ void print ();
8+ };
9+
10+ #endif
Original file line number Diff line number Diff line change 1+ #include < iostream>
2+
3+ #include " static/Hello.h"
4+
5+ void Hello::print ()
6+ {
7+ std::cout << " Hello Static Library!" << std::endl;
8+ }
Original file line number Diff line number Diff line change 1+ #include " static/Hello.h"
2+
3+ int main (int argc, char *argv[])
4+ {
5+ Hello hi;
6+ hi.print ();
7+ return 0 ;
8+ }
You can’t perform that action at this time.
0 commit comments