I am trying to compile a simple code using cmake and I getting an error. The code and cmake file are as below. The test.cpp is the main file in which i have directly included test1.cpp. I have also included my CMake file and the error that I am getting on performing make.
test.cpp
#ifndef _IOSTREAM_
#include<iostream>
#endif
#include"test1.cpp"
using namespace std;
int main()
{
printing("hello");
return 0;
}
test1.cpp
#ifndef _IOSTREAM_
#include<iostream>
#endif
#include<string>
using namespace std;
void printing(string s)
{
cout<<s<<endl;
return;
}
CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
set(CMAKE_C_COMPILER "/usr/bin/clang")
set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
project(test)
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -std=c++11)
add_executable(test test.cpp test1.cpp)
Error
CMakeFiles/test.dir/test1.cpp.o: In function
printing(std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >):
/home/vatsal/Desktop/test/test1.cpp:(.text+0x0): multiple definition
of printing(std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >)
CMakeFiles/test.dir/test.cpp.o:/home/vatsal/Desktop/test/test.cpp:
(.text+0x0): first defined here
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
CMakeFiles/test.dir/build.make:98: recipe for target test failed
make[2]: *** [test] Error 1
CMakeFiles/Makefile2:67: recipe for target CMakeFiles/test.dir/all
failed
make[1]: *** [CMakeFiles/test.dir/all] Error 2
Makefile:83: recipe for target all failed
make: *** [all] Error 2
$ brew info python
python: stable 3.6.4 (bottled), devel 3.7.0b2, HEAD
Interpreted, interactive, object-oriented programming language
https://www.python.org/
/usr/local/Cellar/python/3.6.4_2 (3,593 files, 56.2MB)
Poured from bottle on 2018-02-27 at 20:01:11
/usr/local/Cellar/python/3.6.4_4 (4,615 files, 97.4MB)
Poured from bottle on 2018-03-10 at 14:42:05
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/python.rb
==> Dependencies
Build: pkg-config ✔, sphinx-doc ✘
Required: gdbm ✔, openssl ✔, readline ✔, sqlite ✔, xz ✔
Optional: tcl-tk ✘
==> Options
--with-tcl-tk
Use Homebrew's Tk instead of macOS Tk (has optional Cocoa and threads support)
--devel
Install development version 3.7.0b2
--HEAD
Install HEAD version
==> Caveats
Python has been installed as
/usr/local/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/usr/local/opt/python/libexec/bin
If you need Homebrew's Python 2.7 run
brew install python@2
Pip, setuptools, and wheel have been installed. To update them run
pip3 install --upgrade pip setuptools wheel
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/usr/local/lib/python3.6/site-packages
See: https://docs.brew.sh/Homebrew-and-Python
I am trying to install extra-cmake-modules from source, and then I get an error after executing make
command:
Extension error:
Could not import extension ecm (exception: No module named 'sphinxcontrib')
make[2]: *** [docs/CMakeFiles/documentation.dir/build.make:62: docs/doc_format_html] Error 2
make[2]: Leaving directory '/home/masterpi/Documents/Extra-CMake-Modules/extra-cmake-modules/build'
make[1]: *** [CMakeFiles/Makefile2:217: docs/CMakeFiles/documentation.dir/all] Error 2
make[1]: Leaving directory '/home/masterpi/Documents/Extra-CMake-Modules/extra-cmake-modules/build'
make: *** [Makefile:163: all] Error 2
It seems that the problem is about module Sphinx, but I tried to uninstall and install it again via pip
and the error still occurred. So what can I do to fix it?
Here are logs when I executed cmake -DCMAKE_INSTALL_PREFIX=/usr ..
and make
command:
$ cmake -DCMAKE_INSTALL_PREFIX=/usr ..
-- WARNING: skipping tests that require PyQt
-- The following features have been enabled:
* BUILD_HTML_DOCS, Generate HTML documentation for installed modules.
* BUILD_MAN_DOCS, Generate man page documentation for installed modules.
* BUILD_TESTING, Build automated tests.
-- The following OPTIONAL packages have been found:
* Sphinx (required version >= 1.2), Tool to generate documentation., <https://www.sphinx-doc.org/>
Required to build documentation for Extra CMake Modules.
* QCollectionGenerator, Qt help collection generator., <https://www.qt.io/>
Required to build Extra CMake Modules documentation in Qt Help format.
* Qt5LinguistTools, Qt5 linguist tools., <https://www.qt.io/>
Required to run tests for the ECMPoQmTools module.
* Qt5Core, Qt5 core library., <https://www.qt.io/>
Required to run tests for the ECMQtDeclareLoggingCategory module, and for some tests of the KDEInstallDirs module.
* Qt5Network (required version >= 5.14.2)
* Qt5Qml (required version >= 5.14.2)
* Qt5QmlModels (required version >= 5.14.2)
* Qt5Gui (required version >= 5.14.2)
* Qt5Quick, Qt5 Quick library., <https://www.qt.io/>
Required to run tests for the ECMQMLModules module.
-- The following features have been disabled:
* BUILD_QTHELP_DOCS, Generate QtHelp documentation for installed modules.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/masterpi/Documents/Extra-CMake-Modules/extra-cmake-modules/build
$ make
make[1]: Entering directory '/home/masterpi/Documents/Extra-CMake-Modules/extra-cmake-modules/build'
make[2]: Entering directory '/home/masterpi/Documents/Extra-CMake-Modules/extra-cmake-modules/build'
make[2]: Leaving directory '/home/masterpi/Documents/Extra-CMake-Modules/extra-cmake-modules/build'
make[2]: Entering directory '/home/masterpi/Documents/Extra-CMake-Modules/extra-cmake-modules/build'
[ 50%] sphinx-build html: see /home/masterpi/Documents/Extra-CMake-Modules/extra-cmake-modules/build/docs/build-html.log
/usr/lib/python3.8/importlib/__init__.py:127: RemovedInSphinx40Warning: The alias 'sphinx.util.pycompat.htmlescape' is deprecated, use 'html.escape' instead. Check CHANGES for Sphinx API modifications.
return _bootstrap._gcd_import(name[level:], package, level)
Extension error:
Could not import extension ecm (exception: No module named 'sphinxcontrib')
make[2]: *** [docs/CMakeFiles/documentation.dir/build.make:62: docs/doc_format_html] Error 2
make[2]: Leaving directory '/home/masterpi/Documents/Extra-CMake-Modules/extra-cmake-modules/build'
make[1]: *** [CMakeFiles/Makefile2:217: docs/CMakeFiles/documentation.dir/all] Error 2
make[1]: Leaving directory '/home/masterpi/Documents/Extra-CMake-Modules/extra-cmake-modules/build'
make: *** [Makefile:163: all] Error 2
@ilyaa01
Новичёк не судите строго
Я новичок в cmake и вообще в языке C++
Сама ошибка
[main] Building folder: 02
[build] Starting build
[proc] Executing command: «C:\Program Files\CMake\bin\cmake.EXE» —build d:/ILYAA/Программирование/04/02/build —config Debug —target MMP -j 6 —
[build] CMake Error: Target DependInfo.cmake file not found
[build] mingw32-make.exe[3]: *** No rule to make target ‘D:/ILYAA/Программирование/04/02/src/main.cpp’, needed by ‘CMakeFiles/MMP.dir/src/main.cpp.obj’. Stop.
[build] mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:82: CMakeFiles/MMP.dir/all] Error 2
[build] mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:89: CMakeFiles/MMP.dir/rule] Error 2
[build] mingw32-make.exe: *** [Makefile:143: MMP] Error 2
[proc] The command: «C:\Program Files\CMake\bin\cmake.EXE» —build d:/ILYAA/Программирование/04/02/build —config Debug —target MMP -j 6 — exited with code: 2
[driver] Build completed: 00:00:00.352
[build] Build finished with exit code 2
CMakeLists
cmake_minimum_required(VERSION 3.20.0)
project(MMP VERSION 0.1.0)
set(wxWidgets_ROOT_DIR "c:/wxwidgets")
set(wxWidgets_LIB_DIR "c:/wxwidgets/lib/gcc810_x64_dll")
find_package(wxWidgets REQUIRED COMPONENTS net core base)
include(${wxWidgets_USE_FILE})
file(GLOB project
src/*
)
add_executable(MMP ${project})
target_link_libraries(MMP ${wxWidgets_LIBRARIES})
target_include_directories(MMP PRIVATE ${wxWidgets_INCLUDE_DIRS})
-
Вопрос задан
-
92 просмотра
Попробуйте не использовать кириллические символы в пути к проекту, это может приводить к проблемам. Равно как и пробелы в путях. И того и другого желательно избегать.
Пригласить эксперта
-
Показать ещё
Загружается…
21 сент. 2023, в 12:17
80000 руб./за проект
21 сент. 2023, в 12:08
3000 руб./за проект
21 сент. 2023, в 11:40
10000 руб./за проект
Минуточку внимания
When qtcreator uses the MSVC compilation environment to build a project, a JOM: C: /… /… [cmtc_fe41e \ fast] error 2 error will occur due to incorrect configuration. Here are my solutions and understanding of this problem. I hope it can help small partners who encounter the same problem.
Error screenshot
Error reason
When qtcreator uses cmake to build a project, it will first test the environment configuration. If you have used cmake GUI or the command line to generate the corresponding project file (vs. vcxproj or Makefile, etc.) through cmakelists.txt, you will understand this process. Cmake uses the – g parameter to see which specific projects are supported, called cmake generators.
Cmake command line generates makefiles:
MD build
CD build
cmake – G “nmake makefiles JOM”…
#[[
… Indicates that cmakelists.txt is placed in the upper level directory. In this step, cmake will automatically detect the environment. If an error occurs, you cannot generate project files or makefiles
#]]
nmake
Cmake GUI: after setting, click Configure to generate if there is no problem
so the JOM error above is that cmake detects that the environment configuration is incorrect. At this time, you will see that qtcreator will not load the source file at all. Only one cmakelists.txt
open cmake’s error log file, and you will find that some tools needed in the construction process cannot be found:
“D:\Program Files (x86)\CMake\bin\cmake.exe” -E vs_ link_ exe
–intdir=CMakeFiles\cmTC_ 5b162.dir
–rc=rc
–mt=CMAKE_ MT-NOTFOUND
–manifests
– D:\PROGRA1\MICROS1.0\VC\bin\amd64\link.exe /nologo @CMakeFiles\cmTC_ 5b162.dir\objects1.rsp @C:\Users\ADMINI~1\AppData\Local\Temp\cmTC_ 5b162.exe.9516.577.jom
RC pass 1: command “RC/fo cmakefiles \ cmtc_5b162. Dir/manifest. Res cmakefiles \ cmtc_5b162. Dir/manifest. RC” failed (exit code 0) with the following output:
the system cannot find the specified file. jom: C:\Users\Administrator\AppData\Local\Temp\QtCreator-liCfaX\qtc-cmake-pToFXfXx\CMakeFiles\CMakeTmp\CMakeFiles\cmTC_ 5b162.dir\build.make [cmTC_5b162.exe] Error 2
jom: C:\Users\Administrator\AppData\Local\Temp\QtCreator-liCfaX\qtc-cmake-pToFXfXx\CMakeFiles\CMakeTmp\Makefile [cmTC_5b162\fast] Error 2
RC is rc.exe, and the resource compiler
MT is mt.exe
resolvent
It’s easy to know the cause of the error
First, add the path of jom.exe to the environment variable path
${QT installation directory} \ tools \ qtcreator \ bin
Then add the paths of rc.exe and mt.exe to the environment variable path
C: \ program files (x86) \ windows kits \ 10 \ bin \ 10.0.17763.0 \ x86
depending on the system version and 32-bit/64 bit, find out for yourself
When there are no problems, you can build the project