-2

I included these libraries into my source file main.cpp:

 #include <iostream>
 #include <climits>

My entire code written in Visual Studio 2017, Windows.

I transferred my code file to Linux.

When I try to compile with g++ Item.cpp main.cpp -o main , it gives an error for this part:

items[size - 1]->points = std::numeric_limits<int>::min();

So errors below:

main.cpp: In function ‘void insert_p(Item**, int, int&)’:
main.cpp:287:33: error: ‘numeric_limits’ is not a member of ‘std’
items[size - 1]->points = std::numeric_limits<int>::min();
                             ^~~~~~~~~~~~~~
main.cpp:287:48: error: expected primary-expression before ‘int’
items[size - 1]->points = std::numeric_limits<int>::min();
                                            ^~~

A correct solution would be just replacing #include <climits> with #include <limits>.

Unfortunately, here is the challenge: Is it possible to solve this issue without changing my source code?

Is there any compiling trick to fix this?

I'm looking for a command like g++ Item.cpp main.cpp -o main -llimits to link <limits> library.

[EDIT]:

Solved my problem with command below:

 g++ Item.cpp main.cpp -o main -include "limits"

Check this: https://stackoverflow.com/a/3387518/7977464

And as @user4581301 said:

It's far better to fix the code.

Thank you all.

isydmr
  • 649
  • 7
  • 16

1 Answers1

0

An easy solution would be just replacing #include <climits> with #include <limits>.

That's not an "easy" solution, it's a "correct" solution. Your source code is wrong - fix it instead of using weird workarounds.


Is there any compiling trick to fix this?

You could try to redefine the token climits to limits, but it will probably not work as it will break code trying to use climits.

Pete Becker
  • 74,985
  • 8
  • 76
  • 165
Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416
  • Isn't "it will probably not work as it will break code" enough? Why would you want to do this? – N00byEdge Nov 26 '18 at 22:20
  • Yeah I looked into it and redefining the token does not affect the include, you have to have the proper header included. – N00byEdge Nov 26 '18 at 22:22
  • To be honest, what you can do is to `#include` and then include your code (header or otherwise), but this will require you to include that before your code every time. – N00byEdge Nov 26 '18 at 22:24