Clang++ stdlib/cstdlib.h workaround

Antonio Olivares olivares14031 at
Wed Jul 4 12:30:56 UTC 2018

On Tuesday, July 3, 2018, Shane Ambler <FreeBSD at> wrote:
> On 04/07/2018 04:08, Antonio Olivares wrote:
>> Dear kind folks,
>> I have a cpp file that used stdlib.h and it compiled and ran
>> I am trying it out with clang and it returns errors that it cannot find
>> stdlib.h, I remove the stdlib.h include statement and it still complains.
> You can add -I<path> as an argument that tells clang where to search for
> header files. -L<path> does the same for libraries. Even when you remove
> it another included file may still want it.
> clang++ -I/usr/include -L/usr/lib -o myapp myfile.cpp
>> I made a copy of the c++ file and it compiles and runs correctly, but I
>> removed some stuff " --- " and only output the numbers.  How do I deal
>> stdlib.h requirements?
>> The program finds numbers that are triangular and square.  It fails for
>> numbers that are bigger than 2147483647.
> Does that number have any significance to you? It is the largest number
> that can be held by a 32bit signed integer. You can use an unsigned int
> to get twice that or you can use a long long to get a 64bit integer.
> Also related is that the math library functions have several variations
> that take different size arguments.
> --
> FreeBSD - the place to B...Software Developing
> Shane Ambler


Thanks for your input.  For the moment I have removed the header file

#include <stdlib.c>

>From the c++ program.  In a for loop part, I had a set of statements to
output the values where the number was a triangular and square at the same
time in two lines.  This was where the program was failing to compile and I
was concluding incorrectly that it had to do with the stdlib.h or cstdlib.h

#include <iostream>
#include <math.h>
using namespace std;
int main()
   int i;
   int n;
   int k;

   cout << "This program searches for numbers that\n";
   cout << "are both square and triangular\n";

   cout << "Up to what number do you want to search?\n\n";
   cout << "Enter number: ";
   cin >> n;
   for (i=1; i<n; i++)
   k = (i*(i+1))/2;
   if (sqrt(k) - int(sqrt(k)) == 0)
cout << "\n" << k << " is a triangular number when i = " << i << "."  <<
   cout << "\n\n";
   return 0;

About the big number, it would be nice to get it working for bigger
numbers, but I would need to run it on amd64 freebsd machine at work.
Maybe at some other time we can revisit this issue.  Thank you for your

When running the program if I enter a number like 10,000,000 I get bad
output.  If I stop at 1,000,000 I get correct output.

Best Regards,


More information about the freebsd-questions mailing list