Kg to pounds converter build error (CLion)

隐身守侯 提交于 2019-12-24 17:13:35

问题


I've just started to learn the C++ programming language by reading the book "C++ Primer Plus 5th addition" but I'm coming across a problem. The book just started to go into detail with functions, function prototypes, function headers and such.I decided to try and make a KG --> Pounds converter as practice, but my problem is that when I try to build it (Im using CLion) I get a build error.

The code:

#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;

}

First Build error:

"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

After removing the #include cmath line as it wasn't needed nor being used in my program, I attempted to build it yet again but received a different error which was:

"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

回答1:


There is some sort of problem with your mingw setup, because your compiler is failing to find a function used in the c:\mingw\include\math.h file. However you don't actually need that header for your code. You can remove the line #include and it's going to compile and run just fine. (tested it)

You do need to solve your mingw setup however if you wish to use that header in other programs.

If you still get an error it would be most likely due to the other header that you have used. Reinstall MinGW, check which files should contain the missing functions and try to find them on your machine.




回答2:


Your first problem, (with <cmath>), is a duplicate of this question; you can fix the underlying issue as described therin, (but why are you stipulating compiler options to invoke strict ANSI conformity checking so early in your learning process anyway?)

The second problem certainly merits further investigation; it could be due to any of a number of causes, amongst them:

  • You don't have write permission in the directory where you are trying to save newproject.exe; may seem unlikely, but check anyway.

  • An already existing newproject.exe, in this directory, is marked as "read only", or is owned by another user, and you have not been granted write permission.

  • Another process has a write lock on newproject.exe, which is preventing ld.exe from gaining write access.

  • newproject.exe already exists as some entity which is not a file, (a directory perhaps).

  • Some other reason, which doesn't spring to mind right now.

This doesn't look to me like a MinGW installation problem, but might I suggest that you eliminate this possibility by removing CLion from the equation, and simply issue the appropriate build commands directly from the command line; as a trainee programmer, it's always good to learn how to do that, before you muddy the waters with any higher level build system.



来源:https://stackoverflow.com/questions/30481908/kg-to-pounds-converter-build-error-clion

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!