C/C++ Cpp in visual studio: cmake and being able to compile

  • Thread starter Thread starter cppIStough
  • Start date Start date
Click For Summary
To compile the `run_logger.cpp` file using CMake in Visual Studio, the CMakeLists.txt needs to be adjusted. The `add_executable` command should reference the target name without the `.cpp` extension, so it should be `add_executable(run_logger apps/run_logger.cpp)`. Additionally, ensure that the include directories are specified using `include_directories(include)` to allow the compiler to find `logger.h`. After making these changes, running CMake should generate the necessary build files, enabling successful compilation of the `run_logger.cpp` file.
cppIStough
Messages
24
Reaction score
2
I have the following directory of c++ files, and it looks like:

d.lib
--apps
----run_logger.cpp
----CMakeLists.txt
--include
----logger.h
--source
----logger.cpp

I want to build run_logger.cpp. I'm using Visual Studio. My CMakeLists is
Code:
cmake_minimum_required(VERSION 3.10)

project(d_lib)

# Add your source files
file(GLOB_RECURSE SOURCES "source/*.cpp" "include/*.h")

# Add your executable
add_executable(run_logger.cpp ${SOURCES})

How can I get this to compile? Thanks for your help.[/code]
 
Last edited:
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 12 ·
Replies
12
Views
4K
Replies
6
Views
2K
  • · Replies 15 ·
Replies
15
Views
8K
  • · Replies 6 ·
Replies
6
Views
12K
  • · Replies 29 ·
Replies
29
Views
3K
Replies
3
Views
1K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
4
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K