Reputeless / PerlinNoise

Header-only Perlin noise library for modern C++ (C++17/C++20)
MIT License
673 stars 77 forks source link

Getting errors in the header file when trying to compile #5

Closed flarn2006 closed 4 years ago

flarn2006 commented 4 years ago

I'm trying to compile the following test program:

#include <cstdio>
#include <gd.h>
#include "PerlinNoise.hpp"

using value_t = siv::PerlinNoise::value_type;

int main(int argc, char *argv[])
{
    siv::PerlinNoise noise;
    gdImagePtr img = gdImageCreateTrueColor(512, 512);

    for (int y=0; y<512; ++y) {
        value_t yf = (value_t)y/512;
        for (int x=0; x<512; ++x) {
            value_t xf = (value_t)x/512;
            value_t z = noise.noise2D(xf, yf) * 255;
            gdImageSetPixel(img, x, y, z);
        }
    }

    std::FILE* fp = fopen("output.png", "wb");
    gdImagePng(img, fp);
    gdFree(img);
    std::fclose(fp);
}

When I compile using g++ -o main main.cpp -lgd, I get:

In file included from /usr/include/c++/5/cstdint:35:0,
                 from PerlinNoise.hpp:29,
                 from main.cpp:3:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support \
  ^
In file included from main.cpp:3:0:
PerlinNoise.hpp:53:9: error: expected nested-name-specifier before ‘value_type’
   using value_type = Float;
         ^
PerlinNoise.hpp:57:8: error: ‘uint8_t’ in namespace ‘std’ does not name a type
   std::uint8_t p[512];
        ^
PerlinNoise.hpp:59:3: error: expected unqualified-id before ‘[’ token
   [[nodiscard]]
   ^
PerlinNoise.hpp:65:3: error: expected unqualified-id before ‘[’ token
   [[nodiscard]]
   ^
PerlinNoise.hpp:71:3: error: expected unqualified-id before ‘[’ token
   [[nodiscard]]
   ^
PerlinNoise.hpp:80:3: error: expected unqualified-id before ‘[’ token
   [[nodiscard]]
   ^
main.cpp:25:1: error: expected ‘}’ at end of input
 }
 ^
main.cpp:25:1: error: expected unqualified-id at end of input
main.cpp:25:1: error: expected ‘}’ at end of input

When I add --std=c++11, I get even more errors, and 14 and 17 don't help either.

Please let me know if you need any more information.

Reputeless commented 4 years ago

It seems your compiler doesn't support C++17 features. GCC 7 or later is required to build this library.

urnenfeld commented 4 years ago

Wtih

$ g++ --version
g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.

I could compile the included example: g++ -o example example.cpp -std=c++17

After fixing the deprecation:

flarn2006 commented 4 years ago

Yep, using a newer version of GCC fixed it. Thanks :)