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

  • Thread starter Thread starter cppIStough
  • Start date Start date
AI Thread 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:
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top