diff --git a/c/README.md b/c/README.md index 0c3b361..44944ff 100644 --- a/c/README.md +++ b/c/README.md @@ -119,5 +119,5 @@ 1. [C++ templates](template_cpp.c) 1. [String to int](string_to_int.c) 1. [User input](interactive/user_input.c.off) - 1. [Virtual memory](virtual_memory.c) + 1. [Memory layout](memory_layout.c) 1. [Profiling](interactive/profiling.c) diff --git a/c/virtual_memory.c b/c/memory_layout.c similarity index 95% rename from c/virtual_memory.c rename to c/memory_layout.c index 7982b94..1f5905d 100644 --- a/c/virtual_memory.c +++ b/c/memory_layout.c @@ -30,7 +30,7 @@ int main(int argc, char **argv) { printf(" &heap = %0*" PRIxPTR "\n", PRIxPTR_WIDTH, (uintptr_t)heap); printf(" &bss = %0*" PRIxPTR "\n", PRIxPTR_WIDTH, (uintptr_t)&bss); printf(" &data = %0*" PRIxPTR "\n", PRIxPTR_WIDTH, (uintptr_t)&data); - printf(" &str main = %0*" PRIxPTR "\n", PRIxPTR_WIDTH, (uintptr_t)&main); + printf(" &main = %0*" PRIxPTR "\n", PRIxPTR_WIDTH, (uintptr_t)&main); printf(" &str char* = %0*" PRIxPTR "\n", PRIxPTR_WIDTH, (uintptr_t)&str); free(heap); diff --git a/cmake/README.md b/cmake/README.md index 6afe9a9..fd5fa09 100644 --- a/cmake/README.md +++ b/cmake/README.md @@ -1,5 +1,8 @@ # CMake +Good examples: + +1. [multi_executable](multi_executable/) 1. [shared_lib_external](shared_lib_external/) Make alternative that aims to be portable. diff --git a/cmake/multi_executable/CMakeLists.txt b/cmake/multi_executable/CMakeLists.txt new file mode 100644 index 0000000..b35795e --- /dev/null +++ b/cmake/multi_executable/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.0) +file(GLOB APP_SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "*.c") +message("${APP_SOURCES}") +foreach(testsourcefile ${APP_SOURCES}) + string(REPLACE ".c" "" testname ${testsourcefile}) + add_executable(${testname} ${testsourcefile}) +endforeach(testsourcefile ${APP_SOURCES}) diff --git a/cmake/multi_executable/a.c b/cmake/multi_executable/a.c new file mode 100644 index 0000000..113b2ea --- /dev/null +++ b/cmake/multi_executable/a.c @@ -0,0 +1,7 @@ +#include +#include + +int main(void) { + puts(__FILE__); + return EXIT_SUCCESS; +} diff --git a/cmake/multi_executable/b.c b/cmake/multi_executable/b.c new file mode 100644 index 0000000..113b2ea --- /dev/null +++ b/cmake/multi_executable/b.c @@ -0,0 +1,7 @@ +#include +#include + +int main(void) { + puts(__FILE__); + return EXIT_SUCCESS; +} diff --git a/cmake/shared_lib_external/CMakeLists.txt b/cmake/shared_lib_external/CMakeLists.txt index 3edd1b6..72dcef3 100644 --- a/cmake/shared_lib_external/CMakeLists.txt +++ b/cmake/shared_lib_external/CMakeLists.txt @@ -1,3 +1,4 @@ +# sudo apt-get install libgsl-dev cmake_minimum_required(VERSION 2.8) add_executable(main main.c) target_link_libraries(main gsl gslcblas)