CMake project with subdirectories and static library

Boost, static, static link

I propose to write a small application that will have two subdirectories. One of which will compile the executable file, and the second will contain a statically linked library.

As a result, the project will look like this.

Project with static library

Root CMakeLists.txt

The main CMakeLists.txt will contain the connection of all subdirectories.

cmake_minimum_required (VERSION 3.8)

project (Example)

add_subdirectory (MyStaticLibrary)
add_subdirectory (ExampleStatic)

MyStaticLibrary

Next comes the static library, which will have a class that returns a Hello World message.

CMakeLists.txt

cmake_minimum_required (VERSION 3.8)

project(MyStaticLibrary)

set(SOURCE_FILES "MyStaticLibrary.cpp")
set(HEADER_FILES "MyStaticLibrary.h")

# We declare the project as a static library and add all the source code files to it.
add_library(MyStaticLibrary STATIC ${HEADER_FILES} ${SOURCE_FILES})

MyStaticLibrary.h

#pragma once

#include <string>

class MyStaticLibrary
{
public:
    static std::string getMyStaticMessage();
};

MyStaticLibrary.cpp

#include "MyStaticLibrary.h"

std::string MyStaticLibrary::getMyStaticMessage()
{
    return "Hello world from static library";
}

ExampleStatic

And this is a project for creating a binary and it contains the main.cpp file with the main function.

CMakeLists.txt

cmake_minimum_required (VERSION 3.8)

project(ExampleStatic)

set(SOURCE_FILES "main.cpp")

add_executable (ExampleStatic ${SOURCE_FILES})

# Connecting the library, specify where to get the header files
include_directories("../MyStaticLibrary")
# And also we specify dependence on static library
target_link_libraries(ExampleStatic MyStaticLibrary)

main.cpp

#include <iostream>

#include "MyStaticLibrary.h"

using namespace std; 

int main()
{
    cout << MyStaticLibrary::getMyStaticMessage() << endl;
    return 0;
}

Conclusion

As a conclusion, here is the result of the work of the program with this statically added library.

Example static project

We recommend hosting TIMEWEB
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.
Support the author Donate

Comments

Only authorized users can post comments.
Please, Log in or Sign up
Donate

Hello, Dear Users of EVILEG!!!

If the site helped you, then support the development of the site financially, please.

You can do it by following ways:

Thank you, Evgenii Legotckoi

a
Feb. 25, 2020, 4:40 a.m.
ayb

C++ - Test 005. Structures and Classes

  • Result:83points,
  • Rating points4
DZ
Feb. 24, 2020, 1:47 p.m.
Dmitrij Zlobin

C ++ - Test 004. Pointers, Arrays and Loops

  • Result:40points,
  • Rating points-8
p
Feb. 17, 2020, 1:41 p.m.
pstMem

C++ - Тест 003. Условия и циклы

  • Result:85points,
  • Rating points6
Last comments
Feb. 24, 2020, 2:54 a.m.
Evgenij Legotskoj

Добрый день. Там будет url, на который указывает ссылка тега a в пагинаторе, если правильно помню )) Написал этот код и забыл.
B
Feb. 23, 2020, 11:37 p.m.
BahaMeirman

Евгений Здравствуйте! Не могу понять вот эту часть кода: url: jQuery(this).attr('action') наверное здесь должен быть путь к url, тогда 'action' на какой url указывает?
Feb. 17, 2020, 2:22 a.m.
Evgenij Legotskoj

Добрый день. Это кастомный тег, помещается в файл, который находится в каталоге templatetags myapp/ templatetags/ myapp.py
B
Feb. 16, 2020, 12:36 p.m.
BahaMeirman

Добрый вечер! Монжно по подробней о теге get_companion? ссылка не работает.
Now discuss on the forum
a
Feb. 25, 2020, 7:06 a.m.
ayb

Да
Feb. 24, 2020, 11:04 a.m.
Evgenij Legotskoj

Добрый день. Вот пример с дружественного ресурса с движением камеры
Feb. 24, 2020, 5:29 a.m.
Evgenij Legotskoj

Qt не предоставляет функционала по запросу root прав во время выполнения программы. Поэтому нужно использовать платформозависимый функционал, для Linux это будет выглядеть так: #include…
Feb. 24, 2020, 2:47 a.m.
Evgenij Legotskoj

Добрый день. Что означает клиентская область? Это изображение? Вам нужно распознавать символы текста или всё-таки пользователь будет вводить текст с клавиатуры, просто в любом месте "абстр…
VZ
Feb. 21, 2020, 4:19 a.m.
Vladimir Zhitkovsky

void sendImage(int sessid, int type, int dest, int format, QString imgBase64Data){ QNetworkRequest request; request.setUrl(QUrl(ipAddress + "ctlapi/cmd=preparereportimg&sessid=…
EVILEG
About
Services
© EVILEG 2015-2019
Recommend hosting TIMEWEB