c++ - 在 ubuntu 上编译 lsnes 模拟器时出错

标签 c++ linux ubuntu lua

我目前正在尝试从 https://github.com/aleju/mario-ai 获取 Mario 项目在我的 ubuntu (16.04) 系统上工作。我按照教程已经解决了一些错误,但现在我在 lsnes 模拟器上得到了一些看起来像编译错误的东西,这对我来说没有意义。

我的命令是 LDFLAGS="-L/usr/lib -L/usr/local/lib -L/usr/lib/x86_64-linux-gnu"CFLAGS="-I/usr/include -I/usr/local/include -I/usr/include/lua5.1"make.我添加了试图解决我最后一个错误的标志。

这是我得到的错误:

...
g++ -c -o core.o core.cpp -I../../../include -I../../../bsnes -I/usr/include -I/usr/local/include -I/usr/include/lua5.1 -std=gnu++0x -pthread -g -DNATIVE_THREADS -DUSE_LIBGCRYPT_SHA256 -I/usr/include/lua5.1  -DBSNES_IS_COMPAT -DBSNES_HAS_DEBUGGER -DBSNES_VERSION=\"085\" -DLIBSNES_INCLUDE_FILE=\"ui-libsnes/libsnes.hpp\"  -Wreturn-type
In file included from ../../../bsnes/nall/array.hpp:10:0,
             from ../../../bsnes/snes/snes.hpp:28,
             from core.cpp:49:
../../../bsnes/nall/bit.hpp: In instantiation of ‘constexpr unsigned int nall::uclip(unsigned int) [with int bits = 24]’:
../../../bsnes/snes/cpu/core/registers.hpp:52:69:   required from here
../../../bsnes/nall/bit.hpp:13:3: error: body of constexpr function ‘constexpr unsigned int nall::uclip(unsigned int) [with int bits = 24]’ not a return-statement
   }
   ^
../../../bsnes/nall/bit.hpp: In instantiation of ‘constexpr unsigned int nall::uclip(unsigned int) [with int bits = 2]’:
../../../bsnes/nall/varint.hpp:32:55:   required from ‘nall::uint_t<bits>::uint_t(unsigned int) [with unsigned int bits = 2u]’
../../../bsnes/snes/controller/controller.hpp:27:33:   required from here
../../../bsnes/nall/bit.hpp:13:3: error: body of constexpr function ‘constexpr unsigned int nall::uclip(unsigned int) [with int bits = 2]’ not a return-statement
Makefile:44: die Regel für Ziel „core.o“ scheiterte
make[3]: *** [core.o] Fehler 1
...

比特.hpp:

#ifndef NALL_BIT_HPP
#define NALL_BIT_HPP

namespace nall {
  template<int bits> constexpr inline unsigned uclamp(const unsigned x) {
    enum { y = (1U << (bits - 1)) + ((1U << (bits - 1)) - 1) };
    return y + ((x - y) & -(x < y));  //min(x, y);
  }

  template<int bits> constexpr inline unsigned uclip(const unsigned x) {
    enum { m = (1U << (bits - 1)) + ((1U << (bits - 1)) - 1) };
    return (x & m);
  }

  template<int bits> constexpr inline signed sclamp(const signed x) {
    enum { b = 1U << (bits - 1), m = (1U << (bits - 1)) - 1 };
    return (x > m) ? m : (x < -b) ? -b : x;
  }

  template<int bits> constexpr inline signed sclip(const signed x) {
    enum { b = 1U << (bits - 1), m = (1U << bits) - 1 };
    return ((x & m) ^ b) - b;
  }

  namespace bit {
    //lowest(0b1110) == 0b0010
    template<typename T> constexpr inline T lowest(const T x) {
      return x & -x;
    }

    //clear_lowest(0b1110) == 0b1100
    template<typename T> constexpr inline T clear_lowest(const T x) {
      return x & (x - 1);
    }

    //set_lowest(0b0101) == 0b0111
    template<typename T> constexpr inline T set_lowest(const T x) {
      return x | (x + 1);
    }

    //round up to next highest single bit:
    //round(15) == 16, round(16) == 16, round(17) == 32
    inline unsigned round(unsigned x) {
      if((x & (x - 1)) == 0) return x;
      while(x & (x - 1)) x &= x - 1;
      return x << 1;
    }
  }
}

#endif

我不太熟悉 C++,但文件对我来说看起来不错。

您知道可能是什么问题吗? 我已经尝试了我在此处找到的关于 lsnes 的唯一其他问题中建议的解决方案 ( link error with "undefined lua_xxxxx" when building lsnes ),但它没有帮助。

最佳答案

我刚刚仔细查看了您对 g++ 的调用,您正在使用选项 -std=c++0x。这告诉编译器使用 C++11 标准。但是,正如我在评论中所述,您发布的代码至少需要 C++14 才能工作。因此,请改用选项 -std=c++14,它应该可以工作。

关于c++ - 在 ubuntu 上编译 lsnes 模拟器时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43889403/

相关文章:

c++ - 在指针列表上使用迭代器

linux - 在 docker linux 容器上安装 netstat

linux - 更改学校服务器上的 vim colorscheme

c++ - 如何在 C++ 中将带有空格的单词分成两列

c++ - Poco SSLManager 和 SecureStreamSocket 可以支持 SSL/TLS PSK(预共享 key 密码套件)吗?

c - 如何在 Linux 中以编程方式获取目录的大小?

ubuntu - 如何在命令行中呈现 UTF-16BE?

java - 重启VM后无法启动elasticsearch

c++ - 使用单声道运行 visual studio 可执行文件时出现问题

linux - 将任意字符串(从标准输入或文件)读入 bash 并在不进行任何 shell 扩展的情况下使用它