udacity / CarND-MPC-Project

CarND Term 2 Model Predictive Control (MPC) Project
MIT License
280 stars 1.2k forks source link

Build fails on Ubuntu 17.10 #26

Closed SvenKratz closed 5 years ago

SvenKratz commented 6 years ago

There is a problem with json.hpp, and I did use the installation scripts from the repository:

sven@fxgpu:~/temp/CarND-MPC-Project/build$ make
Scanning dependencies of target mpc
[ 33%] Building CXX object CMakeFiles/mpc.dir/src/main.cpp.o
In file included from /home/sven/temp/CarND-MPC-Project/src/main.cpp:10:0:
/home/sven/temp/CarND-MPC-Project/src/json.hpp: In function ‘bool nlohmann::operator<(nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::const_reference, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::const_reference)’:
/home/sven/temp/CarND-MPC-Project/src/json.hpp:6057:62: error: wrong number of template arguments (1, should be 2)
                     return *lhs.m_value.array < *rhs.m_value.array;
SvenKratz commented 6 years ago

This issue can be fixed by installing the current version of json.hpp

https://github.com/nlohmann/json

tawnkramer commented 6 years ago

I had the same problem. It can also be fixed by moving json.hpp to the top of the includes list in main.cpp. I have a pull request to fix this.

Tsuihao commented 6 years ago

@tawnkramer. Your solution is not optimal.

The reason for this error is: json.hpp is using std::array instead of its own array. and why this happen is because the #include "MPC.h" has a bad practice of using namespace std in the header file. That is why if you list the #include "json.hpp" above #include MPC.h will solve the problem.

The actual solution should be remove the using namespace std in the MPC.h and use it only in the .cpp files.

mvirgo commented 5 years ago

Thanks for the notes here - have updated MPC.h as @Tsuihao noted.

creich commented 5 years ago

due to the removal of the std namespace there came up several compilation errors. i fixed them and created a pull request: https://github.com/udacity/CarND-MPC-Project/pull/41