CMake not creating Makefile, creating a lot of other files instead [duplicate] - c++

This question already has an answer here:
CMake cannot create MakeFile on Windows
(1 answer)
Closed 14 days ago.
I wanted to play around with my pico. I downloaded the examples from official github, installed an sdk and went along with the documentation. The problem I have is when I'm creating build files. While the cmake command is creating a lot of files, none of them are a Makefile, making the use of next command (nmake) impossible.
The strucutre I have after using cmake in build directory is as follows:
├── build
│ ├── blink
│ │ ├── CMakeFiles
│ │ | ├── ELF2UF2Build.dir
│ │ | | ├── Labels.json
│ │ | | ├── Labels.txt
│ │ | ├── generate.stamp
│ │ | ├── generate.stamp.depend
│ | ├── elf2uf2
│ │ | ├── src
│ │ | | ├── Debug (empty directory)
│ │ | | ├── MinSizeRel (empty directory)
│ │ | | ├── Release (empty directory)
│ │ | | ├── RelWithDebInfo (empty directory)
│ │ | | ├── ELF2UF2Build-source_dirinfo.txt
│ │ | ├── tmp
│ │ | | ├── ELF2UF2Build-cfgcmd.txt
│ │ | | ├── ELF2UF2Build-mkdirs.cmake
│ | ├── blink.vcxproj
│ | ├── blink.vcxproj.filters
│ | ├── cmake_install.cmake
│ | ├── ELF2UF2Build.vcxproj
│ | ├── ELF2UF2Build.vcxproj.filters
│ ├── other_examples...
...
Any help would be greatly appreciated, I've been going around in circles for some time.
Im working on Windows 10, cmake, make are installed with cholocatey.

To create Makefiles for nmake call CMake like this
cmake -S .. -B . -G "NMake Makefiles"
For troubleshooting, you can look up all generators that are supported on your system with cmake --help in section "Generators".
Note that nmake does not support parallel builds, so larger projects will be slow.

Related

How can I use the PocketSphinx library in my C++ project?

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

Including CMake Project Libraries

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.

Does OpenCV installed by conda can be used with C++? And how?

I use conda install OpenCV use:
conda install -c conda-forge opencv
I can use OpenCV with python with no error.
Since conda is a convenience tool to build OpenCV, I am wondering whether I can use OpenCV installed by conda with C++.
And how to use it?
I have opencv.hpp in /home/kandy/miniconda3/include/boost/compute/interop, and here it's what the folder contains:
.
├── eigen
│ └── core.hpp
├── eigen.hpp
├── opencv
│ ├── core.hpp
│ ├── highgui.hpp
│ └── ocl.hpp
├── opencv.hpp
├── opengl
│ ├── acquire.hpp
│ ├── cl_gl_ext.hpp
│ ├── cl_gl.hpp
│ ├── context.hpp
│ ├── gl.hpp
│ ├── opengl_buffer.hpp
│ ├── opengl_renderbuffer.hpp
│ └── opengl_texture.hpp
├── opengl.hpp
├── qt
│ ├── qimage.hpp
│ ├── qpointf.hpp
│ ├── qpoint.hpp
│ ├── qtcore.hpp
│ ├── qtgui.hpp
│ └── qvector.hpp
├── qt.hpp
├── vtk
│ ├── bounds.hpp
│ ├── data_array.hpp
│ ├── matrix4x4.hpp
│ └── points.hpp
└── vtk.hpp

Qt does not find header file

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_

ocamlfind cannot see installed package

I wanted to compile my project using command:
ocamlfind ocamlopt -package ocamlnet -package batteries -package unix -linkpkg oauth.ml
but I'm getting following error:
ocamlfind: Package `ocamlnet' not found
make: *** [oauth.cmi] Error 2
After some research on this problem I have read that there may be problem with packages installed via opam and packages installed before opam installation (in this case with ocamlfind) so I tried to check that and get stuck because ocamlfind is installed via opam. Does anybody know what may I try to do to solve that problem?
$ which ocamlfind
/home/user/.opam/4.00.1/bin/ocamlfind
$ opam list
Installed packages for 4.00.1:
[...]
ocamlfind 1.4.0 A library manager for OCaml
[...]
Thanks in advance.
Do a:
eval $(opam config env)
That should fix the problem.
# Edit 1:
If it still does not work remove the dir
/home/user/.opam/4.00.1
and try it again.
I'm making answer because of limit in comments and partial results I've made. Here is the result of 'grep -r 'ocamlnet' *' at '~/.opam' directory: http://pastebin.com/8cJqMXDY by looking at lines 1-90 we may conclude that there is actually no ocamlnet library at all (or I'm looking for it in wrong place - but as I wrote in comment everything were installed using opam - I'd be glad to hear some opinions on this subject). These suspicions may be partially confirmed in two ways:
in fact in lines 1-90 we've all binaries of ocamlnet components (http://projects.camlcity.org/projects/dl/ocamlnet-3.7.3/doc/html-main/index.html)
lines 90-* doesn't seem like something other than some files needed to manage this package using opam. E.g.
~/.opam/repo/default/packages/ocamlnet$ tree -r .
.
├── ocamlnet.3.7.3
│ ├── url
│ ├── opam
│ ├── files
│ │ └── ocamlnet.install
│ └── descr
├── ocamlnet.3.6.5
│ ├── url
│ ├── opam
│ ├── files
│ │ ├── ocamlnet.install
│ │ ├── netpop.patch
│ │ ├── nethttpd_types.patch
│ │ └── cloexec.patch
│ └── descr
├── ocamlnet.3.6.3
│ ├── url
│ ├── opam
│ ├── files
│ │ └── ocamlnet.install
│ └── descr
├── ocamlnet.3.6.0
│ ├── url
│ ├── opam
│ ├── files
│ │ ├── ocamlnet-ocaml4.diff
│ │ └── ocamlnet.install
│ └── descr
├── ocamlnet.3.5.1
│ ├── url
│ ├── opam
│ ├── files
│ │ └── ocamlnet.install
│ └── descr
└── ocamlnet.3.2.1
├── url
├── opam
├── files
│ └── ocamlnet.install
└── descr
I do not have a sufficiently large knowledge to go into it deeper but it looks for me like that ocamlnet become just a shortcut for a few another packages used by opam. Especially that after changing
-package ocamlnet
to exact module which I'm using
-package netstring
everything has compiled fine. I'm still open to any other solutions or explenations for the curious case of ocamlnet package (and Michael's hints) B).