skip to Main Content
Program3
├── CMakeLists.txt
├── CMakePresets.json
├── CPPs
    ├── Program3.cpp // this is example code i'm trying to run
    ├── Program3.txt // this is the premade .cpp file that came with the cmake template
├── Hs
    ├── Program3.h //this is the premade .h file that came with the cmake template
├── out

I’m using the CMAKE template in visual studio with C++ and want to run an SFML example code. For the code to run I need to include .hpp files. I dont want to copy the include files and paste them directly into my project, and am hoping to just reference the library that is in it’s own directory.

this is a tutorial i’m following but slightly altering https://www.youtube.com/watch?v=c35L674qzIE

i’m unsure of the syntax but I think i’m supposed to use target_include_directories or include_directories to have the program search for the file it needs in the SFML folder.

I may be mistaken and just copy files into the project as suggested if referencing them from outside the project isn’t possible.

the error is

Severity    Code    Description Project File    Line    Suppression State   Details
Error   C1083   Cannot open include file: 'SFML/Graphics.hpp': No such file or directory    C:UserssaledOneDriveDesktopGameDevStrategieLLC1stAttemptProgram3outbuildx64-debugProgram3   C:UserssaledOneDriveDesktopGameDevStrategieLLC1stAttemptProgram3CPPsProgram3.cpp  1       
target_include_directories({CMAKE_SOURCE_DIR} ../DevLibrariesUsed/SFML-2.6.1-windows-vc17-64-bit/SFML-2.6.1/include/SFML)

the .. references the common folder between the project and library folder DevLibariesUsed.

i’ve also tried

target_include_directories(Program3 ../DevLibrariesUsed/SFML-2.6.1-windows-vc17-64-bit/SFML-2.6.1/include/SFML)

and

include_directories(Program3 ../DevLibrariesUsed/SFML-2.6.1-windows-vc17-64-bit/SFML-2.6.1/include/SFML)

But I may try just linking each .hpp file, but there are more folders in thaat part of the library and I don’t want to have to add everything in those directly at some point.

this

target_link_libraries(Program3 ../DevLibrariesUsed/SFML-2.6.1-windows-vc17-64-bit/SFML-2.6.1/lib/sfml-window.lib)

seems to work for the .lib files? So i don’t know why similar syntax doesn’t work for include_directories

2

Answers


  1. Your problem seems to be the lack of knowledge about what include_directories, target_include_directory and target_link_libraries does.

    include_directories does not do what you think it does. When you use include_directories, you’re telling CMake that in this folder there is another CMakeLists.txt to continue the definition of the project.

    From the information you have given us, target_include_directories definitiely is what you want to use. target_include_directories is used to tell the compiler where your source-code is located, and gives it scope to said directory.

    target_link_libraries is a complete different story. With target_link_libraries, as the name suggest, you link a library to your project. For this you need to decide if you want/need it to be static or dynamic. If you are new to the concept of libraries, you might want to read up a bit on what static and dynamic actually means. In your case, it is probably a static library.

    To conclude, what you probably want to do is:

    1. Copy your SFML code into your project, and use target_include_directories to enable scope to said source-code.
    2. If SFML is provided to you as a library (which it seems to be), use target_link_libraries AND target_include_directories to link the library to your project.

    Generally, you should probably read through the documentation of CMake and learn some fundamentals before trying to follow a Youtube video, as 273K suggested in the comments.

    Login or Signup to reply.
  2. [1️⃣]### Python Example: Filtering a Dataset

    1.For this example, let’s assume we have a dataset containing information about patients, including their age and whether they have a certain condition. We’ll filter this dataset to find all patients above a certain age who have the condition.
    We’ll use Python’s Pandas library for this task, as it provides powerful data manipulation capabilities. If you don’t have Pandas installed, you can install it using pip:

    pip install pandas
    

    [2️⃣]#### Code

    import pandas as pd
    
    # Sample dataset creation
    data = {
        'PatientID': [1, 2, 3, 4, 5],
        'Age': [25, 34, 45, 65, 76],
        'HasCondition': [False, True, True, False, True]
    }
    _
    df = pd.DataFrame(data)
    _
    # Filtering criteria: Age > 40 and HasCondition == True
    filtered_df = df[(df['Age'] > 40) & (df['HasCondition'] == True)]/
    print(filtered_df)
    

    [3️⃣]#### Explanation

    • Pandas Library: We use Pandas for its data manipulation capabilities. It allows us to easily create, manipulate, and filter datasets.
    • Sample Dataset: data is a dictionary representing a simple dataset with three columns: PatientID, Age, and HasCondition. This dataset is converted into a DataFrame df, which is a two-dimensional, size-mutable, and potentially heterogeneous tabular data structure with labeled axes (rows and columns) in Pandas.
    • Filtering: filtered_df is created by applying a filter to df. The filter criteria are that the patient’s age must be greater than 40 and they must have the condition (HasCondition == True). The & operator is used to combine the two conditions.
    • Output: Finally, filtered_df, which contains only the rows from the original DataFrame that meet the filtering criteria, is printed.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search