我刚刚通过阅读“C++ Primer Plus 5th add”一书开始学习 C++ 编程语言,但我遇到了一个问题。这本书刚刚开始详细介绍函数、函数原型、函数头等。我决定尝试制作一个 KG --> 磅转换器作为练习,但我的问题是当我尝试构建它时(我使用 CLion ) 我得到一个构建错误。
编码:
#include <cmath> // [EDIT] Removed this line as it isnt being used
#include <iostream>
using namespace std;
double pounds_converter(double);
int main()
{
cout << "Welcome to the kg to pounds convertor" << endl;
cout << "Enter the desired kg's to change to pounds: ";
double my_kg;
cin >> my_kg;
double pounds = pounds_converter(my_kg);
cout << my_kg << " in pounds is: " << pounds << endl;
cin.get();
return 0;
}
double pounds_converter(double n)
{
return 2.2046226218 * n;
}
第一次构建错误:
"C:\Program Files (x86)\JetBrains\CLion 1.0.3\bin\cmake\bin\cmake.exe"
--build C:\Users\Admin\.clion10\system\cmake\generated\23677da2\23677da2\Release
--target newproject -- -j 8 Scanning dependencies of target newproject [100%] Building CXX object CMakeFiles/newproject.dir/main.cpp.obj In file included from c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\cmath:44:0,
from C:\Users\Admin\ClionProjects\newproject\main.cpp:1: c:\mingw\include\math.h: In function 'float hypotf(float, float)': c:\mingw\include\math.h:635:30: error: '_hypot' was not declared in this scope { return (float)(_hypot (x, y)); }
^ mingw32-make.exe[3]: *** [CMakeFiles/newproject.dir/main.cpp.obj] Error 1 mingw32-make.exe[2]:
*** [CMakeFiles/newproject.dir/all] Error 2 mingw32-make.exe[1]: *** [CMakeFiles/newproject.dir/rule] Error 2 mingw32-make.exe: *** [newproject] Error 2 CMakeFiles\newproject.dir\build.make:53: recipe for target 'CMakeFiles/newproject.dir/main.cpp.obj' failed CMakeFiles\Makefile2:59: recipe for target 'CMakeFiles/newproject.dir/all' failed CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/newproject.dir/rule' failed Makefile:108: recipe for target 'newproject' failed
在删除 #include cmath 行后,因为它不需要也没有在我的程序中使用,我尝试再次构建它,但收到一个不同的错误:
"C:\Program Files (x86)\JetBrains\CLion 1.0.3\bin\cmake\bin\cmake.exe" --build C:\Users\Admin\.clion10\system\cmake\generated\23677da2\23677da2\Release --target newproject -- -j 8
Linking CXX executable newproject.exe
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot open output file newproject.exe: Permission denied
collect2.exe: error: ld returned 1 exit status
CMakeFiles\newproject.dir\build.make:86: recipe for target 'newproject.exe' failed
CMakeFiles\Makefile2:59: recipe for target 'CMakeFiles/newproject.dir/all' failed
CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/newproject.dir/rule' failed
Makefile:108: recipe for target 'newproject' failed
mingw32-make.exe[3]: *** [newproject.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/newproject.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/newproject.dir/rule] Error 2
mingw32-make.exe: *** [newproject] Error 2