0

`\src\notation\view

\src\engraving\libmscore`

for Musescore.

I have a file in \view\noteinputcursor.cpp that I need to do some math in, but the numbers need to come from \libmscore\stringdata.cpp - i want the cursor i'm working with the know what fret I'm on to know how to highlight it, say a wide cursor or a narrow one.

what's a good way to reference that, and it has to work on anyone else that compiles it in the world too without adding stuff in environment or dependencies. the simplest way for everyone. ideally nobody outside of me (and those who review my hopeful future code) should even notice it.

tried just doing

#include stringdata.h but then realized it wouldn't work since they're in different folders and the compiler only works downstream not upstream/sidestream/parallel stream etc.

  • 5
    You can simply write `#include "relative/path/to/your/file"`. – Friedrich Jan 27 '23 at 09:57
  • 2
    What's more, any compiler will let you set include paths that are searched for files. These are the `-I` or `/I` (capital i) options. Look them up in your compiler's documentation. – Friedrich Jan 27 '23 at 10:05
  • dang. that's a tough one. if i do the first, then i need to add a comment to the file i'm grabbing from that if they move it to a new place, it'll break THIS and THAT, and that's more things to commit/push, which idk it's that's bad practice or not. i'll have to ask them if it'd be okay or not. if i use the second one, then it'll have to work in all major compilers (including QT) or else it'll fail. this is a tough one. i really appreciate your comments. – Variance Within Allan Jan 28 '23 at 09:16
  • Let's put it that way: if you have a perfectly working car and someone comes and removes a tire and puts it somewhere else, the car will stop working. You can make it work but you cannot prevent others from breaking it. – Friedrich Jan 28 '23 at 12:16
  • And Qt is not a compiler. The point in using a _build system_ like CMake (as others have pointed out) is that it handles different compilers so you won't have to worry about it. – Friedrich Jan 28 '23 at 12:18

2 Answers2

0

use cmake to organize your code. cmake is a makefile generation tool. it generates makefiles i.e. MinGW Makefiles, Visual Studio Projects, etc. it use a file to describe how your projects' code organised, and make linking program compile and link your dependicies easily.

for example, this is a project, i wrote it to learn OpenGL. It is easy to link libraries i.e. glfw easily.

cmake_minimum_required ( VERSION 3.15 )

project ( Freecraft )

set ( PRJ_SRC_LIST )    #all sources in the project
set ( PRJ_LIBRARIES )   #all libraries in the project
set ( PRJ_INCLUDE_DIRS )#all headers in the project

#set ( GLFW "d:/software/GLFW3" )

file ( GLOB_RECURSE root_header_files "${PROJECT_SOURCE_DIR}/src/*.h" "${PROJECT_SOURCE_DIR}/src/*.hpp" )
file ( GLOB_RECURSE root_src_files "${PROJECT_SOURCE_DIR}/src/*.cpp" "${PROJECT_SOURCE_DIR}/src/*.c" )


set ( GL_INC "${PROJECT_SOURCE_DIR}/include/" )
set ( GLFW_LIB "${PROJECT_SOURCE_DIR}/lib/glfw3.dll" )

list ( APPEND PRJ_INCLUDE_DIRS . )
list ( APPEND PRJ_INCLUDE_DIRS ${GL_INC} )
#list ( APPEND PRJ_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include/glad/" )
#list ( APPEND PRJ_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include/KHR" )

list ( APPEND PRJ_SRC_LIST ${root_src_files} )
list ( APPEND PRJ_LIBRARIES ${GLFW_LIB} )


add_executable ( ${PROJECT_NAME} ${PRJ_SRC_LIST} )

target_include_directories ( ${PROJECT_NAME}
    PRIVATE 
    ${PRJ_INCLUDE_DIRS}
)

target_link_libraries ( ${PROJECT_NAME} 
    PRIVATE 
    ${PRJ_LIBRARIES}
)

go to cmake.org for more details.

Promesis
  • 1
  • 1
0

i found a proper way to do it within c++, natively, without using cmake or any other.... way.

Referencing a cpp/h file in different location

just do

#include "../LowestSharedFolder/KeepGoingTill/YouGetToYour/NowReferencedFile.cpp"

must be 2 or 1 period before. cannot be 3.
.../folder/ bad
../folder/ good
./folder/ good

..\back\slash\folders\are\bad.cpp