I have such structure of files:
├── MyProject/
│ ├── Include
│ │ ├── mainwindow.h
│ ├── Source
│ │ ├── main.cpp
│ │ ├── MyQtProjectFiles
│ │ │ ├── MyQtProject.pro
MyQtProject.pro contains some strings:
INCLUDEPATH += $$PWD\..\..\Include
SOURCES += $$PWD\..\..\Source\main.cpp
HEADERS += $$PWD\..\..\Include\mainwindow.h
But Qt produces the error : Cannot open include file: "mainwindow.h"; No such file or directory
Problem is solved, I deleted old cache files of previous build process. Recommended variable for usage in my case is _PRO_FILE_PWD_
Related
I'm trying to use the PocketSphinx speech to text library in my project as a Git submodule. So, I added the submodule to my dependency folder and I added the following code to my MakeFile:
add_subdirectory(dependencies/pocketsphinx)
But, when I'm building the project, I'm getting an error saying that:
[build] /home/aniket/code/restapi/dependencies/pocketsphinx/src/allphone_search.c:43:10: fatal error: pocketsphinx.h: No such file or directory
[build] 43 | #include <pocketsphinx.h>
[build] | ^~~~~~~~~~~~~~~~
[build] compilation terminated.
My guess is that CMAKE cannot find the header files; but, when I build PocketSphinx alone it works fine.
I'm also using the JsonCpp library, which compiles without any problem.
My CMAKE file is:
cmake_minimum_required(VERSION 3.2.0)
project(assistant)
add_executable(${PROJECT_NAME} src/main.cpp)
add_subdirectory(dependencies/jsonpp)
add_subdirectory(dependencies/pocketsphinx)
target_include_directories(${PROJECT_NAME} PUBLIC include PUBLIC
dependencies/jsonpp/include)
target_include_directories(${PROJECT_NAME} PRIVATE include
PRIVATE dependencies/jsonpp/include)
target_link_directories(${PROJECT_NAME} PRIVATE build/lib)
target_link_libraries(${PROJECT_NAME} PRIVATE jsoncpp curl)
Here's my directory structure:
.
├── build
├── dependencies
│ ├── jsonpp
│ │ ├── cmake
│ │ ├── devtools
│ │ ├── doc
│ │ ├── example
│ │ ├── include
│ │ ├── pkg-config
│ │ ├── src
│ │ └── test
│ └── pocketsphinx
│ ├── cython
│ ├── docs
│ ├── doxygen
│ ├── examples
│ ├── gst
│ ├── include
│ ├── model
│ ├── programs
│ ├── src
│ └── test
├── include
└── src
I have a project that has multiple subdirectories and I have a unit testing framework (UnitTest++) in the following folder structure:
root_dir
├── sub_dir1
│ ├── main.cpp
│ ├── some_class.hpp
│ └── test.cpp
├── sub_dir2
│ ├── another_class.hpp
│ ├── main.cpp
│ └── test.cpp
├── UnitTest++
│ ├── libUnitTest++.a
└── makefile
I plan to have more sub_dir# in the future.
How do I use make in the root directory so that it would compile all the subdirectories?
└── my-project
├── c++
│ ├─ include
│ │ └── orc
│ │ └── include
│ │ ├── a.h
│ │ └── b.h
│ └── src
│ ├── c.h
│ ├── d.h
│ └── io
│ └── f.h
├── WORKSPACE
└── BUILD
in "a.h",can see '#include "orc/b.h"'
in "c.h",can see '#include "io/f.h"'
in "f.h",can see '#include "d.h"'
i don't wanna change the file, how can organiz they by bazel
#include "orc/b.h" won't work. Such a path doesn't exist in your project. You have to change the structure of your project or change it in the code.
#include "io/f.h" from c.h should work without any changes.
#include "d.h" works after you add my-project/c++/src to the include paths.
I'm in the process of putting together a small c++ project using CMake for the first time. My current project structure is
├── bch
│ ├── CMakeLists.txt
│ ├── gf
│ │ ├── CMakeLists.txt
│ │ ├── include
│ │ │ └── gf.h
│ │ └── src
│ │ └── gf.cpp
│ ├── include
│ │ └── bch.h
│ └── src
│ └── bch.cpp
├── bsc
│ ├── CMakeLists.txt
│ ├── include
│ │ └── bsc.h
│ └── src
│ └── bsc.cpp
├── CMakeLists.txt
├── .gitignore
└── main.cpp
Currently I have gf as a subdirectory of bch. The contents of bch/CMakeLists is
cmake_minimum_required(VERSION 3.17)
project(bch VERSION 0.1.0)
# Targets
add_library(bch STATIC src/bch.cpp)
# Dependant
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/gf)
target_link_libraries(bch PUBLIC gf)
# Export to dependants
target_include_directories(bch PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
I would like to take the gf CMake project and place outside of the directory path of bch. This doesn't seem to be a supported structure when using the add_subdirectory command unless I'm missing something. Generally, what would be the current "Best Practice" for accomplishing my goal of decoupling the directory structure from the dependency tree?
If you want to decouple the project from dependencies, then I would suggest splitting cmake project into two separate, exporting the dependent target and then importing it with 'find_package'. Here is quick google find for that topic:
https://visualgdb.com/tutorials/linux/cmake/find_package
[edit]
For a more general approach I suggest cmake documentation:
https://cmake.org/cmake/help/latest/command/find_package.html#command:find_package
https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html
https://cmake.org/cmake/help/v3.18/command/install.html#export
The idea is:
In a dependency project to generate a '*ConfigVersion.cmake' file, install all needed files (headers, binaries and *ConfigVersion.cmake) using the 'EXPORT' in parameter the 'install' command.
In a final project use 'find_package' to import the dependency.
For bigger library projects I also suggest using namespaces to allow importing only selected parts of the library.
I'm fairly new to webpack and I'm trying to understand what's the proper way to include my assets folder into the dist folder using webpack (or one of its plugins).
This is the structure of my project:
├── package.json
├── webpack.config.js
├── src
│ ├── index.html
│ ├── app.js
│ ├── components
│ │ ├── ...
│ ├── assets
│ │ ├── factory.png
│ │ ├── factory_white.png
I managed to solve my own issue by reading around about copy-webpack-plugin