0

I have graphics files that are not loading because me program generate by CMakeLists.txt is opening in "/Users/icookiez", not in my source directory (/Users/icookiez/Documents/Studia/Projekt C++/hit-the-bucket/). I've try "How do I change the working directory for my program", but nothing happened.

Here is my CMakeLists.txt file:

cmake_minimum_required(VERSION 3.5)

project(Hit-The-Bucket) # VERSION 1.0 LANGUAGES CXX

SET(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(SFML 2.5 COMPONENTS graphics audio REQUIRED)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) # Solution from "How do I change the working directory for my program"

add_executable(Hit-The-Bucket main.cpp)

target_link_libraries(Hit-The-Bucket sfml-graphics sfml-window)

And my files structure is

/Users/icookiez/Documents/Studia/Projekt C++/hit-the-bucket\
    CMakeLists.txt
    main.cpp
    assets\
        fonts\
            ...
        images\
            ...

What should I change in my CMakeLists.txt so ma program is opening at /Users/icookiez/Documents/Studia/Projekt C++/hit-the-bucket/

drescherjm
  • 8,907
  • 5
  • 42
  • 60
  • You likely don't set this in the `CMakeLists.txt`. What you do may depend on your IDE. – drescherjm Jan 29 '20 at 23:56
  • I'm writing in VS code and know working directory from c++ ```cout```: ```c++ ... #include ... std::cout << "Current path is " << std::filesystem::current_path() << '\n'; ... ``` And output is: ```bash ... Failed to load font "./assets/fonts/Roboto-Regular.ttf" (failed to create the font face) Current path is "/Users/icookiez" Failed to load image "./assets/images/main_background.png". Reason: Unable to open file ... ``` – Krzysiek 'Cookiez' Kukiz Jan 30 '20 at 00:05
  • 2
    I think you need to alter the settings in the `launch.json` file. [https://stackoverflow.com/questions/38623138/vscode-how-to-set-working-directory-for-debug](https://stackoverflow.com/questions/38623138/vscode-how-to-set-working-directory-for-debug) – drescherjm Jan 30 '20 at 00:13
  • I'm not sure. becouse when i run this via `g++ -c main.cpp && g++ main.o -o hit-the-bucket -lsfml-graphics -lsfml-window -lsfml-system && ./hit-the-bucket`, it is working fine – Krzysiek 'Cookiez' Kukiz Jan 30 '20 at 00:39
  • 1
    .. because then you are already in the correct directory. You need to configure the `cwd` in your `launch.json` file, as @drescherjm said. You could set it to `"${workspaceRoot}"` for example. – Botje Jan 30 '20 at 09:00

0 Answers0